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