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