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

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