diff --git a/scripts/user-perm-helpers.sh b/scripts/user-perm-helpers.sh index a31d1ddd5..28db38732 100755 --- a/scripts/user-perm-helpers.sh +++ b/scripts/user-perm-helpers.sh @@ -10,25 +10,31 @@ LANDO_MODULE="userperms" add_user() { local USER=$1 local GROUP=$2 - local WEBROOT_UID=$3 - local WEBROOT_GID=$4 - if ! getent group | cut -d: -f1 | grep "$GROUP" > /dev/null 2>&1; then addgroup -g "$WEBROOT_GID" "$GROUP" 2>/dev/null; fi - if ! id -u "$USER" > /dev/null 2>&1; then adduser -H -D -G "$GROUP" -u "$WEBROOT_UID" "$USER" "$GROUP" 2>/dev/null; fi + local UID=$3 + local GID=$4 + local DISTRO=$5 + local EXTRAS="$6" + if [ "$DISTRO" = "alpine" ]; then + if ! groups | grep "$GROUP" > /dev/null 2>&1; then addgroup -g "$GID" "$GROUP" 2>/dev/null; fi + if ! id -u "$GROUP" > /dev/null 2>&1; then adduser -H -D -G "$GROUP" -u "$UID" "$USER" "$GROUP" 2>/dev/null; fi + else + if ! groups | grep "$GROUP" > /dev/null 2>&1; then groupadd --force --gid "$GID" "$GROUP" 2>/dev/null; fi + if ! id -u "$GROUP" > /dev/null 2>&1; then useradd --gid "$GID" --uid "$UID" $EXTRAS "$USER" 2>/dev/null; fi + fi; } # Verify user verify_user() { local USER=$1 local GROUP=$2 + local DISTRO=$3 id -u "$USER" > /dev/null 2>&1 - groups "$USER" | grep "$GROUP" > /dev/null 2>&1 - if command -v chsh > /dev/null 2>&1 ; then - if command -v /bin/bash > /dev/null 2>&1 ; then - chsh -s /bin/bash $USER || true - fi; - else + groups | grep "$GROUP" > /dev/null 2>&1 + if [ "$DISTRO" = "alpine" ]; then true # is there a chsh we can use? do we need to? + else + chsh -s /bin/bash $USER || true fi; } @@ -53,10 +59,11 @@ reset_user() { if [ "$(id -u $USER)" != "$HOST_UID" ]; then usermod -o -u "$HOST_UID" "$USER" 2>/dev/null fi - groupmod -o -g "$HOST_GID" "$GROUP" 2>/dev/null || true - if [ "$(id -g $USER)" != "$HOST_GID" ]; then + groupmod -g "$HOST_GID" "$GROUP" 2>/dev/null || true + if [ "$(id -u $USER)" != "$HOST_UID" ]; then usermod -g "$HOST_GID" "$USER" 2>/dev/null || true fi + usermod -a -G "$GROUP" "$USER" 2>/dev/null || true fi; # If this mapping is incorrect lets abort here if [ "$(id -u $USER)" != "$HOST_UID" ]; then @@ -90,6 +97,7 @@ perm_sweep() { nohup find /user/.ssh -not -user $USER -execdir chown $USER:$GROUP {} \+ > /tmp/perms.out 2> /tmp/perms.err & nohup find /var/www -not -user $USER -execdir chown $USER:$GROUP {} \+ > /tmp/perms.out 2> /tmp/perms.err & nohup find /usr/local/bin -not -user $USER -execdir chown $USER:$GROUP {} \+ > /tmp/perms.out 2> /tmp/perms.err & + nohup chmod -R 755 /var/www >/dev/null 2>&1 & # Lets also make some /usr/locals chowned nohup find /usr/local/lib -not -user $USER -execdir chown $USER:$GROUP {} \+ > /tmp/perms.out 2> /tmp/perms.err &