-
Notifications
You must be signed in to change notification settings - Fork 1
/
createMichaeluser
executable file
·159 lines (138 loc) · 3.98 KB
/
createMichaeluser
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
ACL="Open"
michael_users="[email protected]"
# Email address that subscribe command notification goes to.
# Can't be rc-support or we get tickets and bounce messages
mailing_requestor="[email protected]"
email_cc=""
usage () {
echo "Usage: $0 [options] -u <username> -e <email> -k <ssh_key>
Options:
-h show this help message
-n do not send welcome email
-m <email> mailing list request confirmation goes here
-c <email> welcome email is CCed here
"
}
while getopts ":hu:e:k:nm:c:" opt; do
case $opt in
h)
usage
exit 0
;;
u)
username="$OPTARG"
#echo "Username: $username"
;;
e)
email="$OPTARG"
#echo "Email: $email"
;;
k)
ssh_key="$OPTARG"
#echo "ssh key: $ssh_key"
;;
n)
do_not_mail="y"
;;
m)
mailing_requestor="$OPTARG"
;;
c)
email_cc="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 4
;;
esac
done
# make sure all arguments are supplied (checks for unset or empty)
if [ ! "$username" ] || [ ! "$email" ] || [ ! "$ssh_key" ]
then
usage
exit 1
fi
# become user, create ssh directory and add key
#echo "Becoming ${username}, creating ssh dir and adding key"
#become_output=$(sudo /shared/ucl/sysops/libexec/become $username <<EOF
#echo "Beacon"
#mkdir -p .ssh
#chmod go-rwx .ssh
#echo "${ssh_key}" >> ~/.ssh/authorized_keys
#EOF
#)
#become_exit_status=$?
#if [ "${become_output:0:6}" != "Beacon" ]; then
# echo "Error: could not become user ${username}" >&2
# exit 1
#fi
# replacement for become - creates homedir and adds key
if ! sudo /shared/ucl/sysops/libexec/add_sshkeys "${username}" "${ssh_key}"
then
echo $(date) ": Creation of ${username} homedir or addition of key failed, exiting." >&2
exit 1
fi
# add user to ACL so they can log in and submit jobs
if ! qconf -au "$username" "$ACL"
then
echo $(date) ": Adding ${username} to $ACL ACL failed, exiting." >&2
exit 1
fi
# check that the qconf change actually worked!
# Try 3 times.
for i in 1 2 3
do
qconf -su "$ACL" | grep -q "$username"
if [ $? == 0 ]
then
echo ""
echo $(date) ": Successfully allowed ${username} to log in"
break
elif (( $i < 3 ))
# failed, try again
then
sleep 5
else
echo $(date) ": Grid Engine failed to add ${username} to $ACL ACL three times - please contact [email protected]" >&2
exit 1
fi
done
# add user to michael-users mailing list
echo " Emailing ${michael_users} to add ${email}"
/usr/sbin/sendmail -t<<EOF
From: ${mailing_requestor}
To: ${michael_users}
Subject: subscribe address=${email}
EOF
# email welcome to user, unless do_not_mail was set
if [ ! "$do_not_mail" ]
then
echo " Emailing user ${username} at ${email}"
/usr/sbin/sendmail -t<<EOF
From: [email protected]
To: ${email}
CC: ${email_cc}
Subject: Michael: EPSRC Tier 2 MMM Hub account
We are happy to confirm that your account to use Michael is now active.
Michael is an extension to the UK National Tier 2 High Performance Computing
Hub in Materials and Molecular Modelling for the Faraday Institution.
You should be able to log in within 5 minutes of receiving this email.
Your username is ${username} and you should ssh to michael.rc.ucl.ac.uk.
You will be logging in using the ssh key you provided us.
GETTING HELP
Information to help you get started in using Michael is available at
https://www.rc.ucl.ac.uk/docs/Clusters/Michael/
including a user guide covering all of our systems.
ANNOUNCEMENTS
Emails relating to planned outages, service changes etc will be sent to the
[email protected] email list. You have been subscribed to this
list using the email address provided with your account application - please
make sure that you read all notices sent to this address promptly and
observe the requests/guidelines they contain.
If you have any queries relating to this information please email the
support address [email protected].
EOF
else
echo "Sending no welcome email"
fi