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