source: locker/deploy/bin/onathena @ 240

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