forked from Piotr1215/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-test-user.sh
41 lines (35 loc) · 1008 Bytes
/
create-test-user.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
usage() {
printf "create-user [-u|--username] <username>\n"
printf " OPTIONS\n"
printf " -u --username\tusername of the new account (required)\n"
printf " -p --password\tpassword for the new account (optional)\n"
printf " -h --help\tprint this help\n"
exit 1
}
while [ "$#" -gt 0 ]; do
case "$1" in
-u|--username) username="$2" shift ;;
-p|--password) password="$2" shift ;;
-h|--help) usage ;;
*) usage ;;
esac
shift
done
[ -z "$username" ] && usage
[ -z "$password" ] && password=$(uuidgen | cut -d'-' -f1)
useradd -m "$username" -p "$password" > /dev/null 2>&1
usermod -aG sudo "$username" > /dev/null 2>&1
#------------#
# VARIATIONS #
#------------#
# useradd -m "$username"
# echo -n "$password\n$password\n" | passwd $username"
# echo "${username}:${password}" | chpasswd
if [ "$?" -eq 0 ]; then
echo "Username: $username"
echo "Password: $password"
else
echo "Failed to set up user account"
userdel -f "$username"
fi