source: locker/deploy/bin/onathena @ 463

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