This is the initial work. Will add labels w/e Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
24 lines
741 B
Bash
24 lines
741 B
Bash
#!/bin/bash
|
|
# setuser.sh: Helper script to set the user and group.
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: setuser.sh <username> <userid> <groupid>"
|
|
exit 1
|
|
fi
|
|
|
|
USER_NAME="$1"
|
|
USER_ID="${2:-1000}" # Default to 1000 if not provided
|
|
GROUP_ID="${3:-1000}" # Default to 1000 if not provided
|
|
|
|
# Check if the group exists, create if it doesn't
|
|
if ! getent group "$USER_NAME" >/dev/null 2>&1; then
|
|
groupadd -g "$GROUP_ID" "$USER_NAME"
|
|
fi
|
|
|
|
# Check if the user exists, create if it doesn't
|
|
if ! id -u "$USER_NAME" >/dev/null 2>&1; then
|
|
useradd -u "$USER_ID" -g "$GROUP_ID" -d /home/"$USER_NAME" -s /bin/bash "$USER_NAME"
|
|
fi
|
|
USER="$USER_NAME"
|
|
# Set the user.
|
|
exec setpriv --reuid "$USER_ID" --regid "$GROUP_ID" --init-groups -- /bin/sh -c "$0" |