-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathappend_users.sh
More file actions
executable file
·59 lines (49 loc) · 1.82 KB
/
append_users.sh
File metadata and controls
executable file
·59 lines (49 loc) · 1.82 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# What I really would like would be to have the user ID iqual to the student ID, but it can't be.
# The file /etc/group is used for knowing who is currently a member of some group
# please unsure that the following groups exist: student
MIN_UID=1200 # Users created in 2021/2022 start at 1165
if [ $# -lt 1 ]; then
echo "please provide the filename containing the new users"
exit 1
elif [ ! -f "$1" ]; then
echo "The filename containing the new users does not exist"
exit 2
fi
newusers=$1
# possible groups: tm, pcl, msc, phd, ceb
# group=tmcd
if [ $# -eq 2 ] && [ $( grep -c "^$2:" /etc/group ) -gt 0 ]; then
group=$2
else
echo "ERROR: Please provide the group name. aborting"
exit 1
fi
echo "Adding users to the group: $group"
if [ -n "$admin_email_pass" ]; then
echo -n "Press <enter> to start appending additional students (Mail server password already set)"
else
echo -n "E-mail server password: "
read -s admin_email_pass
export admin_email_pass
echo -n "Press <enter> to start appending additional students"
fi
read ok
cat $newusers | iconv -f UTF-8 -t 'ASCII//TRANSLIT' | while read line; do
username=$( echo "$line" | awk -F'\t' '{print $1}')
match=$(grep -c "^$username:" /etc/passwd )
if [ $match -ne 0 ]; then
echo "Warning: user $username already exists. Adding groups only"
else
nome=$( echo "$line" | awk -F'\t' '{print $2}')
email=$( echo "$line" | awk -F'\t' '{print $3}')
adduser --firstuid $MIN_UID --ingroup student --gecos "$nome,,,,$email" --disabled-login $username
chmod 700 /home/$username
./reset_password.sh $username $email
fi
adduser $username $group
if [ $( grep -c "^jupyterhub:" /etc/group ) -gt 0 ]; then
adduser $username jupyterhub
# Please don't forget to manually add these users later on in the jupyterhub interface
fi
done