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