| 1 | #!/bin/sh | 
|---|
| 2 |  | 
|---|
| 3 | : ${aicontact:=scripts@mit.edu} | 
|---|
| 4 | : ${aimaintainer:=scripts.mit.edu} | 
|---|
| 5 |  | 
|---|
| 6 |  | 
|---|
| 7 | checkfailed() { | 
|---|
| 8 | if [ -f "$lroot/web_scripts/$addrend/.failed" ]; then | 
|---|
| 9 | rm -f "$lroot/web_scripts/$addrend/.failed" | 
|---|
| 10 | exit 1 | 
|---|
| 11 | fi | 
|---|
| 12 | } | 
|---|
| 13 |  | 
|---|
| 14 | die() { | 
|---|
| 15 | echo "== INSTALLATION FAILED ==" | 
|---|
| 16 | echo "Sorry, the installation failed:" | 
|---|
| 17 | echo "$@" | 
|---|
| 18 | echo "Please contact $aicontact and provide a copy of the output of this installer." | 
|---|
| 19 | exit 1 | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | attach scripts | 
|---|
| 23 |  | 
|---|
| 24 | sshrun() { | 
|---|
| 25 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" 2>/dev/null | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | vsshrun() { | 
|---|
| 29 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | checksqlpass() { | 
|---|
| 33 | errors=`sshrun "sql/bin$scriptsdev/test-password"` | 
|---|
| 34 | if [ "$errors" != "" ]; then | 
|---|
| 35 | if [ "$1" -eq 1 ]; then | 
|---|
| 36 | rm -f "$lroot/.sql/my.cnf" | 
|---|
| 37 | fi | 
|---|
| 38 | echo | 
|---|
| 39 | echo "ERROR:" | 
|---|
| 40 | printf "$2" | 
|---|
| 41 | exit | 
|---|
| 42 | fi | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | override=1 | 
|---|
| 46 | if [ "$override" = "" ]; then | 
|---|
| 47 | echo "The $aimaintainer automatic installers are currently unavailable." | 
|---|
| 48 | echo "We hope to make them available again soon." | 
|---|
| 49 | echo "If you would like us to notify you as soon as they are available again," | 
|---|
| 50 | echo "let us know by sending us an e-mail at $aicontact" | 
|---|
| 51 | exit | 
|---|
| 52 | fi | 
|---|
| 53 |  | 
|---|
| 54 | echo | 
|---|
| 55 | echo "== Welcome to the $aimaintainer installer for $sname ==" | 
|---|
| 56 | echo | 
|---|
| 57 |  | 
|---|
| 58 | echo "For documentation, including a link to the Athena rules of use," | 
|---|
| 59 | echo "see <http://scripts.mit.edu/start>." | 
|---|
| 60 | echo | 
|---|
| 61 | echo "Please report problems with this installer to $aicontact." | 
|---|
| 62 | echo | 
|---|
| 63 | echo "Are you performing this install for:" | 
|---|
| 64 | echo "1. Your personal Athena account" | 
|---|
| 65 | echo "2. A locker that you control (a club, a course, etc)" | 
|---|
| 66 | echo "If you do not understand this question, you should answer '1'." | 
|---|
| 67 | printf "Please enter either '1' or '2' (without quotes): " | 
|---|
| 68 | read whofor | 
|---|
| 69 | if [ "$whofor" = 1 ]; then | 
|---|
| 70 | lname="${ATHENA_USER:-$USER}" | 
|---|
| 71 | elif [ "$whofor" = 2 ]; then | 
|---|
| 72 | echo | 
|---|
| 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." | 
|---|
| 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 | 
|---|
| 79 | else | 
|---|
| 80 | echo | 
|---|
| 81 | echo "ERROR:" | 
|---|
| 82 | echo "You must select either '1' or '2'." | 
|---|
| 83 | exit 1 | 
|---|
| 84 | fi | 
|---|
| 85 | while 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 | 
|---|
| 92 | done | 
|---|
| 93 | lroot="/mit/$lname" | 
|---|
| 94 |  | 
|---|
| 95 | echo | 
|---|
| 96 | echo Checking the status of your scripts.mit.edu account... | 
|---|
| 97 |  | 
|---|
| 98 | attach scripts 2>/dev/null | 
|---|
| 99 | . "/mit/scripts/bin$scriptsdev/signup-web" | 
|---|
| 100 |  | 
|---|
| 101 | echo | 
|---|
| 102 | echo "Your new copy of $sname will appear on the web at a URL" | 
|---|
| 103 | echo "that starts with http://$lname.scripts.mit.edu/" | 
|---|
| 104 | echo "Please decide upon a complete URL and enter it below." | 
|---|
| 105 | echo "You must enter one or more characters after mit.edu/" | 
|---|
| 106 | echo "The completed address must only contain a-z, 0-9, and /." | 
|---|
| 107 | printf "Desired address: http://$lname.scripts.mit.edu/" | 
|---|
| 108 | read addrend | 
|---|
| 109 |  | 
|---|
| 110 | addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"` | 
|---|
| 111 | if [ "$addrend" = "" ]; then | 
|---|
| 112 | echo | 
|---|
| 113 | echo "ERROR:" | 
|---|
| 114 | echo "You must enter one or more characters after mit.edu/" | 
|---|
| 115 | echo "The completed address must only contain a-z, 0-9, and /." | 
|---|
| 116 | exit 1 | 
|---|
| 117 | fi | 
|---|
| 118 |  | 
|---|
| 119 | if [ -d "$lroot/web_scripts/$addrend" ]; then | 
|---|
| 120 | echo | 
|---|
| 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" | 
|---|
| 124 | echo "contact $aicontact for assistance." | 
|---|
| 125 | exit 1 | 
|---|
| 126 | fi | 
|---|
| 127 |  | 
|---|
| 128 | if [ "$requires_sql" = "" ]; then | 
|---|
| 129 | requires_sql=1 | 
|---|
| 130 | fi | 
|---|
| 131 |  | 
|---|
| 132 | if [ ! -f "$lroot/.my.cnf" ]; then | 
|---|
| 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 | 
|---|
| 137 | fi | 
|---|
| 138 |  | 
|---|
| 139 | fs sa "$lroot/.sql" system:anyuser none | 
|---|
| 140 | fs sa "$lroot/.sql" system:authuser none | 
|---|
| 141 |  | 
|---|
| 142 | if [ "$requires_sql" -eq 1 ]; then | 
|---|
| 143 | sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"` | 
|---|
| 144 | if [ "$sqlinfo" = "" ]; then | 
|---|
| 145 | echo | 
|---|
| 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." | 
|---|
| 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 | 
|---|
| 156 | . "/mit/scripts/sql/bin$scriptsdev/save-password" | 
|---|
| 157 | checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n' | 
|---|
| 158 | echo | 
|---|
| 159 | echo "OK.  Continuing with the install..." | 
|---|
| 160 | else | 
|---|
| 161 | checksqlpass 0 'The MySQL login information in your .my.cnf file\nappears to be incorrect.\n' | 
|---|
| 162 | fi | 
|---|
| 163 | fi | 
|---|
| 164 |  | 
|---|
| 165 | origdir=`pwd` | 
|---|
| 166 | mkdir -p "$lroot/web_scripts_tmp" | 
|---|
| 167 | cd "$lroot/web_scripts_tmp" | 
|---|
| 168 | fs sa . system:anyuser none | 
|---|
| 169 | fs sa . system:authuser none | 
|---|
| 170 | fs sa . daemon.scripts write | 
|---|
| 171 | fs sa . system:scripts-security-upd write | 
|---|
| 172 | 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 | 
|---|
| 173 | mkdir -p "$lroot/web_scripts/$addrend" | 
|---|
| 174 | cd "$lroot/web_scripts/$addrend" | 
|---|
| 175 | fs sa . system:anyuser none | 
|---|
| 176 | fs sa . system:authuser none | 
|---|
| 177 | fs sa . daemon.scripts write | 
|---|
| 178 | fs sa . system:scripts-security-upd write | 
|---|
| 179 |  | 
|---|
| 180 | # This version is deprecated, use create_scripts_dir instead | 
|---|
| 181 |  | 
|---|
| 182 | if [ "$create_dir" = "" ]; then | 
|---|
| 183 | create_dir=0 | 
|---|
| 184 | fi | 
|---|
| 185 |  | 
|---|
| 186 | if [ "$create_dir" -eq 1 ]; then | 
|---|
| 187 | mkdir -p "$lroot/scripts-$deploy" | 
|---|
| 188 | fs sa "$lroot/scripts-$deploy" system:anyuser none | 
|---|
| 189 | fs sa "$lroot/scripts-$deploy" system:authuser none | 
|---|
| 190 | fs sa "$lroot/scripts-$deploy" daemon.scripts write | 
|---|
| 191 | fs sa "$lroot/scripts-$deploy" system:scripts-security-upd write | 
|---|
| 192 | fi | 
|---|
| 193 |  | 
|---|
| 194 | # This is the better version | 
|---|
| 195 |  | 
|---|
| 196 | if [ "$create_scripts_dir" = "" ]; then | 
|---|
| 197 | create_scripts_dir=0 | 
|---|
| 198 | fi | 
|---|
| 199 |  | 
|---|
| 200 | if [ "$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 | 
|---|
| 206 | fi | 
|---|
| 207 |  | 
|---|
| 208 | if [ "$wizard" != "" ]; then | 
|---|
| 209 | vsshrun "wizard/bin/wizard" "install" "$@" "$wizard" "$lroot/web_scripts/$addrend" | 
|---|
| 210 | exit 0 | 
|---|
| 211 | fi | 
|---|
| 212 |  | 
|---|
| 213 | if [ "$prompt_username" = "" ]; then | 
|---|
| 214 | admin_username="admin" | 
|---|
| 215 | prompt_username=0 | 
|---|
| 216 | fi | 
|---|
| 217 | if [ "$prompt_password" = "" ]; then | 
|---|
| 218 | prompt_password=1 | 
|---|
| 219 | fi | 
|---|
| 220 |  | 
|---|
| 221 | if [ "$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 | 
|---|
| 236 | fi | 
|---|
| 237 |  | 
|---|
| 238 | if [ "$prompt_password" -eq 1 ]; then | 
|---|
| 239 | stty -echo | 
|---|
| 240 | sshrun "deploy$scriptsdev/bin/prompt-password" "$sname" "$deploy" "$addrend" "$admin_username" | 
|---|
| 241 | stty echo | 
|---|
| 242 | fi | 
|---|
| 243 |  | 
|---|
| 244 | echo | 
|---|
| 245 | echo "Unpacking $sname... (this step might take several minutes)" | 
|---|
| 246 | # xavid: use p to keep the same permissions as in the file | 
|---|
| 247 | athrun scripts gtar zxpf "/mit/scripts/deploy$scriptsdev/$deploy.tar.gz" | 
|---|
| 248 | files=`athrun scripts gfind . -mindepth 1 -maxdepth 1 | grep -v .admin` | 
|---|
| 249 | numfiles=`echo "$files" | wc -l` | 
|---|
| 250 | if [ ! -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 | 
|---|
| 255 | fi | 
|---|
| 256 | if [ -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/"' -- {} \; | 
|---|
| 260 | fi | 
|---|
| 261 | cd "$origdir" | 
|---|
| 262 |  | 
|---|
| 263 | vsshrun "deploy$scriptsdev/bin/$deploy" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration" | 
|---|
| 264 | rm -f "$lroot/web_scripts/$addrend/.scripts-tmp" | 
|---|
| 265 | checkfailed | 
|---|
| 266 |  | 
|---|
| 267 | echo | 
|---|
| 268 | echo "== Installation complete! ==" | 
|---|
| 269 | echo "You should now be able to access your new copy of $sname at" | 
|---|
| 270 | echo "http://$lname.scripts.mit.edu/$addrend/" | 
|---|
| 271 | echo "(You can replace the http with https if you want to use encryption)" | 
|---|
| 272 | echo "If you have trouble accessing it, feel free to contact" | 
|---|
| 273 | echo "the $aimaintainer team by e-mailing $aicontact" | 
|---|
| 274 | exit 0 | 
|---|