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

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