diff --git a/tools/nextwks.sh b/tools/nextwks.sh index 40e8ad7..1dc9b5f 100755 --- a/tools/nextwks.sh +++ b/tools/nextwks.sh @@ -83,6 +83,9 @@ if [ "$MODE" = "install" ]; then read -sp "SMTP password: " SMTP_PASS; echo "" [ -z "$SMTP_PASS" ] && echo "ERROR: SMTP password required" && exit 1 + read -p "IMAP host [imap.openxchange.eu]: " IMAP_HOST; IMAP_HOST="${IMAP_HOST:-imap.openxchange.eu}" + read -p "IMAP port [993]: " IMAP_PORT; IMAP_PORT="${IMAP_PORT:-993}" + # Persist config to backup vault mkdir -p "$BACKUP_DIR" cat > "$BACKUP_DIR/.env" </dev/null || true - podman rm caddy authelia launcher 2>/dev/null || true rm -rf "$TARGET_DIR" mkdir -p "$TARGET_DIR/config/caddy" "$TARGET_DIR/config/authelia" \ "$TARGET_DIR/data/caddy" "$TARGET_DIR/data/authelia" \ @@ -210,7 +213,42 @@ if [ "$MODE" != "update" ]; then fi # ============================================================ -# 8. DEPLOY stack +# 8. STOP old containers (all modes) +# ============================================================ +echo "[*] Stopping any previous containers..." +for c in caddy authelia launcher; do + podman stop "$c" 2>/dev/null && echo " stopped $c" || true + podman rm "$c" 2>/dev/null && echo " removed $c" || true +done +sleep 1 + +# ============================================================ +# 9. PORT CHECK — before deploy +# ============================================================ +if ss -tlnp 2>/dev/null | grep -q ':80 '; then + echo "==============================================" + echo "[WARN] Port 80 is already in use." + ss -tlnp 2>/dev/null | grep ':80 ' + echo "" + echo " This is usually Caddy from a previous run." + echo " Run this to stop it, then re-run deploy:" + echo " podman stop caddy && podman rm caddy" + echo "==============================================" + echo "" + read -p "Stop the container on port 80 now? [y/N]: " KILL + if [ "$KILL" = "y" ] || [ "$KILL" = "Y" ]; then + podman stop caddy 2>/dev/null || true + podman rm caddy 2>/dev/null || true + sleep 2 + echo "[OK] Port 80 freed." + else + echo "[ABORT] Free port 80 first, then re-run." + exit 1 + fi +fi + +# ============================================================ +# 10. DEPLOY stack # ============================================================ echo "[*] Deploying containers on $NETWORK_NAME..." @@ -234,7 +272,7 @@ sleep 1 podman-compose -f "$TARGET_DIR/compose/stack.yaml" up -d 2>&1 || echo "[WARN] Stack deploy had issues" # ============================================================ -# 9. HEALTH CHECK +# 11. HEALTH CHECK # ============================================================ echo "[*] Running health check..." for i in $(seq 1 $HEALTH_CHECK_RETRIES); do @@ -248,4 +286,10 @@ for i in $(seq 1 $HEALTH_CHECK_RETRIES); do done echo "[FAIL] Health check failed — launcher did not respond" +echo "" +echo "--- Container status ---" +podman ps -a --filter "name=caddy|authelia|launcher" 2>/dev/null || true +echo "" +echo "--- Launcher logs (last 20 lines) ---" +podman logs launcher --tail 20 2>/dev/null || echo " (no logs)" exit 1