Poproś Claude Code o pakiet QPKG: Hello world na udziale Public i edytor crontaba
Claude Code działa na Twoim NAS-ie w środowisku Bucket & Code Server IDE. Sesję uruchamiasz z panelu, z terminala edytora, z claude.ai/code albo z aplikacji na telefon, a pakiet opisujesz zwykłymi słowami. Ten poradnik pokazuje dwie prawdziwe prośby. HelloPublic zapisuje „Hello world” do pliku na udziale Public. CronEdit dopisuje własne linie do crontaba NAS-a według zasad QNAP.
- Sesjaw folderze projektu
- Prośbaco ma robić pakiet
- Przeglądprzeczytaj i przetestuj kod
- Kompilacjabvs qbuild
- Instalacjai sprawdzenie
Obrazy pochodzą z Bucket & Code Server IDE 1.0.0-102, z kontem ola. Claude Code jest zainstalowany w środowisku, ale nikt się nie zalogował, więc samą sesję pokazujemy jako tekst. Prośby i odpowiedzi pochodzą z prawdziwych uruchomień Claude Code.
01Zanim zaczniesz
- Projekt utworzony przez Nowy projekt z szablonu Pakiet QPKG. Zawiera skill
.claude/skills/qnap-devi plikAGENTS.md. Claude Code czyta skill i pisze pod NAS-a: BusyBoxsh,/etc/config, dzienniki systemowe QTS. - Claude Code w środowisku: Toolchainy → środowisko → Narzędzia AI → Claude Code → Zainstaluj. Potem w tym samym oknie Zaloguj się do Claude własnym kontem.
- Konto z rolą developer albo admin. Instalacja pakietu na NAS-ie to krok administratora.
02Uruchom sesję
Każdy z poniższych sposobów uruchamia tego samego Claude Code w środowisku. Uruchom go w folderze projektu, żeby przeczytał skill projektu.
- W panelu. Na karcie Claude Code w oknie Narzędzia AI wybierz projekt w polu Folder i naciśnij Uruchom nową sesję. Sesja działa na NAS-ie w izolacji środowiska i działa dalej po zamknięciu strony. Znajdziesz ją w sekcji Terminal.

