1 | #!/bin/sh |
---|
2 | |
---|
3 | checkfailed() { |
---|
4 | if [ -f "$lroot/web_scripts/$addrend/.failed" ]; then |
---|
5 | rm -f "$lroot/web_scripts/$addrend/.failed" |
---|
6 | exit 1 |
---|
7 | fi |
---|
8 | } |
---|
9 | |
---|
10 | die() { |
---|
11 | echo "== INSTALLATION FAILED ==" |
---|
12 | echo "Sorry, the installation failed:" |
---|
13 | echo "$@" |
---|
14 | echo "Please contact scripts@mit.edu and provide a copy of the output of this installer." |
---|
15 | exit 1 |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | sshrun() { |
---|
20 | athrun scripts scripts-ssh "$lname" "/mit/scripts/$@" 2>/dev/null |
---|
21 | } |
---|
22 | |
---|
23 | vsshrun() { |
---|
24 | athrun scripts scripts-ssh "$lname" "/mit/scripts/$@" |
---|
25 | } |
---|
26 | |
---|
27 | checksqlpass() { |
---|
28 | errors=`sshrun "sql/bin$scriptsdev/test-password"` |
---|
29 | if [ "$errors" != "" ]; then |
---|
30 | if [ "$1" -eq 1 ]; then |
---|
31 | rm -f "$lroot/.sql/my.cnf" |
---|
32 | fi |
---|
33 | echo |
---|
34 | echo "ERROR:" |
---|
35 | printf "$2" |
---|
36 | exit |
---|
37 | fi |
---|
38 | } |
---|
39 | |
---|
40 | if [ "$override" = "" ]; then |
---|
41 | echo "The scripts.mit.edu automatic installers are currently unavailable." |
---|
42 | echo "We hope to make them available again soon." |
---|
43 | echo "If you would like us to notify you as soon as they are available again," |
---|
44 | echo "let us know by sending us an e-mail at scripts@mit.edu" |
---|
45 | exit |
---|
46 | fi |
---|
47 | |
---|
48 | echo |
---|
49 | echo "== Welcome to the scripts.mit.edu installer for $sname ==" |
---|
50 | echo |
---|
51 | |
---|
52 | echo "For documentation, including a link to the Athena rules of use," |
---|
53 | echo "see <http://scripts.mit.edu/start>." |
---|
54 | echo |
---|
55 | echo "Please report problems with this installer to scripts@mit.edu." |
---|
56 | echo |
---|
57 | echo "Are you performing this install for:" |
---|
58 | echo "1. Your personal Athena account" |
---|
59 | echo "2. A locker that you control (a club, a course, etc)" |
---|
60 | echo "If you do not understand this question, you should answer '1'." |
---|
61 | printf "Please enter either '1' or '2' (without quotes): " |
---|
62 | read whofor |
---|
63 | if [ "$whofor" = 1 ]; then |
---|
64 | lname=$USER |
---|
65 | lroot=$HOME |
---|
66 | elif [ "$whofor" = 2 ]; then |
---|
67 | echo |
---|
68 | echo "OK. $sname will be installed into a locker of your choice that" |
---|
69 | echo "you control. Please enter the name of the selected locker below." |
---|
70 | echo "(For the locker /mit/lsc -- which has a full path of" |
---|
71 | echo "/afs/athena.mit.edu/activity/l/lsc -- you would simply enter lsc)." |
---|
72 | printf "Locker name: " |
---|
73 | read lname |
---|
74 | lroot="/mit/$lname" |
---|
75 | else |
---|
76 | echo |
---|
77 | echo "ERROR:" |
---|
78 | echo "You must select either '1' or '2'." |
---|
79 | exit 1 |
---|
80 | fi |
---|
81 | |
---|
82 | echo |
---|
83 | echo Checking the status of your scripts.mit.edu account... |
---|
84 | |
---|
85 | attach scripts 2>/dev/null |
---|
86 | . "/mit/scripts/bin$scriptsdev/signup-web" |
---|
87 | |
---|
88 | echo |
---|
89 | echo "Your new copy of $sname will appear on the web at a URL" |
---|
90 | echo "that starts with http://scripts.mit.edu/~$lname/" |
---|
91 | echo "Please decide upon a complete URL and enter it below." |
---|
92 | echo "You must enter one or more characters after ~$lname/" |
---|
93 | echo "The completed address must only contain a-z, 0-9, and /." |
---|
94 | printf "Desired address: http://scripts.mit.edu/~$lname/" |
---|
95 | read addrend |
---|
96 | |
---|
97 | addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"` |
---|
98 | if [ "$addrend" = "" ]; then |
---|
99 | echo |
---|
100 | echo "ERROR:" |
---|
101 | echo "You must enter one or more characters after ~$lname/" |
---|
102 | echo "The completed address must only contain a-z, 0-9, and /." |
---|
103 | exit 1 |
---|
104 | fi |
---|
105 | |
---|
106 | if [ -d "$lroot/web_scripts/$addrend" ]; then |
---|
107 | echo |
---|
108 | echo "ERROR:" |
---|
109 | echo "You already have a directory corresponding to that web address." |
---|
110 | echo "Please remove that directory, choose a different address, or" |
---|
111 | echo "contact scripts@mit.edu for assistance." |
---|
112 | exit 1 |
---|
113 | fi |
---|
114 | |
---|
115 | if [ "$requires_sql" = "" ]; then |
---|
116 | requires_sql=1 |
---|
117 | fi |
---|
118 | |
---|
119 | if [ ! -f "$lroot/.my.cnf" ]; then |
---|
120 | mkdir "$lroot/.sql" 2>/dev/null |
---|
121 | fs sa "$lroot/.sql" daemon.scripts write |
---|
122 | fs sa "$lroot/.sql" daemon.sql write |
---|
123 | ln -nfs "$lroot/.sql/my.cnf" "$lroot/.my.cnf" 2>/dev/null |
---|
124 | fi |
---|
125 | |
---|
126 | fs sa "$lroot/.sql" system:anyuser none |
---|
127 | fs sa "$lroot/.sql" system:authuser none |
---|
128 | |
---|
129 | if [ "$requires_sql" -eq 1 ]; then |
---|
130 | sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"` |
---|
131 | if [ "$sqlinfo" = "" ]; then |
---|
132 | echo |
---|
133 | echo "You already have a MySQL account but you do not have a .my.cnf file." |
---|
134 | echo "If you do not remember your MySQL account password, you can change it" |
---|
135 | echo "at http://sql.mit.edu using MIT certificates." |
---|
136 | printf "Please type your MySQL password and press [enter]: " |
---|
137 | stty -echo |
---|
138 | read sqlpass |
---|
139 | stty echo |
---|
140 | echo |
---|
141 | sqlhost="sql.mit.edu" |
---|
142 | sqluser=$lname |
---|
143 | . "/mit/scripts/sql/bin$scriptsdev/save-password" |
---|
144 | checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n' |
---|
145 | echo |
---|
146 | echo "OK. Continuing with the install..." |
---|
147 | else |
---|
148 | checksqlpass 0 'The MySQL login information in your .my.cnf file\nappears to be incorrect.\n' |
---|
149 | fi |
---|
150 | fi |
---|
151 | |
---|
152 | if [ "$prompt_username" = "" ]; then |
---|
153 | admin_username="admin" |
---|
154 | prompt_username=0 |
---|
155 | fi |
---|
156 | if [ "$prompt_password" = "" ]; then |
---|
157 | prompt_password=1 |
---|
158 | fi |
---|
159 | |
---|
160 | if [ "$prompt_username" -eq 1 ]; then |
---|
161 | echo |
---|
162 | echo "You will be able to log in to $sname using a username of your choice." |
---|
163 | echo "Please decide upon a username and enter it below." |
---|
164 | echo "Your username must contain only alphanumeric characters (a-z, 0-9)." |
---|
165 | printf "Desired username: " |
---|
166 | read admin_username |
---|
167 | admin_username=`perl -0e 'print $ARGV[0] =~ /^([[:alnum:]]+)$/' -- "$admin_username"` |
---|
168 | if [ "$admin_username" = "" ]; then |
---|
169 | echo |
---|
170 | echo ERROR: |
---|
171 | echo "Your username must contain only alphanumeric characters (a-z, 0-9)." |
---|
172 | echo "You will need to run the installer again and choose a different username." |
---|
173 | exit 1 |
---|
174 | fi |
---|
175 | fi |
---|
176 | |
---|
177 | origdir=`pwd` |
---|
178 | mkdir -p "$lroot/web_scripts_tmp" |
---|
179 | cd "$lroot/web_scripts_tmp" |
---|
180 | fs sa . system:anyuser none |
---|
181 | fs sa . system:authuser none |
---|
182 | fs sa . daemon.scripts write |
---|
183 | fs sa . system:scripts-security-upd write |
---|
184 | mkdir -p "$lroot/web_scripts/$addrend" |
---|
185 | cd "$lroot/web_scripts/$addrend" |
---|
186 | fs sa . system:anyuser none |
---|
187 | fs sa . system:authuser none |
---|
188 | fs sa . daemon.scripts write |
---|
189 | fs sa . system:scripts-security-upd write |
---|
190 | |
---|
191 | if [ "$prompt_password" -eq 1 ]; then |
---|
192 | stty -echo |
---|
193 | sshrun "deploy$scriptsdev/bin/prompt-password" "$sname" "$deploy" "$addrend" "$admin_username" |
---|
194 | stty echo |
---|
195 | fi |
---|
196 | |
---|
197 | echo |
---|
198 | echo "Unpacking $sname... (this step might take several minutes)" |
---|
199 | |
---|
200 | if [ "$create_dir" = "" ]; then |
---|
201 | create_dir=0 |
---|
202 | fi |
---|
203 | |
---|
204 | if [ "$create_dir" -eq 1 ]; then |
---|
205 | mkdir -p "$lroot/scripts-$deploy" |
---|
206 | fs sa "$lroot/scripts-$deploy" system:anyuser none |
---|
207 | fs sa "$lroot/scripts-$deploy" system:authuser none |
---|
208 | fs sa "$lroot/scripts-$deploy" daemon.scripts write |
---|
209 | fs sa "$lroot/scripts-$deploy" system:scripts-security-upd write |
---|
210 | fi |
---|
211 | |
---|
212 | athrun scripts gtar zxf "/mit/scripts/deploy$scriptsdev/$deploy.tar.gz" |
---|
213 | files=`athrun scripts gfind . -mindepth 1 -maxdepth 1 | grep -v .admin` |
---|
214 | numfiles=`echo "$files" | wc -l` |
---|
215 | if [ "$numfiles" -eq 1 ]; then |
---|
216 | athrun scripts gfind . -mindepth 2 -maxdepth 2 | xargs -i mv \{} . |
---|
217 | rmdir "$files" |
---|
218 | fi |
---|
219 | if [ -f "/mit/scripts/deploy$scriptsdev/php.ini/$deploy" ]; then |
---|
220 | nodot=`echo "$lname" | sed "/\./s///"`; |
---|
221 | sed -e "/SCRIPTS_USER/ s//$lname/" -e "/SCRIPTS_NODOT/ s//$nodot/" "/mit/scripts/deploy$scriptsdev/php.ini/$deploy" > php.ini |
---|
222 | athrun scripts gfind . -mindepth 1 -type d -exec sh -c 'ln -sf "`echo "$1" | sed '\''s,[^/],,g; s,/,../,g'\''`php.ini" "$1/"' -- {} \; |
---|
223 | fi |
---|
224 | cd "$origdir" |
---|
225 | |
---|
226 | vsshrun "deploy$scriptsdev/bin/$deploy" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration" |
---|
227 | rm -f "$lroot/web_scripts/$addrend/.scripts-tmp" |
---|
228 | checkfailed |
---|
229 | |
---|
230 | echo |
---|
231 | echo "== Installation complete! ==" |
---|
232 | echo "You should now be able to access your new copy of $sname at" |
---|
233 | echo "http://scripts.mit.edu/~$lname/$addrend/" |
---|
234 | echo "(You can replace the http with https if you want to use encryption)" |
---|
235 | echo "If you have trouble accessing it, feel free to contact" |
---|
236 | echo "the scripts.mit.edu team by e-mailing scripts@mit.edu" |
---|
237 | exit 0 |
---|