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