source: locker/deploy/bin/onathena @ 456

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