diff --git a/scripts/88-update-wrapper.sh b/scripts/88-update-wrapper.sh index ebd7c07..6a7aa97 100644 --- a/scripts/88-update-wrapper.sh +++ b/scripts/88-update-wrapper.sh @@ -4,12 +4,17 @@ source ./lib.sh log "Update-Wrapper & Sudoers …" -# Pfade WRAPPER="/usr/local/sbin/mw-update" LOGFILE="/var/log/mailwolt-update.log" STATEDIR="/var/lib/mailwolt/update" SUDOERS="/etc/sudoers.d/mailwolt-update" -UPDATE_SCRIPT="/mailwolt-installer/scripts/update.sh" + +# Kandidaten: wo liegt update.sh? +CANDIDATES=( + /opt/mailwolt-installer/scripts/update.sh + /mailwolt-installer/scripts/update.sh + /usr/local/lib/mailwolt/update.sh +) # State/Log vorbereiten install -d -m 0755 "$(dirname "$LOGFILE")" @@ -24,19 +29,42 @@ set -euo pipefail LOG="/var/log/mailwolt-update.log" STATE_DIR="/var/lib/mailwolt/update" -SCRIPT="/mailwolt-installer/scripts/update.sh" + +CANDIDATES=( + /opt/mailwolt-installer/scripts/update.sh + /mailwolt-installer/scripts/update.sh + /usr/local/lib/mailwolt/update.sh +) + +SCRIPT="" +for p in "${CANDIDATES[@]}"; do + if [[ -x "$p" ]]; then SCRIPT="$p"; break; fi + # falls nicht executable, aber lesbar: über bash ausführen + if [[ -f "$p" && -r "$p" ]]; then SCRIPT="$p"; break; fi +done install -d -m 0755 "$STATE_DIR" echo "running" > "$STATE_DIR/state" { echo "===== $(date -Is) :: Update gestartet =====" - if [[ -x "$SCRIPT" ]]; then - "$SCRIPT" - rc=$? - else - echo "[!] $SCRIPT nicht gefunden oder nicht ausführbar" + if [[ -z "$SCRIPT" ]]; then + echo "[!] update.sh nicht gefunden oder nicht ausführbar" rc=127 + else + if [[ "$(id -u)" -ne 0 ]]; then + echo "[!] Bitte als root ausführen" + rc=1 + else + # Env aus REQUEST durchreichen (falls via sudo aufgerufen) + # und Script starten; wenn nicht executable → über bash starten + if [[ -x "$SCRIPT" ]]; then + "$SCRIPT" + else + bash "$SCRIPT" + fi + rc=$? + fi fi echo "===== $(date -Is) :: Update beendet (rc=$rc) =====" echo "$rc" > "$STATE_DIR/rc" @@ -44,15 +72,17 @@ echo "running" > "$STATE_DIR/state" exit "$rc" } | tee -a "$LOG" EOF + chmod 0755 "$WRAPPER" chown root:root "$WRAPPER" -# Sudoers erlauben, dass www-data & mailwolt den Wrapper ohne PW starten dürfen +# Sudoers: www-data (Laravel) & mailwolt dürfen den Wrapper laufen lassen cat > "$SUDOERS" <<'EOF' Defaults!/usr/local/sbin/mw-update !requiretty -www-data ALL=(root) NOPASSWD: /usr/local/sbin/mw-update -mailwolt ALL=(root) NOPASSWD: /usr/local/sbin/mw-update +www-data ALL=(root) NOPASSWD: /usr/local/sbin/mw-update +mailwolt ALL=(root) NOPASSWD: /usr/local/sbin/mw-update EOF + chown root:root "$SUDOERS" chmod 440 "$SUDOERS" diff --git a/scripts/92-sudoers-npm.sh b/scripts/92-sudoers-npm.sh new file mode 100644 index 0000000..6f07a93 --- /dev/null +++ b/scripts/92-sudoers-npm.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail +source ./lib.sh + +log "Sudoers: npm-Build ohne Passwort für user 'mailwolt' …" + +# 1) npm-Binary ermitteln (normal: /usr/bin/npm) +NPM_BIN="$(command -v npm || true)" + +if [[ -z "$NPM_BIN" ]]; then + warn "npm wurde nicht gefunden – sudoers wird vorbereitet, aber ohne Validierung. Stelle sicher, dass Node/npm installiert ist." + # Fallback – die meisten Distros legen hier an + NPM_BIN="/usr/bin/npm" +fi + +SUDOERS_FILE="/etc/sudoers.d/mailwolt-npm" + +# 2) Sudoers-Datei schreiben +cat > "$SUDOERS_FILE" </dev/null 2>&1; then + log "[✓] sudoers OK: ${SUDOERS_FILE} erlaubt 'mailwolt' → ${NPM_BIN} ohne Passwort." +else + echo "[!] Ungültiger sudoers-Eintrag in ${SUDOERS_FILE} – entferne Datei." + rm -f "$SUDOERS_FILE" +fi \ No newline at end of file diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 1cb9d27..e79e9a1 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -211,7 +211,8 @@ for STEP in \ 20-ssl 21-le-deploy-hook 22-dkim-helper \ 30-db 40-postfix 50-dovecot \ 60-rspamd-opendkim 61-opendmarc 62-clamav 63-fail2ban \ - 70-nginx 75-le-issue 80-app 88-update-wrapper 90-services 95-woltguard 98-motd 99-summary + 70-nginx 75-le-issue 80-app 88-update-wrapper 90-services \ + 92-sudoers-npm 95-woltguard 98-motd 99-summary do log ">>> Running ${STEP}.sh" bash "./${STEP}.sh"