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

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