-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas_adduser.sh
executable file
·32 lines (27 loc) · 1.01 KB
/
has_adduser.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
#!/bin/sh
# TODO: If given arguments, create each user passed as an argument.
# Otherwise, create all standard users and groups.
while read name uid; do
# Check if group already exists
group_line=$(grep ^$name\\: /etc/group)
if [ $? -ne 0 ]; then
echo "adding group $name : $uid"
addgroup -g $uid $name
elif [ "$uid" != $( echo "$group_line" | awk -F: '{print $3}' ) ]; then
echo "Group $name already exists but has wrong gid"
exit 1
else
echo "Group $name already exists with correct gid $uid"
fi
# Check if user already exists
passwd_line=$(grep ^$name\\: /etc/passwd)
if [ $? -ne 0 ]; then
echo "adding user $name : $uid"
adduser -s /bin/false -G $name -D -H -u $uid $name
elif [ "$uid" != $( echo "$passwd_line" | awk -F: '{print $3}' ) ]; then
echo "User $name already exists but has wrong uid"
exit 1
else
echo "User $name already exists with correct uid $uid"
fi
done < "$(dirname "$0")/users.txt"