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

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