diff --git a/deploy_vps.sh b/deploy_vps.sh index ee84edf..c683883 100755 --- a/deploy_vps.sh +++ b/deploy_vps.sh @@ -45,9 +45,30 @@ set -euo pipefail sudo -v +find_command() { + local name="$1" + shift + if command -v "$name" >/dev/null 2>&1; then + command -v "$name" + return 0 + fi + for candidate in "$@"; do + if [ -x "$candidate" ]; then + printf '%s\n' "$candidate" + return 0 + fi + done + return 1 +} + if ! id "$APP_USER" >/dev/null 2>&1; then - if command -v useradd >/dev/null 2>&1; then - sudo useradd --system --home "$APP_DIR" --shell /usr/sbin/nologin "$APP_USER" + if USERADD="$(find_command useradd /usr/sbin/useradd /sbin/useradd)"; then + NOLOGIN="$(find_command nologin /usr/sbin/nologin /sbin/nologin || true)" + if [ -n "$NOLOGIN" ]; then + sudo "$USERADD" --system --home "$APP_DIR" --shell "$NOLOGIN" "$APP_USER" + else + sudo "$USERADD" --system --home "$APP_DIR" "$APP_USER" + fi else APP_USER="$(id -un)" echo "useradd not found on remote host; using existing SSH user '$APP_USER' for the service." >&2 diff --git a/restart_prompt.md b/restart_prompt.md index 4f4d60f..aeabd0a 100644 --- a/restart_prompt.md +++ b/restart_prompt.md @@ -149,7 +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. +- The deploy script searches both PATH and common sbin locations such as `/usr/sbin/useradd` and `/sbin/useradd`. If `useradd` is genuinely unavailable, it 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.