diff --git a/deploy_vps.sh b/deploy_vps.sh index 147a715..ee84edf 100755 --- a/deploy_vps.sh +++ b/deploy_vps.sh @@ -46,23 +46,30 @@ set -euo pipefail sudo -v if ! id "$APP_USER" >/dev/null 2>&1; then - sudo useradd --system --home "$APP_DIR" --shell /usr/sbin/nologin "$APP_USER" + if command -v useradd >/dev/null 2>&1; then + sudo useradd --system --home "$APP_DIR" --shell /usr/sbin/nologin "$APP_USER" + else + APP_USER="$(id -un)" + echo "useradd not found on remote host; using existing SSH user '$APP_USER' for the service." >&2 + fi fi +APP_GROUP="$(id -gn "$APP_USER")" sudo mkdir -p "$APP_DIR" /var/lib/mailcat /var/log/mailcat sudo tar -xzf /tmp/mailcat-deploy.tar.gz -C "$APP_DIR" -sudo chown -R "$APP_USER:$APP_USER" "$APP_DIR" /var/lib/mailcat /var/log/mailcat +sudo chown -R "$APP_USER:$APP_GROUP" "$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 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 +sudo chown "$APP_USER:$APP_GROUP" "$APP_DIR/config.json" 2>/dev/null || true sudo install -m 0644 "$APP_DIR/systemd/mailcat-sort.service" "/etc/systemd/system/$SERVICE_NAME.service" sudo sed -i \ -e "s#__APP_USER__#$APP_USER#g" \ + -e "s#__APP_GROUP__#$APP_GROUP#g" \ -e "s#__APP_DIR__#$APP_DIR#g" \ -e "s#__ACCOUNT__#$ACCOUNT#g" \ "/etc/systemd/system/$SERVICE_NAME.service" diff --git a/restart_prompt.md b/restart_prompt.md index 590fe83..4f4d60f 100644 --- a/restart_prompt.md +++ b/restart_prompt.md @@ -149,6 +149,7 @@ Remote/NAS deployment files: - `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`. - The deploy script uploads a temporary remote shell script and runs it with `ssh -tt`, so remote `sudo` can prompt for a password on NAS systems that require a terminal. The remote script starts with `sudo -v`. +- If the remote NAS does not have `useradd`, the deploy script falls back to the existing SSH user and that user's primary group for service ownership. - `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 remote host with mode `600` before starting the service. diff --git a/systemd/mailcat-sort.service b/systemd/mailcat-sort.service index 37cb985..7b1bf6d 100644 --- a/systemd/mailcat-sort.service +++ b/systemd/mailcat-sort.service @@ -6,7 +6,7 @@ Wants=network-online.target [Service] Type=simple User=__APP_USER__ -Group=__APP_USER__ +Group=__APP_GROUP__ WorkingDirectory=__APP_DIR__ ExecStart=/usr/bin/python3 __APP_DIR__/sort_mail_daemon.py --account __ACCOUNT__ --folder INBOX --state-file /var/lib/mailcat/sort_mail_daemon_state.json --log-file /var/log/mailcat/sort_mail_daemon.log Restart=always