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