[127] | 1 | #!/bin/sh |
---|
| 2 | |
---|
[1493] | 3 | : ${aicontact:=scripts@mit.edu} |
---|
| 4 | : ${aimaintainer:=scripts.mit.edu} |
---|
[1492] | 5 | |
---|
| 6 | |
---|
[127] | 7 | checkfailed() { |
---|
| 8 | if [ -f "$lroot/web_scripts/$addrend/.failed" ]; then |
---|
[457] | 9 | rm -f "$lroot/web_scripts/$addrend/.failed" |
---|
[127] | 10 | exit 1 |
---|
| 11 | fi |
---|
| 12 | } |
---|
| 13 | |
---|
[456] | 14 | die() { |
---|
| 15 | echo "== INSTALLATION FAILED ==" |
---|
| 16 | echo "Sorry, the installation failed:" |
---|
| 17 | echo "$@" |
---|
[1492] | 18 | echo "Please contact $aicontact and provide a copy of the output of this installer." |
---|
[456] | 19 | exit 1 |
---|
| 20 | } |
---|
| 21 | |
---|
[1345] | 22 | attach scripts |
---|
| 23 | |
---|
[127] | 24 | sshrun() { |
---|
[1345] | 25 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" 2>/dev/null |
---|
[127] | 26 | } |
---|
| 27 | |
---|
| 28 | vsshrun() { |
---|
[1345] | 29 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" |
---|
[127] | 30 | } |
---|
| 31 | |
---|
| 32 | checksqlpass() { |
---|
[457] | 33 | errors=`sshrun "sql/bin$scriptsdev/test-password"` |
---|
[127] | 34 | if [ "$errors" != "" ]; then |
---|
| 35 | if [ "$1" -eq 1 ]; then |
---|
[457] | 36 | rm -f "$lroot/.sql/my.cnf" |
---|
[127] | 37 | fi |
---|
| 38 | echo |
---|
[463] | 39 | echo "ERROR:" |
---|
[127] | 40 | printf "$2" |
---|
| 41 | exit |
---|
| 42 | fi |
---|
| 43 | } |
---|
| 44 | |
---|
[465] | 45 | override=1 |
---|
[456] | 46 | if [ "$override" = "" ]; then |
---|
[1492] | 47 | echo "The $aimaintainer automatic installers are currently unavailable." |
---|
[456] | 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," |
---|
[1492] | 50 | echo "let us know by sending us an e-mail at $aicontact" |
---|
[456] | 51 | exit |
---|
| 52 | fi |
---|
[127] | 53 | |
---|
| 54 | echo |
---|
[1492] | 55 | echo "== Welcome to the $aimaintainer installer for $sname ==" |
---|
[127] | 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 |
---|
[1492] | 61 | echo "Please report problems with this installer to $aicontact." |
---|
[127] | 62 | echo |
---|
[457] | 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'." |
---|
[127] | 67 | printf "Please enter either '1' or '2' (without quotes): " |
---|
| 68 | read whofor |
---|
[457] | 69 | if [ "$whofor" = 1 ]; then |
---|
[733] | 70 | lname="${ATHENA_USER:-$USER}" |
---|
[457] | 71 | elif [ "$whofor" = 2 ]; then |
---|
[127] | 72 | echo |
---|
[457] | 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." |
---|
[127] | 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 |
---|
[457] | 81 | echo "ERROR:" |
---|
| 82 | echo "You must select either '1' or '2'." |
---|
[127] | 83 | exit 1 |
---|
| 84 | fi |
---|
[733] | 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" |
---|
[127] | 94 | |
---|
| 95 | echo |
---|
| 96 | echo Checking the status of your scripts.mit.edu account... |
---|
| 97 | |
---|
| 98 | attach scripts 2>/dev/null |
---|
[457] | 99 | . "/mit/scripts/bin$scriptsdev/signup-web" |
---|
[127] | 100 | |
---|
| 101 | echo |
---|
[457] | 102 | echo "Your new copy of $sname will appear on the web at a URL" |
---|
[1045] | 103 | echo "that starts with http://$lname.scripts.mit.edu/" |
---|
[457] | 104 | echo "Please decide upon a complete URL and enter it below." |
---|
[1045] | 105 | echo "You must enter one or more characters after mit.edu/" |
---|
[457] | 106 | echo "The completed address must only contain a-z, 0-9, and /." |
---|
[1045] | 107 | printf "Desired address: http://$lname.scripts.mit.edu/" |
---|
[127] | 108 | read addrend |
---|
| 109 | |
---|
[457] | 110 | addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"` |
---|
[127] | 111 | if [ "$addrend" = "" ]; then |
---|
| 112 | echo |
---|
[457] | 113 | echo "ERROR:" |
---|
[1045] | 114 | echo "You must enter one or more characters after mit.edu/" |
---|
[457] | 115 | echo "The completed address must only contain a-z, 0-9, and /." |
---|
[127] | 116 | exit 1 |
---|
| 117 | fi |
---|
| 118 | |
---|
| 119 | if [ -d "$lroot/web_scripts/$addrend" ]; then |
---|
| 120 | echo |
---|
[457] | 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" |
---|
[1492] | 124 | echo "contact $aicontact for assistance." |
---|
[127] | 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 |
---|
[457] | 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 |
---|
[127] | 137 | fi |
---|
| 138 | |
---|
[457] | 139 | fs sa "$lroot/.sql" system:anyuser none |
---|
| 140 | fs sa "$lroot/.sql" system:authuser none |
---|
[160] | 141 | |
---|
[127] | 142 | if [ "$requires_sql" -eq 1 ]; then |
---|
| 143 | sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"` |
---|
| 144 | if [ "$sqlinfo" = "" ]; then |
---|
| 145 | echo |
---|
[457] | 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." |
---|
[127] | 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 |
---|
[457] | 156 | . "/mit/scripts/sql/bin$scriptsdev/save-password" |
---|
[463] | 157 | checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n' |
---|
[127] | 158 | echo |
---|
[457] | 159 | echo "OK. Continuing with the install..." |
---|
[127] | 160 | else |
---|
[463] | 161 | checksqlpass 0 'The MySQL login information in your .my.cnf file\nappears to be incorrect.\n' |
---|
[127] | 162 | fi |
---|
| 163 | fi |
---|
| 164 | |
---|
[240] | 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 |
---|
[1045] | 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 |
---|
[240] | 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 | |
---|
[1045] | 180 | # This version is deprecated, use create_scripts_dir instead |
---|
| 181 | |
---|
[127] | 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 |
---|
[159] | 189 | fs sa "$lroot/scripts-$deploy" system:authuser none |
---|
[127] | 190 | fs sa "$lroot/scripts-$deploy" daemon.scripts write |
---|
| 191 | fs sa "$lroot/scripts-$deploy" system:scripts-security-upd write |
---|
| 192 | fi |
---|
| 193 | |
---|
[1045] | 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 | |
---|
[1344] | 208 | if [ "$wizard" != "" ]; then |
---|
[1346] | 209 | vsshrun "wizard/bin/wizard" "install" "$@" "$wizard" "$lroot/web_scripts/$addrend" |
---|
[1344] | 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)" |
---|
[1420] | 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" |
---|
[1344] | 262 | |
---|
[1420] | 263 | vsshrun "deploy$scriptsdev/bin/$deploy" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration" |
---|
[457] | 264 | rm -f "$lroot/web_scripts/$addrend/.scripts-tmp" |
---|
[127] | 265 | checkfailed |
---|
| 266 | |
---|
| 267 | echo |
---|
[457] | 268 | echo "== Installation complete! ==" |
---|
| 269 | echo "You should now be able to access your new copy of $sname at" |
---|
[1045] | 270 | echo "http://$lname.scripts.mit.edu/$addrend/" |
---|
[127] | 271 | echo "(You can replace the http with https if you want to use encryption)" |
---|
[457] | 272 | echo "If you have trouble accessing it, feel free to contact" |
---|
[1492] | 273 | echo "the $aimaintainer team by e-mailing $aicontact" |
---|
[127] | 274 | exit 0 |
---|