- W terminalu edytora. Link Albo uruchom w terminalu edytora pod przyciskiem otwiera sesję tam. Taka sesja kończy się, gdy zamkniesz kartę edytora.
- Z claude.ai/code albo z aplikacji Claude. Po zalogowaniu ta sama karta pokazuje Remote Control: „Sesje w tym środowisku można uruchamiać i sterować nimi z claude.ai/code oraz z aplikacji Claude.” Włącz to i wybierz tam to środowisko.
- Z telefonu. Aplikacja Bucket & Code na telefon, sparowana na stronie Aplikacja na telefon w panelu, ma kartę AI. Wybierz środowisko, folder i narzędzie, potem Zacznij nową rozmowę.
03Poproś o HelloPublic
Prośba słowo w słowo (po angielsku, tak jak ją wpisaliśmy), w folderze nowego projektu HelloPublic:
This folder is a QPKG project that Bucket & Code's New project made. Make the package HelloPublic: when it starts, it writes the line "Hello world" into the text file hello.txt in the Public shared folder. - Take the Public folder's path from QTS: getcfg Public path -f /etc/config/smb.conf. Never a fixed volume such as /share/CACHEDEV1_DATA. - If the NAS has no Public share, the start says so in the NAS's System Logs and fails. - Stop and uninstall leave hello.txt where it is: it is the user's file then. - Follow the qnap-dev skill in .claude/skills. Do not build or install anything: I build it with bvs qbuild and install it myself. At the end, tell me which files you changed, how to build it and how to check it on the NAS.
Claude Code zapisał start w shared/HelloPublic.sh. Ścieżkę udziału Public bierze z QTS, a plik nadpisuje, więc po drugim starcie nadal ma jedną linię:
service_start() {
local dir file
dir=$("$QPKG_SYS/sbin/getcfg" Public path -f "$QPKG_SYS/etc/config/smb.conf")
if [ -z "$dir" ]; then
qpkg_log error "this NAS has no Public shared folder (no path for [Public] in /etc/config/smb.conf); hello.txt is not written"
return 1
fi
qpkg_sys "$dir"
if [ ! -d "$QPKG_P" ]; then
qpkg_log error "the Public shared folder $dir does not exist or its volume is not mounted; hello.txt is not written"
return 1
fi
file=$QPKG_P/hello.txt
…
if ! echo "Hello world" >"$file"; then
qpkg_log error "cannot write $dir/hello.txt"
return 1
fi
# the user's file: not only root may change it (root writes it, with the umask 022 qpkg_init set)
chmod 666 "$file"
qpkg_log info "wrote \"Hello world\" into $dir/hello.txt"
}
}
Jego odpowiedź, skrócona. W tym uruchomieniu Claude Code mógł zmieniać pliki i sprawdzać ich składnię, ale nie mógł ich uruchamiać, i sam o tym pisze:
HelloPublic now writes "Hello world" into `hello.txt` in the Public shared folder when it starts. I haven't run it: the syntax check (`sh -n`) passes, but the test against a fake NAS folder needed your approval and wasn't run. Nothing is built, installed or committed.
## Files changed
- **`shared/HelloPublic.sh`** (the start script):
- **Start** gets the Public folder's path from `/sbin/getcfg Public path -f /etc/config/smb.conf`, with no fixed volume anywhere. It then overwrites `hello.txt` there with the one line, so starting twice still leaves one line. It sets the file to mode 666 so other users can change it, not only root.
- **Start fails** (exit 1, with an error in System Logs) when:
- the NAS has no Public share;
- Public's folder doesn't exist, for example because its volume isn't mounted. The script never creates that folder, because a folder made then would land in RAM;
- `hello.txt` is a link or not a regular file. Public is open to every user, so this stops anyone tricking the root-run start into overwriting some other file.
- **Stop and uninstall** don't touch `hello.txt`.
…
## Check it on the NAS
1. Install it: `qpkg_cli -m /share/<folder>/HelloPublic_0.1.0_<arch>.qpkg --keep`, or use App Center's manual install. The start runs as part of the install.
…
04Poproś o CronEdit
Prośba wymienia po kolei zasady QNAP dla crona, więc potem każdą z nich znajdziesz w kodzie:
This folder is a QPKG project that Bucket & Code's New project made. Make the package CronEdit, a small crontab editor for a QNAP NAS that follows QNAP's rules for cron: 1. The app keeps its own schedule lines in a file of its own in the package's folder, one cron line per line. A command, cronedit, manages them: cronedit add "<five time fields> <command>", cronedit list, cronedit remove <number>. 2. The lines go into /etc/config/crontab, the file that survives a restart of the NAS. Never crontab -e, never the files under /tmp/cron or /var/spool/cron. 3. Every line the app writes into /etc/config/crontab ends with the app's own tag, so its lines can always be told from the others. 4. At every start, the service script checks each of the app's lines and adds it only when /etc/config/crontab does not have it yet. A second start adds nothing: never a duplicate. 5. On stop and on uninstall it removes its own tagged lines, and only those (cleanup), including lines that are no longer in its own file. 6. After every change of /etc/config/crontab it reloads cron the QNAP way: crontab /etc/config/crontab && /etc/init.d/crond.sh restart. When nothing changed, it does not reload. 7. It never changes, moves or removes a line it did not write. 8. cronedit add and cronedit remove change the app's file and, while the app is started, bring /etc/config/crontab in line at once, by the same rules. Follow the qnap-dev skill in .claude/skills (the NAS has BusyBox and no bash; cron runs commands with a short PATH). Do not build or install anything: I build it with bvs qbuild and install it myself. At the end, tell me which files you changed, how to build it and how to check it on the NAS.
Odpowiedź, skrócona:
I've written CronEdit, but **I haven't run it.** Running scripts needed an approval this session didn't give, so the only check was a syntax check with `sh -n`, which passed for both scripts. Everything else comes from reading the code. A test script for a fake NAS file tree is in `build/t/run.sh` (git ignores `build/`), so you can run it with `sh build/t/run.sh`. Nothing is committed. ## Files changed - **`shared/bin/cronedit`** (new, POSIX `sh` for BusyBox): the `add`, `list` and `remove <number>` commands, plus `sync`, `cleanup` and `check`, which the service script calls. - **Its own file:** the lines live in `<install folder>/cronedit.tab`. The package doesn't ship that file, so an upgrade can't overwrite it. - **Tag:** every line it writes into `/etc/config/crontab` ends in `# managed-by:CronEdit`. It rejects a line that is badly formed, starts with `@reboot` or `#`, contains the tag, or ends in `\`. It also rejects a line that is already in its file. - **Other lines are safe:** before it replaces `/etc/config/crontab`, it checks that every untagged line is still there, unchanged and in the same order. If not, it leaves the file alone. It keeps a backup while writing and puts it back if the write fails. - **Reload:** it runs `crontab /etc/config/crontab && /etc/init.d/crond.sh restart` only when lines were actually added or removed. - **Started or stopped:** `add` and `remove` update `/etc/config/crontab` straight away only while the package is started. While it's stopped, the change waits for the next start. - A command that doesn't start with `/` gets a note that cron's PATH is short. - **`shared/CronEdit.sh`**: the service script, written by hand on top of `lib/bvs-qpkg.sh`. - **start:** runs `sync`, which adds only the missing lines, so a second start adds nothing. It also removes tagged lines that are no longer in `cronedit.tab`, and links `/usr/bin/cronedit`. - **stop and remove (uninstall):** run `cleanup`, which removes every tagged line and only those. - **status:** runs `check`. - **Switched-off package:** if a start is refused because the package is off, it still removes the tagged lines first, in case a power cut skipped the stop. … **One thing for you:** deleting the template placeholder `shared/bin/CronEdit` needed an approval I didn't get, so it's still there. It does no harm, but you can remove it with `git rm shared/bin/CronEdit`.
05Zasady crontaba w kodzie
CronEdit trzyma swoje linie w pliku cronedit.tab w folderze pakietu. Program bin/cronedit wpisuje je do /etc/config/crontab, pliku, który przetrwa restart. Każda linia, którą wpisuje, kończy się znacznikiem, a zmienia tylko linie z tym znacznikiem na końcu:
TAG_WORD='managed-by:CronEdit'
TAG="# $TAG_WORD" # the end of every line CronEdit writes; a user's line may not hold TAG_WORD
SYS=${BVS_QPKG_SYSROOT-}
CONF=$SYS/etc/config/qpkg.conf
CRONTAB=$SYS/etc/config/crontab
Jedno przejście awk tworzy nowy plik. Każdą linię bez znacznika zostawia na jej miejscu. Z linii ze znacznikiem zostawia pierwszą kopię każdej linii, której chce pakiet, a resztę usuwa, także linie, których nie ma już w cronedit.tab. Brakujące linie dopisuje na końcu pliku:
changes=$(awk -v tag="$TAG" -v out="$new" "$AWK_OURS"'
FILENAME == ARGV[1] { if (!($0 in want)) { want[$0] = 1; order[++n] = $0 }; next }
ours($0) {
if (($0 in want) && !($0 in seen)) { seen[$0] = 1; print > out } else { dropped++ }
next
}
{ print > out }
END {
for (i = 1; i <= n; i++) if (!(order[i] in seen)) { print order[i] > out; added++ }
print dropped + 0, added + 0
}' "$want" "$old")
Gdy nic nie doszło i nic nie ubyło, plik zostaje bez zmian, a cron się nie restartuje:
set -- $changes
DROPPED=${1:-0}
ADDED=${2:-0}
if [ "$DROPPED" = 0 ] && [ "$ADDED" = 0 ]; then
rm -f "$new"
return 0
fi
Przed zapisem drugie przejście awk sprawdza, czy każda linia bez znacznika nadal jest w pliku, bez zmian i w tej samej kolejności. Jeśli nie, plik zostaje nietknięty. Po zapisie cron przeładowuje się po QNAP-owemu:
reload() {
# on the NAS: /usr/bin/crontab /etc/config/crontab && /etc/init.d/crond.sh restart
if "$SYS/usr/bin/crontab" "$CRONTAB" && "$SYS/etc/init.d/crond.sh" restart >/dev/null 2>&1; then
return 0
fi
say "the reload of cron failed (crontab /etc/config/crontab && /etc/init.d/crond.sh restart)"
event 2 "the reload of cron failed (crontab /etc/config/crontab && /etc/init.d/crond.sh restart)"
return 1
}
Wywołuje to skrypt usługi: start doprowadza plik do porządku, stop i remove (odinstalowanie) usuwają wszystkie linie ze znacznikiem. Usuwa je też start, którego nie dopuszcza przełącznik App Center, na wypadek gdyby zanik zasilania pominął stop:
service_start() {
# the command on PATH; a file of another at /usr/bin/cronedit is left alone, and bin/cronedit still works
qpkg_link "$CRONEDIT" /usr/bin/cronedit || :
"$CRONEDIT" sync
}
service_stop() {
"$CRONEDIT" cleanup
qpkg_unlink /usr/bin/cronedit "$CRONEDIT"
return 0
}
…
service_remove() {
"$CRONEDIT" cleanup
qpkg_unlink /usr/bin/cronedit "$CRONEDIT"
return 0
}
# A switched-off package's start is refused by qpkg_start; its tagged lines must not run either (a power cut skips
# the stop), so they go first.
if [ "${1-}" = start ] && ! qpkg_enabled; then
"$CRONEDIT" cleanup
fi
Gdy pakiet działa, cronedit add i cronedit remove zmieniają cronedit.tab i od razu poprawiają /etc/config/crontab. Gdy pakiet jest zatrzymany, zmiana czeka na następny start.
06Sprawdź, co napisał Claude Code
Przeczytaj zmiany, a potem uruchom to, czego sesja uruchomić nie mogła. Dla CronEdit to jego własny test na udawanym drzewie NAS-a, sh build/t/run.sh. Przeszedł. Przegląd zmienił te rzeczy:
- CronEdit: nie ma już
bin/CronEditz szablonu. Nic go nie uruchamiało, a jego nazwa różni się odbin/cronedittylko wielkością liter: w Windows i macOS jeden plik nadpisuje drugi. Claude Code to zauważył, ale usunięcie pliku wymagało zgody. Dwie linie README o tym pliku opisują terazbin/cronedit. - HelloPublic: kod bez zmian.
- Instalacja. Odpowiedź każe instalować przez
qpkg_cli -m … --keep. Dla pakietu bez podpisu to w QTS 6.1 nic nie instaluje:qpkg_cli -sodpowiada „notfound”. Sekcja 08 pokazuje, co go instaluje.
07Skompiluj pakiet
Na stronie projektu przycisk Skompiluj uruchamia bvs qbuild w środowisku kompilacji projektu. W terminalu, w folderze projektu, polecenie jest to samo:
bvs qbuild ls build/ CronEdit_0.1.0_x86_64.qpkg CronEdit_0.1.0_x86_64.qpkg.md5
Bez certyfikatu do podpisu kodu w projekcie pakiet nie ma podpisu, a Wdrożenie testowe jest wyłączone: „Wymaga pakietu z podpisem kodu”. Podpisany pakiet zainstalujesz przez Wdrożenie testowe; jak podpisać, pokazuje poradnik o App Center.
08Zainstaluj i sprawdź
Pakiet bez podpisu wypróbujesz na własnym NAS-ie tak: skopiuj plik do udostępnionego folderu i uruchom go przez SSH jako admin. QTS go instaluje i uruchamia:
# przez SSH jako admin, w udostępnionym folderze z plikiem
cd /share/Public/packages
sh ./CronEdit_0.1.0_x86_64.qpkg
…
Link service start/stop script: CronEdit.sh
Set QPKG information in /etc/config/qpkg.conf
CronEdit: started
- Pakiet zainstalowany w ten sposób nie ma linii
Statusw/etc/config/qpkg.conf. Instalacje z App Center wpisująStatus = complete. - Nie włączaj dla tych pakietów ustawienia App Center dla aplikacji bez ważnego podpisu cyfrowego. Podpisz je.
- Pakiet usuniesz w App Center albo poleceniem
qpkg_cli -R CronEdit.
HelloPublic po starcie:
P=$(getcfg Public path -f /etc/config/smb.conf) cat "$P/hello.txt" Hello world
CronEdit z dwiema liniami dodanymi w czasie pracy:
cronedit add "*/15 * * * * /bin/true" cronedit: added: */15 * * * * /bin/true cronedit: /etc/config/crontab: 1 line(s) added, 0 removed cronedit add "* * * * * /bin/date -u >> /share/Public/cronedit-demo.txt" cronedit: added: * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt cronedit: /etc/config/crontab: 1 line(s) added, 0 removed cronedit list CronEdit is started; its lines (/share/CACHEDEV1_DATA/.qpkg/CronEdit/cronedit.tab): 1 */15 * * * * /bin/true 2 * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt grep -n 'managed-by:CronEdit' /etc/config/crontab 57:*/15 * * * * /bin/true # managed-by:CronEdit 58:* * * * * /bin/date -u >> /share/Public/cronedit-demo.txt # managed-by:CronEdit /etc/init.d/CronEdit.sh status CronEdit: Enable = TRUE CronEdit: started CronEdit: every line of /share/CACHEDEV1_DATA/.qpkg/CronEdit/cronedit.tab is in /etc/config/crontab, once: yes
09Co pokazał test
Na NAS-ie z QTS 6.1 zapisaliśmy przed instalacją kopię /etc/config/crontab (58 linii) i po każdym kroku porównywaliśmy z nią plik.
| Krok | /etc/config/crontab po kroku | Restart crona |
|---|---|---|
| instalacja, jeszcze bez linii | zapisana kopia | nie |
dwa razy cronedit add w czasie pracy | dwie linie ze znacznikiem więcej | tak, po każdym |
| stop | zapisana kopia, bajt w bajt | tak |
| start | obie linie z powrotem | tak |
| drugi start | bez zmian, żadna linia dwa razy | nie |
linia usunięta z cronedit.tab, gdy stop się nie wykonał (jak po zaniku zasilania), potem start | tej linii nie ma, druga została | tak |
cronedit add, potem cronedit remove, w czasie pracy | linia dopisana, potem usunięta | tak, po każdym |
qpkg_cli -R CronEdit | zapisana kopia, bajt w bajt; crontab -l to samo | tak |
- Po każdym kroku pozostałe 58 linii były takie jak w kopii, w tej samej kolejności.
- Linia
* * * * * /bin/date -u >> /share/Public/cronedit-demo.txtzapisała pierwszy znacznik czasu w ciągu minuty: cron wykonuje linie ze znacznikiem. - Skrypt QTS
crond.sh startprzenosi własne linievs_refreshibackup_conf.shna koniec pliku już po tym, jakcrontabwczytał plik. Dlatego, gdy linie CronEdit są w pliku,crontab -lmoże pokazać te same linie w innej kolejności niż plik. - HelloPublic: po starcie
hello.txtzawierałHello world, po drugim starcie nadal jedną linię. Stop i odinstalowanie zostawiły plik na udziale Public.
10Pobierz źródła
ai-qpkg-examples.zip (170 KB) zawiera oba projekty po przeglądzie, obie prośby i README, które mówi, co napisał Claude Code, a co zmienił przegląd. Skopiuj projekt do folderu projektów i skompiluj go poleceniem bvs qbuild.