source: branches/locker-dev/locker/deploy/bin/onathena @ 1493

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