Unofficial
Auf dieser Seite
  1. 01Voraussetzungen
  2. 02Sitzung starten
  3. 03HelloPublic anfordern
  4. 04CronEdit anfordern
  5. 05Die crontab-Regeln im Code
  6. 06Den Code von Claude Code prüfen
  7. 07Paket bauen
  8. 08Paket installieren und prüfen
  9. 09Testergebnisse
  10. 10Quellcode herunterladen

Claude Code um ein QPKG bitten: „Hello world“ im Freigabeordner Public und ein crontab-Editor

Claude Code läuft auf Ihrem NAS in einer Umgebung von Bucket & Code Server IDE. Sie starten die Sitzung über das Panel, das Terminal des Editors, claude.ai/code oder die App auf Ihrem Telefon. Beschreiben Sie in einfachen Worten, was das Paket tun soll. Diese Anleitung zeigt zwei Prompts aus echten Sitzungen. HelloPublic schreibt „Hello world“ in eine Datei im Freigabeordner Public. CronEdit trägt eigene Zeilen nach den Regeln von QNAP in die crontab des NAS ein.

  1. Sitzungim Projektordner
  2. PromptFunktion des Pakets beschreiben
  3. PrüfenCode lesen und testen
  4. Bauenbvs qbuild
  5. Installierenund prüfen

Die Screenshots zeigen Bucket & Code Server IDE 1.0.0-102 mit dem Konto ola. Claude Code ist in der Umgebung installiert. Bei Claude Code ist niemand angemeldet. Daher zeigt diese Anleitung die Sitzung als Text. Die Prompts und Antworten stammen aus echten Sitzungen mit Claude Code.

01Voraussetzungen

  • Legen Sie über Neues Projekt ein Projekt mit der Vorlage QPKG-Paket an. Das Projekt enthält den Skill .claude/skills/qnap-dev und die Datei AGENTS.md. Claude Code liest den Skill und schreibt Code für das NAS. Der Code verwendet BusyBox sh, /etc/config und die Systemprotokolle.
  • Installieren Sie Claude Code in einer Umgebung. Wählen Sie Toolchains → die Umgebung → KI-Werkzeuge → Claude Code → Installieren. Wählen Sie im selben Dialog Bei Claude anmelden. Melden Sie sich mit Ihrem eigenen Konto an.
  • Sie brauchen ein Konto mit der Rolle developer oder admin. Auf dem NAS installiert ein Administrator das Paket.

02Sitzung starten

Auf allen folgenden Wegen starten Sie dieselbe Installation von Claude Code in der Umgebung. Starten Sie die Sitzung im Projektordner, damit Claude Code den Skill des Projekts liest.

  • Im Panel. Öffnen Sie in KI-Werkzeuge die Registerkarte Claude Code. Wählen Sie im Feld Ordner das Projekt aus und klicken Sie auf Neue Sitzung starten. Die Sitzung läuft im Jail der Umgebung. Sie läuft weiter, wenn Sie die Seite schließen. Auf der Seite Terminal finden Sie die Sitzung wieder. KI-Werkzeuge in ubuntu2404-builder, Registerkarte Claude Code: installiert, Konto mit Nicht angemeldet und Bei Claude anmelden, Sitzung starten mit Ordner, Alle Projekte und Neue Sitzung starten, Unterhaltung fortsetzen, Sitzungseinstellungen
  • Im Terminal des Editors. Der Link Oder im Terminal des Editors starten unter der Schaltfläche öffnet die Sitzung im Terminal des Editors. Die Sitzung endet, wenn Sie die Registerkarte des Editors schließen.
  • Über claude.ai/code oder die Claude-App. Nach der Anmeldung zeigt dieselbe Registerkarte Remote Control mit dem Hinweis „Sitzungen dieser Umgebung lassen sich über claude.ai/code und die Claude-App starten und steuern.“ Aktivieren Sie die Funktion und wählen Sie dort diese Umgebung aus.
  • Auf dem Telefon. Koppeln Sie die App von Bucket & Code auf der Seite Telefon-App im Panel. Öffnen Sie in der App die Registerkarte KI. Wählen Sie die Umgebung, den Ordner und das Werkzeug. Wählen Sie dann Neue Unterhaltung starten.

