rstudio/pam_script_auth.sh

20 lines
647 B
Bash
Executable File

#!/bin/bash
if [ -z "$PAM_USER" ]; then
echo "did not receive PAM_USER env var"
exit 1
fi
if ! id "$PAM_USER" &>/dev/null; then
# NOTE(3wc): This generates a stable UID for the user based on the username;
# without it, UID→username mapping changes on every container restart, which
# creates file ownership issues and prevents RStudio from working.
# See https://github.com/WASHNote/washnote-apps/issues/67
uid=$(echo "$PAM_USER" | md5sum | grep -Eo "[[:digit:]]{3}" | head -n1 | sed -E 's/^0+//')
uid=$((1000+uid))
adduser --uid="$uid" "$PAM_USER" --disabled-password --quiet --gecos ""
usermod -aG staff "$PAM_USER"
fi
exit 0