| 1 | #!/bin/sh | 
|---|
| 2 |  | 
|---|
| 3 | checkfailed() { | 
|---|
| 4 | if [ -f "$lroot/web_scripts/$addrend/.failed" ]; then | 
|---|
| 5 | rm -f "$lroot/web_scripts/$addrend/.failed" | 
|---|
| 6 | exit 1 | 
|---|
| 7 | fi | 
|---|
| 8 | } | 
|---|
| 9 |  | 
|---|
| 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 |  | 
|---|
| 18 | attach scripts | 
|---|
| 19 |  | 
|---|
| 20 | sshrun() { | 
|---|
| 21 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" 2>/dev/null | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | vsshrun() { | 
|---|
| 25 | /afs/athena.mit.edu/contrib/scripts/bin$scriptsdev/scripts-ssh "$lname" "/mit/scripts/$@" | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | checksqlpass() { | 
|---|
| 29 | errors=`sshrun "sql/bin$scriptsdev/test-password"` | 
|---|
| 30 | if [ "$errors" != "" ]; then | 
|---|
| 31 | if [ "$1" -eq 1 ]; then | 
|---|
| 32 | rm -f "$lroot/.sql/my.cnf" | 
|---|
| 33 | fi | 
|---|
| 34 | echo | 
|---|
| 35 | echo "ERROR:" | 
|---|
| 36 | printf "$2" | 
|---|
| 37 | exit | 
|---|
| 38 | fi | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | override=1 | 
|---|
| 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 | 
|---|
| 49 |  | 
|---|
| 50 | echo | 
|---|
| 51 | echo "== Welcome to the scripts.mit.edu installer for $sname ==" | 
|---|
| 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 | 
|---|
| 57 | echo "Please report problems with this installer to scripts@mit.edu." | 
|---|
| 58 | echo | 
|---|
| 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'." | 
|---|
| 63 | printf "Please enter either '1' or '2' (without quotes): " | 
|---|
| 64 | read whofor | 
|---|
| 65 | if [ "$whofor" = 1 ]; then | 
|---|
| 66 | lname="${ATHENA_USER:-$USER}" | 
|---|
| 67 | elif [ "$whofor" = 2 ]; then | 
|---|
| 68 | echo | 
|---|
| 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." | 
|---|
| 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 | 
|---|
| 77 | echo "ERROR:" | 
|---|
| 78 | echo "You must select either '1' or '2'." | 
|---|
| 79 | exit 1 | 
|---|
| 80 | fi | 
|---|
| 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" | 
|---|
| 90 |  | 
|---|
| 91 | echo | 
|---|
| 92 | echo Checking the status of your scripts.mit.edu account... | 
|---|
| 93 |  | 
|---|
| 94 | attach scripts 2>/dev/null | 
|---|
| 95 | . "/mit/scripts/bin$scriptsdev/signup-web" | 
|---|
| 96 |  | 
|---|
| 97 | echo | 
|---|
| 98 | echo "Your new copy of $sname will appear on the web at a URL" | 
|---|
| 99 | echo "that starts with http://$lname.scripts.mit.edu/" | 
|---|
| 100 | echo "Please decide upon a complete URL and enter it below." | 
|---|
| 101 | echo "You must enter one or more characters after mit.edu/" | 
|---|
| 102 | echo "The completed address must only contain a-z, 0-9, and /." | 
|---|
| 103 | printf "Desired address: http://$lname.scripts.mit.edu/" | 
|---|
| 104 | read addrend | 
|---|
| 105 |  | 
|---|
| 106 | addrend=`perl -0e 'print $ARGV[0] =~ /^([\w\/-]*[\w-])\/*$/' -- "$addrend"` | 
|---|
| 107 | if [ "$addrend" = "" ]; then | 
|---|
| 108 | echo | 
|---|
| 109 | echo "ERROR:" | 
|---|
| 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 | exit 1 | 
|---|
| 113 | fi | 
|---|
| 114 |  | 
|---|
| 115 | if [ -d "$lroot/web_scripts/$addrend" ]; then | 
|---|
| 116 | echo | 
|---|
| 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." | 
|---|
| 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 | 
|---|
| 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 | 
|---|
| 133 | fi | 
|---|
| 134 |  | 
|---|
| 135 | fs sa "$lroot/.sql" system:anyuser none | 
|---|
| 136 | fs sa "$lroot/.sql" system:authuser none | 
|---|
| 137 |  | 
|---|
| 138 | if [ "$requires_sql" -eq 1 ]; then | 
|---|
| 139 | sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"` | 
|---|
| 140 | if [ "$sqlinfo" = "" ]; then | 
|---|
| 141 | echo | 
|---|
| 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." | 
|---|
| 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 | 
|---|
| 152 | . "/mit/scripts/sql/bin$scriptsdev/save-password" | 
|---|
| 153 | checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n' | 
|---|
| 154 | echo | 
|---|
| 155 | echo "OK.  Continuing with the install..." | 
|---|
| 156 | else | 
|---|
| 157 | checksqlpass 0 'The MySQL login information in your .my.cnf file\nappears to be incorrect.\n' | 
|---|
| 158 | fi | 
|---|
| 159 | fi | 
|---|
| 160 |  | 
|---|
| 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 | 
|---|
| 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 | 
|---|
| 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 |  | 
|---|
| 176 | # This version is deprecated, use create_scripts_dir instead | 
|---|
| 177 |  | 
|---|
| 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 | 
|---|
| 185 | fs sa "$lroot/scripts-$deploy" system:authuser none | 
|---|
| 186 | fs sa "$lroot/scripts-$deploy" daemon.scripts write | 
|---|
| 187 | fs sa "$lroot/scripts-$deploy" system:scripts-security-upd write | 
|---|
| 188 | fi | 
|---|
| 189 |  | 
|---|
| 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 |  | 
|---|
| 204 | if [ "$wizard" != "" ]; then | 
|---|
| 205 | vsshrun "wizard/bin/wizard" "install" "$@" "$wizard" "$lroot/web_scripts/$addrend" | 
|---|
| 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 | cd "$origdir" | 
|---|
| 241 |  | 
|---|
| 242 | echo | 
|---|
| 243 | echo "Unpacking $sname... (this step might take several minutes)" | 
|---|
| 244 |  | 
|---|
| 245 | vsshrun "deploy$scriptsdev/bin/$deploy" "$lname" "$sname" "$deploy" "$addrend" "$admin_username" "$requires_sql" "$scriptsdev" "$USER" || die "Unknown failure during configuration" | 
|---|
| 246 | rm -f "$lroot/web_scripts/$addrend/.scripts-tmp" | 
|---|
| 247 | checkfailed | 
|---|
| 248 |  | 
|---|
| 249 | echo | 
|---|
| 250 | echo "== Installation complete! ==" | 
|---|
| 251 | echo "You should now be able to access your new copy of $sname at" | 
|---|
| 252 | echo "http://$lname.scripts.mit.edu/$addrend/" | 
|---|
| 253 | echo "(You can replace the http with https if you want to use encryption)" | 
|---|
| 254 | echo "If you have trouble accessing it, feel free to contact" | 
|---|
| 255 | echo "the scripts.mit.edu team by e-mailing scripts@mit.edu" | 
|---|
| 256 | exit 0 | 
|---|