03HelloPublic anfordern

Geben Sie im Ordner eines neuen Projekts namens HelloPublic genau diesen Prompt ein:

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.

Der Startcode von Claude Code steht in shared/HelloPublic.sh. Der Pfad zu Public stammt aus QTS. Das Skript überschreibt die Datei, sodass sie auch nach einem zweiten Start genau eine Zeile enthält:

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"
}
}

Die Antwort in gekürzter Form. In dieser Sitzung kann Claude Code die Dateien bearbeiten und ihre Syntax prüfen. Die Skripte kann Claude Code in dieser Sitzung nicht ausführen. Das steht auch in der Antwort:

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.
…

04CronEdit anfordern

Der Prompt führt die Regeln von QNAP für cron einzeln auf. So finden Sie jede Regel später im Code:

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.

Die Antwort in gekürzter Form:

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`.

05Die crontab-Regeln im Code

CronEdit speichert seine Zeilen in cronedit.tab im Paketordner. Das Programm bin/cronedit schreibt sie in /etc/config/crontab. Diese Datei bleibt bei einem Neustart erhalten. Jede Zeile, die das Programm schreibt, endet mit der Markierung. Das Programm ändert nur Zeilen, die damit enden:

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

Ein awk-Durchlauf erzeugt die neue Datei. Zeilen ohne Markierung bleiben an ihrer Stelle. Von jeder markierten Zeile, die das Paket braucht, übernimmt awk das erste Vorkommen. Alle anderen markierten Zeilen lässt awk aus, auch Zeilen, die nicht mehr in cronedit.tab stehen. Fehlende Zeilen fügt awk am Dateiende hinzu:

  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")

Wenn keine Zeile hinzukommt oder wegfällt, bleibt die Datei unverändert und cron startet nicht neu:

  set -- $changes
  DROPPED=${1:-0}
  ADDED=${2:-0}
  if [ "$DROPPED" = 0 ] && [ "$ADDED" = 0 ]; then
    rm -f "$new"
    return 0
  fi

Vor dem Schreiben prüft ein zweiter awk-Durchlauf, ob jede Zeile ohne Markierung unverändert und in derselben Reihenfolge vorhanden ist. Andernfalls bleibt die Datei unverändert. Nach dem Schreiben lädt das Programm cron nach QNAP-Vorgabe neu:

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
}

Das Dienstskript ruft das Programm auf. Bei start gleicht das Programm die Datei ab. Bei stop und remove (Deinstallation) entfernt es alle markierten Zeilen. Sperrt der Schalter in App Center den Start, entfernt das Programm die markierten Zeilen ebenfalls. Das ist nötig, wenn ein Stromausfall den regulären Stopp verhindert:

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

Während das Paket läuft, ändern cronedit add und cronedit remove die Datei cronedit.tab und gleichen /etc/config/crontab sofort ab. Ist das Paket gestoppt, erfolgt der Abgleich beim nächsten Start.

06Den Code von Claude Code prüfen

Lesen Sie den Diff. Führen Sie dann aus, was Claude Code in der Sitzung nicht ausführen kann. Bei CronEdit ist das der eigene Test mit einer nachgebildeten NAS-Verzeichnisstruktur. Starten Sie ihn mit sh build/t/run.sh. Im Testlauf besteht CronEdit die Prüfung. Aus der Prüfung ergeben sich folgende Änderungen:

  • Bei CronEdit fehlt jetzt die Vorlagendatei bin/CronEdit. Das Paket ruft sie nirgends auf. Ihr Name unterscheidet sich von bin/cronedit nur in der Groß- und Kleinschreibung. Unter Windows oder macOS überschreibt deshalb eine Datei die andere. Claude Code erkennt das Problem. Zum Löschen braucht die Sitzung eine Freigabe. Die beiden Zeilen in der README beschreiben jetzt bin/cronedit.
  • HelloPublic: keine Codeänderung.
  • Installation. Die Antwort nennt qpkg_cli -m … --keep als Installationsbefehl. Unter QTS 6.1 schlägt die Installation eines unsignierten Pakets damit fehl. qpkg_cli -s meldet „notfound“. Abschnitt 08 zeigt, wie die Installation gelingt.

07Paket bauen

Auf der Projektseite startet Bauen den Befehl bvs qbuild in der Build-Umgebung des Projekts. Im Terminal führen Sie denselben Befehl im Projektordner aus:

bvs qbuild
ls build/
CronEdit_0.1.0_x86_64.qpkg  CronEdit_0.1.0_x86_64.qpkg.md5
Projektschritte nach „Bauen“. Der Build ist fertig. Die Schaltflächen heißen „Erneut bauen“ und „Neu bauen“. „Testeinsatz“ ist deaktiviert und zeigt „Braucht ein codesigniertes Paket“. Darunter steht, dass der Testeinsatz ein codesigniertes Paket braucht und der Build keine Signatur hat.

Ohne Codesignaturzertifikat im Projekt bleibt das Paket unsigniert. Testeinsatz bleibt dann deaktiviert und zeigt „Braucht ein codesigniertes Paket“. Ein signiertes Paket installieren Sie über Testeinsatz. Die Anleitung zu App Center zeigt, wie Sie das Paket signieren.

08Paket installieren und prüfen

Kopieren Sie das unsignierte Paket zum Testen in einen Freigabeordner auf Ihrem NAS. Melden Sie sich per SSH als admin an und führen Sie die Datei aus. QTS installiert und startet das Paket:

# per SSH als admin im Freigabeordner mit der Datei
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
  • Bei dieser Installation erhält das Paket keinen Status-Eintrag in /etc/config/qpkg.conf. Bei einer Installation über App Center lautet der Eintrag Status = complete.
  • Lassen Sie die Einstellung für Apps ohne gültige digitale Signatur in App Center deaktiviert und signieren Sie diese Pakete.
  • Entfernen Sie ein Paket über App Center oder mit qpkg_cli -R CronEdit.

HelloPublic nach dem Start:

P=$(getcfg Public path -f /etc/config/smb.conf)
cat "$P/hello.txt"
Hello world

CronEdit nach dem Hinzufügen von zwei Zeilen im laufenden Betrieb:

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

09Testergebnisse

Für den Test auf einem NAS mit QTS 6.1 speichern wir vor der Installation eine Kopie von /etc/config/crontab (58 Zeilen) und vergleichen die Datei nach jedem Schritt mit dieser Kopie.

Schritt/etc/config/crontab danachNeustart von cron
Installation, noch keine Zeilenentspricht der Kopienein
zweimal cronedit add im laufenden Betriebzwei zusätzliche markierte Zeilenja, nach jedem Aufruf
stoppenbytegenau wie die Kopieja
startenbeide Zeilen wieder vorhandenja
erneut startenunverändert, keine doppelten Zeilennein
ohne vorherigen Stopp (wie nach einem Stromausfall) eine Zeile aus cronedit.tab entfernen, dann startendiese Zeile ist entfernt, die andere bleibtja
cronedit add, dann cronedit remove, im laufenden BetriebZeile hinzugefügt, dann entferntja, nach jedem Aufruf
qpkg_cli -R CronEditbytegenau wie die Kopie, auch bei crontab -lja
  • Nach jedem Schritt entsprechen die 58 übrigen Zeilen der Kopie und stehen in derselben Reihenfolge.
  • Die Zeile * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt schreibt innerhalb einer Minute den ersten Zeitstempel. cron führt die markierten Zeilen aus.
  • In QTS verschiebt crond.sh start die systemeigenen Zeilen für vs_refresh und backup_conf.sh ans Dateiende, nachdem crontab die Datei geladen hat. Solange die Zeilen von CronEdit eingetragen sind, kann crontab -l dieselben Zeilen in einer anderen Reihenfolge als in der Datei ausgeben.
  • Nach dem Start von HelloPublic enthält hello.txt genau eine Zeile mit Hello world. Auch nach dem zweiten Start enthält die Datei genau eine Zeile. Beim Stoppen und Deinstallieren bleibt sie im Freigabeordner Public.

10Quellcode herunterladen

ai-qpkg-examples.zip (170 KB) enthält beide Projekte in der geprüften Fassung, die beiden Prompts und eine README. Die README nennt den Code von Claude Code und die Änderungen aus der Prüfung. Kopieren Sie eines der Projekte in den Ordner für Ihre Projekte. Bauen Sie das Paket mit bvs qbuild.