source: trunk/locker/deploy/bin/onathena @ 1417

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