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