[127] | 1 | #!/bin/sh |
---|
| 2 | |
---|
[1492] | 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 | |
---|
[127] | 12 | checkfailed() { |
---|
| 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] | 19 | die() { |
---|
| 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] | 27 | attach scripts |
---|
| 28 | |
---|
[127] | 29 | sshrun() { |
---|
[1345] | 30 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" 2>/dev/null |
---|
[127] | 31 | } |
---|
| 32 | |
---|
| 33 | vsshrun() { |
---|
[1345] | 34 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" |
---|
[127] | 35 | } |
---|
| 36 | |
---|
| 37 | checksqlpass() { |
---|
[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] | 50 | override=1 |
---|
[456] | 51 | if [ "$override" = "" ]; then |
---|
[1492] | 52 | echo "The $aimaintainer automatic installers are currently unavailable." |
---|
[456] | 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," |
---|
[1492] | 55 | echo "let us know by sending us an e-mail at $aicontact" |
---|
[456] | 56 | exit |
---|
| 57 | fi |
---|
[127] | 58 | |
---|
| 59 | echo |
---|
[1492] | 60 | echo "== Welcome to the $aimaintainer installer for $sname ==" |
---|
[127] | 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 |
---|
[1492] | 66 | echo "Please report problems with this installer to $aicontact." |
---|
[127] | 67 | echo |
---|
[457] | 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'." |
---|
[127] | 72 | printf "Please enter either '1' or '2' (without quotes): " |
---|
| 73 | read whofor |
---|
[457] | 74 | if [ "$whofor" = 1 ]; then |
---|
[733] | 75 | lname="${ATHENA_USER:-$USER}" |
---|
[457] | 76 | elif [ "$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 |
---|
| 84 | else |
---|
| 85 | echo |
---|
[457] | 86 | echo "ERROR:" |
---|
| 87 | echo "You must select either '1' or '2'." |
---|
[127] | 88 | exit 1 |
---|
| 89 | fi |
---|
[733] | 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" |
---|
[127] | 99 | |
---|
| 100 | echo |
---|
| 101 | echo Checking the status of your scripts.mit.edu account... |
---|
| 102 | |
---|
| 103 | attach scripts 2>/dev/null |
---|
[457] | 104 | . "/mit/scripts/bin$scriptsdev/signup-web" |
---|
[127] | 105 | |
---|
| 106 | echo |
---|
[457] | 107 | echo "Your new copy of $sname will appear on the web at a URL" |
---|
[1045] | 108 | echo "that starts with http://$lname.scripts.mit.edu/" |
---|
[457] | 109 | echo "Please decide upon a complete URL and enter it below." |
---|
[1045] | 110 | echo "You must enter one or more characters after mit.edu/" |
---|
[457] | 111 | echo "The completed address must only contain a-z, 0-9, and /." |
---|
[1045] | 112 | printf "Desired address: http://$lname.scripts.mit.edu/" |
---|
[127] | 113 | read addrend |
---|
| 114 | |
---|
[457] | 115 | addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"` |
---|
[127] | 116 | if [ "$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 |
---|
| 122 | fi |
---|
| 123 | |
---|
| 124 | if [ -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 |
---|
| 131 | fi |
---|
| 132 | |
---|
| 133 | if [ "$requires_sql" = "" ]; then |
---|
| 134 | requires_sql=1 |
---|
| 135 | fi |
---|
| 136 | |
---|
| 137 | if [ ! -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] | 142 | fi |
---|
| 143 | |
---|
[457] | 144 | fs sa "$lroot/.sql" system:anyuser none |
---|
| 145 | fs sa "$lroot/.sql" system:authuser none |
---|
[160] | 146 | |
---|
[127] | 147 | if [ "$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 |
---|
| 168 | fi |
---|
| 169 | |
---|
[240] | 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 |
---|
[1045] | 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 |
---|
[240] | 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 | |
---|
[1045] | 185 | # This version is deprecated, use create_scripts_dir instead |
---|
| 186 | |
---|
[127] | 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 |
---|
[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 |
---|
| 197 | fi |
---|
| 198 | |
---|
[1045] | 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 | |
---|
[1344] | 213 | if [ "$wizard" != "" ]; then |
---|
[1346] | 214 | vsshrun "wizard/bin/wizard" "install" "$@" "$wizard" "$lroot/web_scripts/$addrend" |
---|
[1344] | 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)" |
---|
[1420] | 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" |
---|
[1344] | 267 | |
---|
[1420] | 268 | vsshrun "deploy$scriptsdev/bin/$deploy" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration" |
---|
[457] | 269 | rm -f "$lroot/web_scripts/$addrend/.scripts-tmp" |
---|
[127] | 270 | checkfailed |
---|
| 271 | |
---|
| 272 | echo |
---|
[457] | 273 | echo "== Installation complete! ==" |
---|
| 274 | echo "You should now be able to access your new copy of $sname at" |
---|
[1045] | 275 | echo "http://$lname.scripts.mit.edu/$addrend/" |
---|
[127] | 276 | echo "(You can replace the http with https if you want to use encryption)" |
---|
[457] | 277 | echo "If you have trouble accessing it, feel free to contact" |
---|
[1492] | 278 | echo "the $aimaintainer team by e-mailing $aicontact" |
---|
[127] | 279 | exit 0 |
---|