mailwolt-installer/scripts/92-sudoers-npm.sh

33 lines
958 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/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" <<EOF
Defaults!${NPM_BIN} !requiretty
mailwolt ALL=(root) NOPASSWD: ${NPM_BIN}
EOF
chown root:root "$SUDOERS_FILE"
chmod 440 "$SUDOERS_FILE"
# 3) Validieren
if visudo -c -f "$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