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