mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-27 05:49:45 +00:00
7bd9f8aee8
Co-authored-by: nnyyxxxx <nnyyxxxx@users.noreply.github.com>
36 lines
1.0 KiB
Bash
Executable File
36 lines
1.0 KiB
Bash
Executable File
#!/bin/sh -e
|
|
|
|
. ../../common-script.sh
|
|
. ./utility_functions.sh
|
|
|
|
clear
|
|
printf "%b\n" "${YELLOW}Add to group${RC}"
|
|
printf "%b\n" "${YELLOW}=================${RC}"
|
|
|
|
username=$(promptUsername "" "non-root") || exit 1
|
|
user_groups=$(groups "$username" | cut -d: -f2 | sort | tr '\n' ' ')
|
|
|
|
printf "%b\n" "${YELLOW}Groups user $username is in:${RC} $user_groups"
|
|
printf "%b\n" "${YELLOW}=================${RC}"
|
|
|
|
available_groups=$(cut -d: -f1 /etc/group | sort | tr '\n' ' ')
|
|
|
|
printf "%b\n" "${YELLOW}Available groups:${RC} $available_groups"
|
|
printf "%b\n" "${YELLOW}=================${RC}"
|
|
|
|
read -p "Enter the groups you want to add user $username to (space-separated): " groups
|
|
|
|
checkEmpty "$groups" || exit 1
|
|
checkGroupAvailabe "$groups" "$available_groups" || exit 1
|
|
|
|
groups_to_add=$(echo "$groups" | tr ' ' ',')
|
|
|
|
printf "Are you sure you want to add user $username to $groups_to_add? [Y/N]: "
|
|
read -r confirm
|
|
confirmAction || exit 1
|
|
|
|
$ESCALATION_TOOL usermod -aG $groups_to_add "$username"
|
|
|
|
printf "%b\n" "${GREEN}User successfully added to the $groups_to_add${RC}"
|
|
|
|
checkEnv |