| 1 | #!/bin/bash | 
|---|
| 2 |  | 
|---|
| 3 | if [ "$scriptsdev" != "" -a "$scriptsdev" != "dev" ]; then | 
|---|
| 4 | echo ERROR: | 
|---|
| 5 | echo The \$scriptsdev variable is set to an invalid value. | 
|---|
| 6 | echo \(The variable should not be set.\) | 
|---|
| 7 | echo Please contact scripts@mit.edu. | 
|---|
| 8 | fi | 
|---|
| 9 |  | 
|---|
| 10 | sshrun() { | 
|---|
| 11 | athrun scripts scripts-ssh -l "$lname" "/mit/scripts/$@" 2>/dev/null | 
|---|
| 12 | } | 
|---|
| 13 |  | 
|---|
| 14 | checksqlpass() { | 
|---|
| 15 | errors=`sshrun "sql/bin$scriptsdev/test-password"` | 
|---|
| 16 | if [ "$errors" != "" ]; then | 
|---|
| 17 | if [ "$1" -eq 1 ]; then | 
|---|
| 18 | rm -f "$lroot/.sql/my.cnf" | 
|---|
| 19 | fi | 
|---|
| 20 | echo | 
|---|
| 21 | echo ERROR: | 
|---|
| 22 | printf "$2" | 
|---|
| 23 | printf "$3" | 
|---|
| 24 | exit 1 | 
|---|
| 25 | fi | 
|---|
| 26 | } | 
|---|
| 27 | attach scripts sql 2>/dev/null | 
|---|
| 28 |  | 
|---|
| 29 | echo Welcome to the scripts.mit.edu uninstaller. This program will | 
|---|
| 30 | echo help you cleanly remove software that you have auto-installed. | 
|---|
| 31 | echo | 
|---|
| 32 | echo Are you removing an installation from: | 
|---|
| 33 | echo 1. Your personal Athena account | 
|---|
| 34 | echo 2. A locker that you control \(a club, a course, etc.\) | 
|---|
| 35 | echo If you do not understand this question, you should answer 1. | 
|---|
| 36 | printf "Please enter either 1 or 2: " | 
|---|
| 37 | read whofor | 
|---|
| 38 | if [ "$whofor" -eq 1 ]; then | 
|---|
| 39 | lname=$USER | 
|---|
| 40 | lroot=$HOME | 
|---|
| 41 | elif [ "$whofor" -eq 2 ]; then | 
|---|
| 42 | echo | 
|---|
| 43 | echo Please enter the name of the selected locker below. | 
|---|
| 44 | echo "(For the locker /mit/sipb, you would enter sipb.)" | 
|---|
| 45 | read lname | 
|---|
| 46 | lroot="/mit/$lname" | 
|---|
| 47 | else | 
|---|
| 48 | echo | 
|---|
| 49 | echo ERROR: | 
|---|
| 50 | echo You must select either 1 or 2. | 
|---|
| 51 | exit 1 | 
|---|
| 52 | fi | 
|---|
| 53 | attach "$lname" 2>/dev/null | 
|---|
| 54 |  | 
|---|
| 55 | echo | 
|---|
| 56 | echo When you installed the software, you chose a URL | 
|---|
| 57 | echo that starts with http://scripts.mit.edu/~"$lname"/. | 
|---|
| 58 | echo Please enter the full URL where this software was | 
|---|
| 59 | echo installed. \(This should correspond to a directory | 
|---|
| 60 | echo in /mit/"$lname"/web_scripts/.\) | 
|---|
| 61 | printf "URL: http://scripts.mit.edu/~$lname/" | 
|---|
| 62 | read addrend | 
|---|
| 63 |  | 
|---|
| 64 | addrend=`echo "$addrend" | sed -n 's/^\([a-z0-9A-Z\/-]*[a-z0-9A-Z-]\)\/\?$/\1/ p'` | 
|---|
| 65 | if [ "$addrend" = "" ]; then | 
|---|
| 66 | echo | 
|---|
| 67 | echo ERROR: | 
|---|
| 68 | echo You must enter one or more characters after "~$lname/" | 
|---|
| 69 | echo The completed address must only contain a-z, 0-9, and /. | 
|---|
| 70 | exit 1 | 
|---|
| 71 | fi | 
|---|
| 72 |  | 
|---|
| 73 | if [ ! -d "$lroot/web_scripts/$addrend" ]; then | 
|---|
| 74 | echo | 
|---|
| 75 | echo ERROR: | 
|---|
| 76 | echo The directory "$lroot/web_scripts/$addrend" | 
|---|
| 77 | echo does not exist. Please make sure that this is the | 
|---|
| 78 | echo correct installation directory, and try again, or | 
|---|
| 79 | echo contact scripts@mit.edu for assistance. | 
|---|
| 80 | exit 1 | 
|---|
| 81 | fi | 
|---|
| 82 |  | 
|---|
| 83 | echo | 
|---|
| 84 |  | 
|---|
| 85 | sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"` | 
|---|
| 86 | if [ "$sqlinfo" = "" ]; then | 
|---|
| 87 | echo | 
|---|
| 88 | echo You have a MySQL account but you do not have a .my.cnf file. | 
|---|
| 89 | echo If you do not remember your MySQL account password, you can change it | 
|---|
| 90 | echo at http://sql.mit.edu using MIT certificates. | 
|---|
| 91 | printf "Please type your MySQL password and press [enter]: " | 
|---|
| 92 | stty -echo | 
|---|
| 93 | read sqlpass | 
|---|
| 94 | stty echo | 
|---|
| 95 | echo | 
|---|
| 96 | sqlhost="sql.mit.edu" | 
|---|
| 97 | sqluser=$lname | 
|---|
| 98 | . "/mit/scripts/sql/bin$scriptsdev/save-password" | 
|---|
| 99 | checksqlpass 1 'The MySQL password that you typed appears to be incorrect.\n' '' | 
|---|
| 100 | echo | 
|---|
| 101 | echo OK.  Continuing with the uninstaller... | 
|---|
| 102 | else | 
|---|
| 103 | checksqlpass 0 'The MySQL login information in your .my.cnf file\n' 'appears to be incorrect.\n' | 
|---|
| 104 | fi | 
|---|
| 105 |  | 
|---|
| 106 | sqldb=`sshrun "sql/bin$scriptsdev/get-next-database" "$addrend"` | 
|---|
| 107 | if [ "$sqldb" != "${addrend}1" -a "$sqldb" != "$addrend" ]; then | 
|---|
| 108 | echo | 
|---|
| 109 | echo ERROR: | 
|---|
| 110 | echo The auto-uninstaller was unable to find the appropriate | 
|---|
| 111 | echo database to drop. Please examine the installation to | 
|---|
| 112 | echo find the database it uses, drop the database from | 
|---|
| 113 | echo http://sql.mit.edu/, and manually remove the "$addrend" | 
|---|
| 114 | echo directory \(or re-run the auto-installer\). Contact | 
|---|
| 115 | echo scripts@mit.edu if you need assistance. | 
|---|
| 116 | exit 1 | 
|---|
| 117 | fi | 
|---|
| 118 |  | 
|---|
| 119 | echo Removing files. Please wait... | 
|---|
| 120 | echo \(This may take several seconds for large software.\) | 
|---|
| 121 | if rm -rf "$lroot/web_scripts/$addrend"; then | 
|---|
| 122 | echo The directory "$lroot/web_scripts/$addrend" | 
|---|
| 123 | echo was successfully removed. | 
|---|
| 124 | if [ -d "$lroot/OldFiles/web_scripts/$addrend" ]; then | 
|---|
| 125 | echo A one-day-old backup of the installation is | 
|---|
| 126 | echo available from "$lroot/OldFiles/web_scripts/$addrend". | 
|---|
| 127 | fi | 
|---|
| 128 | else | 
|---|
| 129 | echo ERROR: | 
|---|
| 130 | echo The directory "$lroot/web_scripts/$addrend" | 
|---|
| 131 | echo could not be removed. Please ensure that you have | 
|---|
| 132 | echo access to this directory and try again, or | 
|---|
| 133 | echo contact scripts@mit.edu for assistance. | 
|---|
| 134 | exit 1 | 
|---|
| 135 | fi | 
|---|
| 136 |  | 
|---|
| 137 | echo | 
|---|
| 138 | if [ "$sqldb" = "${addrend}1" ]; then | 
|---|
| 139 | sqldb="$lname+$addrend" | 
|---|
| 140 | dropped=`sshrun sql/bin$scriptsdev/drop-database "$sqldb"` | 
|---|
| 141 | if [ "$dropped" ]; then | 
|---|
| 142 | echo The database "$sqldb" | 
|---|
| 143 | echo was successfully removed. | 
|---|
| 144 | attach sql 2>/dev/null | 
|---|
| 145 | if [ -f "/mit/sql/backup/$lname/$sqldb.sql.gz" ]; then | 
|---|
| 146 | echo A one-day-old backup of your SQL database is | 
|---|
| 147 | echo available in /mit/sql/backup/"$lname". | 
|---|
| 148 | fi | 
|---|
| 149 | exit | 
|---|
| 150 | else | 
|---|
| 151 | echo ERROR: | 
|---|
| 152 | echo The database "$lname+$addrend" | 
|---|
| 153 | echo could not be automatically removed. You can | 
|---|
| 154 | echo try removing it from http://sql.mit.edu/, | 
|---|
| 155 | echo or you can contact sql@mit.edu for assistance. | 
|---|
| 156 | exit 1 | 
|---|
| 157 | fi | 
|---|
| 158 | fi | 
|---|
| 159 | echo | 
|---|
| 160 | echo The installation in "scripts.mit.edu/~$lname/$addrend" | 
|---|
| 161 | echo has been successfully uninstalled. | 
|---|