source: branches/fc11-dev/locker/deploy/bin/onathena @ 1121

Last change on this file since 1121 was 1045, checked in by geofft, 16 years ago
onathena: Uncommitted changes that enable *.scripts and ~/Scripts Apparently we've been running this for a while. Some of the ~/Scripts code (at least) is xavid's.
  • Property svn:executable set to *
File size: 8.3 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 "$lname" "/mit/scripts/$@" 2>/dev/null
21}
22
23vsshrun() {
24  athrun scripts scripts-ssh "$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        exit
37    fi
38}
39
40override=1
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" = 1 ]; then
65    lname="${ATHENA_USER:-$USER}"
66elif [ "$whofor" = 2 ]; then
67    echo
68    echo "OK.  $sname will be installed into a locker of your choice that"
69    echo "you control.  Please enter the name of the selected locker below."
70    echo "(For the locker /mit/lsc -- which has a full path of"
71    echo "/afs/athena.mit.edu/activity/l/lsc -- you would simply enter lsc)."
72    printf "Locker name: "
73    read lname
74else
75    echo
76    echo "ERROR:"
77    echo "You must select either '1' or '2'."
78    exit 1
79fi
80while true; do
81    if attach "$lname"; then
82        break
83    fi
84    echo "$lname is not a valid locker name."
85    printf "Locker name: "
86    read lname
87done
88lroot="/mit/$lname" 
89
90echo
91echo Checking the status of your scripts.mit.edu account...
92
93attach scripts 2>/dev/null
94. "/mit/scripts/bin$scriptsdev/signup-web"
95
96echo
97echo "Your new copy of $sname will appear on the web at a URL"
98echo "that starts with http://$lname.scripts.mit.edu/"
99echo "Please decide upon a complete URL and enter it below."
100echo "You must enter one or more characters after mit.edu/"
101echo "The completed address must only contain a-z, 0-9, and /."
102printf "Desired address: http://$lname.scripts.mit.edu/"
103read addrend
104
105addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"`
106if [ "$addrend" = "" ]; then
107        echo
108        echo "ERROR:"
109        echo "You must enter one or more characters after mit.edu/"
110        echo "The completed address must only contain a-z, 0-9, and /."
111        exit 1
112fi
113
114if [ -d "$lroot/web_scripts/$addrend" ]; then
115    echo
116    echo "ERROR:"
117    echo "You already have a directory corresponding to that web address."
118    echo "Please remove that directory, choose a different address, or"
119    echo "contact scripts@mit.edu for assistance."
120    exit 1
121fi
122
123if [ "$requires_sql" = "" ]; then
124  requires_sql=1
125fi
126
127if [ ! -f "$lroot/.my.cnf" ]; then
128  mkdir "$lroot/.sql" 2>/dev/null
129  fs sa "$lroot/.sql" daemon.scripts write
130  fs sa "$lroot/.sql" daemon.sql write
131  ln -nfs "$lroot/.sql/my.cnf" "$lroot/.my.cnf" 2>/dev/null
132fi
133
134fs sa "$lroot/.sql" system:anyuser none
135fs sa "$lroot/.sql" system:authuser none
136
137if [ "$requires_sql" -eq 1 ]; then
138  sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"`
139  if [ "$sqlinfo" = "" ]; then
140      echo
141      echo "You already have a MySQL account but you do not have a .my.cnf file."
142      echo "If you do not remember your MySQL account password, you can change it"
143      echo "at http://sql.mit.edu using MIT certificates."
144      printf "Please type your MySQL password and press [enter]: "
145      stty -echo
146      read sqlpass
147      stty echo
148      echo
149      sqlhost="sql.mit.edu"
150      sqluser=$lname
151      . "/mit/scripts/sql/bin$scriptsdev/save-password"
152      checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n'
153      echo
154      echo "OK.  Continuing with the install..."
155  else
156      checksqlpass 0 'The MySQL login information in your .my.cnf file\nappears to be incorrect.\n'
157  fi
158fi
159
160if [ "$prompt_username" = "" ]; then
161  admin_username="admin"
162  prompt_username=0
163fi
164if [ "$prompt_password" = "" ]; then
165  prompt_password=1
166fi
167
168if [ "$prompt_username" -eq 1 ]; then
169    echo
170    echo "You will be able to log in to $sname using a username of your choice."
171    echo "Please decide upon a username and enter it below."
172    echo "Your username must contain only alphanumeric characters (a-z, 0-9)."
173    printf "Desired username: "
174    read admin_username
175    admin_username=`perl -0e 'print $ARGV[0] =~ /^([[:alnum:]]+)$/' -- "$admin_username"`
176    if [ "$admin_username" = "" ]; then
177        echo
178        echo ERROR:
179        echo "Your username must contain only alphanumeric characters (a-z, 0-9)."
180        echo "You will need to run the installer again and choose a different username."
181        exit 1
182    fi
183fi
184
185origdir=`pwd`
186mkdir -p "$lroot/web_scripts_tmp"
187cd "$lroot/web_scripts_tmp"
188fs sa . system:anyuser none
189fs sa . system:authuser none
190fs sa . daemon.scripts write
191fs sa . system:scripts-security-upd write
192echo "This directory is necessary to store login sessions and other transient files for auto-installed packages from scripts.mit.edu." > DO_NOT_DELETE.txt
193mkdir -p "$lroot/web_scripts/$addrend"
194cd "$lroot/web_scripts/$addrend"
195fs sa . system:anyuser none
196fs sa . system:authuser none
197fs sa . daemon.scripts write
198fs sa . system:scripts-security-upd write
199
200if [ "$prompt_password" -eq 1 ]; then
201    stty -echo
202    sshrun "deploy$scriptsdev/bin/prompt-password" "$sname" "$deploy" "$addrend" "$admin_username"
203    stty echo
204fi
205
206echo
207echo "Unpacking $sname... (this step might take several minutes)"
208
209# This version is deprecated, use create_scripts_dir instead
210
211if [ "$create_dir" = "" ]; then
212  create_dir=0
213fi
214
215if [ "$create_dir" -eq 1 ]; then
216  mkdir -p "$lroot/scripts-$deploy"
217  fs sa "$lroot/scripts-$deploy" system:anyuser none
218  fs sa "$lroot/scripts-$deploy" system:authuser none
219  fs sa "$lroot/scripts-$deploy" daemon.scripts write
220  fs sa "$lroot/scripts-$deploy" system:scripts-security-upd write
221fi
222
223# This is the better version
224
225if [ "$create_scripts_dir" = "" ]; then
226  create_scripts_dir=0
227fi
228
229if [ "$create_scripts_dir" -eq 1 ]; then
230  mkdir -p "$lroot/Scripts/$deploy"
231  fs sa "$lroot/Scripts/$deploy" system:anyuser none
232  fs sa "$lroot/Scripts/$deploy" system:authuser none
233  fs sa "$lroot/Scripts/$deploy" daemon.scripts write
234  fs sa "$lroot/Scripts/$deploy" system:scripts-security-upd write
235fi
236
237# xavid: use p to keep the same permissions as in the file
238athrun scripts gtar zxpf "/mit/scripts/deploy$scriptsdev/$deploy.tar.gz"
239files=`athrun scripts gfind . -mindepth 1 -maxdepth 1 | grep -v .admin`
240numfiles=`echo "$files" | wc -l`
241if [ ! -z "$files" ]; then
242    if [ "$numfiles" -eq 1 ]; then
243        athrun scripts gfind . -mindepth 2 -maxdepth 2 | xargs -i mv \{} .
244        rmdir "$files"
245    fi
246fi
247if [ -f "/mit/scripts/deploy$scriptsdev/php.ini/$deploy" ]; then
248        nodot=`echo "$lname" | sed "/\./s///"`;
249        sed -e "/SCRIPTS_USER/ s//$lname/" -e "/SCRIPTS_NODOT/ s//$nodot/" "/mit/scripts/deploy$scriptsdev/php.ini/$deploy" > php.ini
250        athrun scripts gfind . -mindepth 1 -type d -exec sh -c 'ln -sf "`echo "$1" | sed '\''s,[^/],,g; s,/,../,g'\''`php.ini" "$1/"' -- {} \;
251fi
252cd "$origdir"
253
254vsshrun "deploy$scriptsdev/bin/$deploy" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration"
255rm -f "$lroot/web_scripts/$addrend/.scripts-tmp"
256checkfailed
257
258echo
259echo "== Installation complete! =="
260echo "You should now be able to access your new copy of $sname at"
261echo "http://$lname.scripts.mit.edu/$addrend/"
262echo "(You can replace the http with https if you want to use encryption)"
263echo "If you have trouble accessing it, feel free to contact"
264echo "the scripts.mit.edu team by e-mailing scripts@mit.edu"
265exit 0
Note: See TracBrowser for help on using the repository browser.