5c0e345fd8
Prompts used since the previous commit: - Hieronder staat je oorspronkelijke plan. Volgens mij moet stap 'Add VPS automation' nog worden uitgevoerd, inclusief de testen. Special observations: - Added a testable IMAP sorting daemon, shared IMAP operation helpers, systemd service template, and SSH deployment script. - Local tests passed; no live VPS deployment or mailbox-affecting daemon test was run. - verplaats_log.json remains modified from the user's run and was intentionally not staged.
69 lines
2.1 KiB
Bash
Executable File
69 lines
2.1 KiB
Bash
Executable File
#!/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}"
|
|
APP_USER="${APP_USER:-mailcat}"
|
|
APP_DIR="${APP_DIR:-/opt/mailcat}"
|
|
SERVICE_NAME="${SERVICE_NAME:-mailcat-sort-backup}"
|
|
ACCOUNT="${ACCOUNT:-backup}"
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ARCHIVE="$(mktemp -t mailcat-deploy.XXXXXX.tar.gz)"
|
|
|
|
cleanup() {
|
|
rm -f "$ARCHIVE"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
tar \
|
|
--exclude ".git" \
|
|
--exclude "__pycache__" \
|
|
--exclude "mailbox" \
|
|
--exclude "config.json" \
|
|
--exclude "*.log" \
|
|
--exclude "backup_log.json" \
|
|
--exclude "verplaats_log*.json" \
|
|
--exclude "sort_mail_daemon_state.json" \
|
|
--exclude "mailing_lists_cache*.json" \
|
|
--exclude "*.pyc" \
|
|
-C "$ROOT_DIR" \
|
|
-czf "$ARCHIVE" .
|
|
|
|
scp "$ARCHIVE" "$VPS_USER@$VPS_HOST:/tmp/mailcat-deploy.tar.gz"
|
|
|
|
ssh "$VPS_USER@$VPS_HOST" \
|
|
"APP_USER='$APP_USER' APP_DIR='$APP_DIR' SERVICE_NAME='$SERVICE_NAME' ACCOUNT='$ACCOUNT' bash -s" <<'REMOTE'
|
|
set -euo pipefail
|
|
|
|
if ! id "$APP_USER" >/dev/null 2>&1; then
|
|
sudo useradd --system --home "$APP_DIR" --shell /usr/sbin/nologin "$APP_USER"
|
|
fi
|
|
|
|
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 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
|
|
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 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_DIR__#$APP_DIR#g" \
|
|
-e "s#__ACCOUNT__#$ACCOUNT#g" \
|
|
"/etc/systemd/system/$SERVICE_NAME.service"
|
|
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable "$SERVICE_NAME.service"
|
|
|
|
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
|