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