Allow remote NAS deployment target

Prompts used since the previous commit:
- Ik wil dit testen op mijn NAS, die lokaal hier in huis draait. Dus niet op vps.australius.nl. Kan dat ook?

Special observations:
- deploy_vps.sh now accepts REMOTE_HOST and REMOTE_USER, with VPS_HOST/VPS_USER kept as aliases.
- The current service install path still assumes a Linux/systemd target with sudo; Synology/QNAP-style NAS deployment may need scheduler or container adaptation.
- verplaats_log.json remains modified from the user's run and was intentionally not staged.
This commit is contained in:
2026-07-04 20:02:43 +02:00
parent 5c0e345fd8
commit 5932e8927e
2 changed files with 25 additions and 17 deletions
+13 -5
View File
@@ -1,8 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
VPS_HOST="${VPS_HOST:-vps.austalius.nl}"
VPS_USER="${VPS_USER:?Set VPS_USER to the non-root sudo SSH user}"
REMOTE_HOST="${REMOTE_HOST:-${VPS_HOST:-}}"
REMOTE_USER="${REMOTE_USER:-${VPS_USER:-}}"
if [ -z "$REMOTE_HOST" ]; then
echo "Set REMOTE_HOST to the SSH host or IP address, for example a local NAS hostname." >&2
exit 2
fi
if [ -z "$REMOTE_USER" ]; then
echo "Set REMOTE_USER to the non-root sudo SSH user." >&2
exit 2
fi
APP_USER="${APP_USER:-mailcat}"
APP_DIR="${APP_DIR:-/opt/mailcat}"
SERVICE_NAME="${SERVICE_NAME:-mailcat-sort-backup}"
@@ -30,9 +38,9 @@ tar \
-C "$ROOT_DIR" \
-czf "$ARCHIVE" .
scp "$ARCHIVE" "$VPS_USER@$VPS_HOST:/tmp/mailcat-deploy.tar.gz"
scp "$ARCHIVE" "$REMOTE_USER@$REMOTE_HOST:/tmp/mailcat-deploy.tar.gz"
ssh "$VPS_USER@$VPS_HOST" \
ssh "$REMOTE_USER@$REMOTE_HOST" \
"APP_USER='$APP_USER' APP_DIR='$APP_DIR' SERVICE_NAME='$SERVICE_NAME' ACCOUNT='$ACCOUNT' bash -s" <<'REMOTE'
set -euo pipefail
@@ -46,7 +54,7 @@ sudo chown -R "$APP_USER:$APP_USER" "$APP_DIR" /var/lib/mailcat /var/log/mailcat
sudo chmod 750 "$APP_DIR"
if [ ! -f "$APP_DIR/config.json" ]; then
echo "Missing $APP_DIR/config.json on VPS. Create it with mode 600 before starting the service." >&2
echo "Missing $APP_DIR/config.json on remote host. Create it with mode 600 before starting the service." >&2
fi
sudo chmod 600 "$APP_DIR/config.json" 2>/dev/null || true
sudo chown "$APP_USER:$APP_USER" "$APP_DIR/config.json" 2>/dev/null || true
+12 -12
View File
@@ -9,9 +9,9 @@ Build a reliable mailbox cleanup and automation toolkit for `australius.nl`.
The project started as an offline analysis of a local mailbox export and is being moved toward an IMAP-based sorter because Sieve does not work with the email provider. The intended production model is:
- Email is hosted at `australius.nl`.
- A VPS is available at `vps.austalius.nl`.
- A VPS is available at `vps.austalius.nl`, but the user now wants to test automation first on a local home NAS instead of the VPS.
- The test mailbox is `backup@australius.nl`.
- The future automation should run on the VPS, preferably via SSH deployment and an IMAP IDLE daemon.
- The future automation should run on an always-on remote host, preferably via SSH deployment and an IMAP IDLE daemon. The current deploy path assumes a Linux/systemd target with sudo; if the NAS does not support that, adapt the run method to the NAS scheduler or container tooling.
- The current end-to-end test uses the `backup` account as a disposable test target.
## Repository State
@@ -135,7 +135,7 @@ Shared operation helpers:
`sort_mail_daemon.py` current behavior:
- Intended VPS automation entry point for IMAP sorting.
- Intended remote-host automation entry point for IMAP sorting.
- Defaults to `--account backup` and `--folder INBOX`.
- Uses the same shared routing policy through `mail_imap_ops.destination_from_header()`.
- Maintains a JSON state file of processed UIDs per folder and resets that state when UIDVALIDITY changes.
@@ -144,12 +144,12 @@ Shared operation helpers:
- Logs to `sort_mail_daemon.log` by default, or to the path passed with `--log-file`.
- Ensures the destination mailbox exists before moving a message, then moves by UID COPY plus UID STORE `\Deleted`, followed by expunge after a scan.
VPS deployment files:
Remote/NAS deployment files:
- `deploy_vps.sh` packages the repo excluding `.git`, `config.json`, logs, runtime JSON state/log files, bytecode, and local mailbox data; uploads to `vps.austalius.nl`; installs under `/opt/mailcat` by default; creates/uses a non-root system user named `mailcat` by default; installs a systemd service; enables but does not start the service.
- The deploy script requires `VPS_USER` to be set to the non-root sudo SSH user. Optional overrides: `VPS_HOST`, `APP_USER`, `APP_DIR`, `SERVICE_NAME`, and `ACCOUNT`.
- `deploy_vps.sh` is host-neutral despite its historical filename. It packages the repo excluding `.git`, `config.json`, logs, runtime JSON state/log files, bytecode, and local mailbox data; uploads to the SSH host in `REMOTE_HOST`; installs under `/opt/mailcat` by default; creates/uses a non-root system user named `mailcat` by default; installs a systemd service; enables but does not start the service.
- The deploy script requires `REMOTE_HOST` and `REMOTE_USER`. The old `VPS_HOST` and `VPS_USER` names still work as aliases. Optional overrides: `APP_USER`, `APP_DIR`, `SERVICE_NAME`, and `ACCOUNT`.
- `systemd/mailcat-sort.service` is a template consumed by `deploy_vps.sh`; after placeholder replacement it runs `sort_mail_daemon.py --account backup --folder INBOX` and stores state/logs under `/var/lib/mailcat` and `/var/log/mailcat`.
- `config.json` remains ignored and must be created manually on the VPS with mode `600` before starting the service.
- `config.json` remains ignored and must be created manually on the remote host with mode `600` before starting the service.
## Current Backup Test Status
@@ -237,16 +237,16 @@ Latest live mailbox verification:
- The user started an actual sorter run on `backup@australius.nl`; it began moving messages from `INBOX` and then crashed on an unexpected IMAP `FETCH` response shape: `AttributeError: 'int' object has no attribute 'decode'`. The local `verplaats_log.json` contains processed `INBOX:<uid>` entries from that run and should be preserved if the user resumes sorting. The current code fixes this parser crash.
- A later read-only INBOX inspection of the `backup` account found 1,908 unmatched messages and identified additional candidate sender domains. No mailbox-affecting script was run by Codex.
- After the latest routing refinements, the user reported the backup sorter ended with `Totaal gepland: 0 | Totaal geen match: 2218 | Totaal overgeslagen: 8219 | Totaal fouten: 0`. Treat this as a successful backup historical-sorter run with no immediate recovery work needed.
- VPS deployment and daemon live tests have not yet been run by Codex.
- Remote NAS/systemd deployment and daemon live tests have not yet been run by Codex.
## What To Do Next
Recommended next work:
1. Ask the user for the VPS non-root sudo SSH username.
2. Before starting the service, ensure `/opt/mailcat/config.json` on the VPS contains the `backup` account credentials and has mode `600`.
3. Deploy with a command like `VPS_USER=<ssh-user> ./deploy_vps.sh`.
4. On the VPS, start and inspect the service:
1. Ask the user for the NAS SSH hostname/IP, SSH username, and whether the NAS has Linux/systemd with sudo. If it is a Synology/QNAP-style NAS without systemd, adapt the run method to its scheduler or container tooling before deploying.
2. Before starting the service, ensure `/opt/mailcat/config.json` on the NAS contains the `backup` account credentials and has mode `600`.
3. Deploy to a Linux/systemd NAS with a command like `REMOTE_HOST=<nas-host> REMOTE_USER=<ssh-user> ./deploy_vps.sh`.
4. On the NAS, start and inspect the service:
- `sudo systemctl start mailcat-sort-backup.service`
- `sudo systemctl status mailcat-sort-backup.service`
- `sudo journalctl -u mailcat-sort-backup.service -f`