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