Find NAS useradd outside PATH
Prompts used since the previous commit: - De nas heeft wel een useradd commando. Als ik inlog, kan ik useradd uitvoeren Special observations: - Non-interactive SSH sessions may omit /usr/sbin from PATH, so deployment now searches common sbin paths for useradd and nologin. - verplaats_log.json remains modified from the user's run and was intentionally not staged.
This commit is contained in:
+23
-2
@@ -45,9 +45,30 @@ set -euo pipefail
|
||||
|
||||
sudo -v
|
||||
|
||||
find_command() {
|
||||
local name="$1"
|
||||
shift
|
||||
if command -v "$name" >/dev/null 2>&1; then
|
||||
command -v "$name"
|
||||
return 0
|
||||
fi
|
||||
for candidate in "$@"; do
|
||||
if [ -x "$candidate" ]; then
|
||||
printf '%s\n' "$candidate"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! id "$APP_USER" >/dev/null 2>&1; then
|
||||
if command -v useradd >/dev/null 2>&1; then
|
||||
sudo useradd --system --home "$APP_DIR" --shell /usr/sbin/nologin "$APP_USER"
|
||||
if USERADD="$(find_command useradd /usr/sbin/useradd /sbin/useradd)"; then
|
||||
NOLOGIN="$(find_command nologin /usr/sbin/nologin /sbin/nologin || true)"
|
||||
if [ -n "$NOLOGIN" ]; then
|
||||
sudo "$USERADD" --system --home "$APP_DIR" --shell "$NOLOGIN" "$APP_USER"
|
||||
else
|
||||
sudo "$USERADD" --system --home "$APP_DIR" "$APP_USER"
|
||||
fi
|
||||
else
|
||||
APP_USER="$(id -un)"
|
||||
echo "useradd not found on remote host; using existing SSH user '$APP_USER' for the service." >&2
|
||||
|
||||
Reference in New Issue
Block a user