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

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