Allow sudo password prompts during remote deploy
Prompts used since the previous commit: - sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper - sudo: a password is required Special observations: - deploy_vps.sh now uploads a temporary remote install script and executes it with ssh -tt so sudo can prompt on a terminal. - The remote script starts with sudo -v to validate credentials once before install steps. - verplaats_log.json remains modified from the user's run and was intentionally not staged.
This commit is contained in:
+12
-4
@@ -18,9 +18,11 @@ ACCOUNT="${ACCOUNT:-backup}"
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ARCHIVE="$(mktemp -t mailcat-deploy.XXXXXX.tar.gz)"
|
||||
REMOTE_SCRIPT="$(mktemp -t mailcat-remote-deploy.XXXXXX.sh)"
|
||||
|
||||
cleanup() {
|
||||
rm -f "$ARCHIVE"
|
||||
rm -f "$REMOTE_SCRIPT"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
@@ -38,12 +40,11 @@ tar \
|
||||
-C "$ROOT_DIR" \
|
||||
-czf "$ARCHIVE" .
|
||||
|
||||
scp "$ARCHIVE" "$REMOTE_USER@$REMOTE_HOST:/tmp/mailcat-deploy.tar.gz"
|
||||
|
||||
ssh "$REMOTE_USER@$REMOTE_HOST" \
|
||||
"APP_USER='$APP_USER' APP_DIR='$APP_DIR' SERVICE_NAME='$SERVICE_NAME' ACCOUNT='$ACCOUNT' bash -s" <<'REMOTE'
|
||||
cat > "$REMOTE_SCRIPT" <<'REMOTE'
|
||||
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"
|
||||
fi
|
||||
@@ -68,9 +69,16 @@ sudo sed -i \
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable "$SERVICE_NAME.service"
|
||||
rm -f /tmp/mailcat-deploy.tar.gz /tmp/mailcat-remote-deploy.sh
|
||||
|
||||
echo "Deployment complete."
|
||||
echo "Create/check $APP_DIR/config.json, then run:"
|
||||
echo " sudo systemctl start $SERVICE_NAME.service"
|
||||
echo " sudo journalctl -u $SERVICE_NAME.service -f"
|
||||
REMOTE
|
||||
|
||||
scp "$ARCHIVE" "$REMOTE_USER@$REMOTE_HOST:/tmp/mailcat-deploy.tar.gz"
|
||||
scp "$REMOTE_SCRIPT" "$REMOTE_USER@$REMOTE_HOST:/tmp/mailcat-remote-deploy.sh"
|
||||
|
||||
REMOTE_COMMAND=$(printf "APP_USER=%q APP_DIR=%q SERVICE_NAME=%q ACCOUNT=%q bash /tmp/mailcat-remote-deploy.sh" "$APP_USER" "$APP_DIR" "$SERVICE_NAME" "$ACCOUNT")
|
||||
ssh -tt "$REMOTE_USER@$REMOTE_HOST" "$REMOTE_COMMAND"
|
||||
|
||||
@@ -148,6 +148,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`.
|
||||
- `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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user