Handle NAS deploy without useradd

Prompts used since the previous commit:
- sudo: useradd: command not found

Special observations:
- If useradd is unavailable, remote deployment now falls back to the existing SSH user and primary group.
- The systemd template now has a separate group placeholder.
- verplaats_log.json remains modified from the user's run and was intentionally not staged.
This commit is contained in:
2026-07-04 20:07:35 +02:00
parent cf83946795
commit 32cee7c65f
3 changed files with 12 additions and 4 deletions
+10 -3
View File
@@ -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"