source: locker/bin/scripts-remove @ 359

Last change on this file since 359 was 328, checked in by andersk, 18 years ago
Add scripts-remove from geofft.
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1#!/bin/bash
2
3if [ "$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.
8fi
9
10sshrun() {
11    athrun scripts sshmic "$lname@scripts.mit.edu" "/mit/scripts/$@" 2>/dev/null
12}
13
14checksqlpass() {
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}
27attach scripts sql 2>/dev/null
28
29echo Welcome to the scripts.mit.edu uninstaller. This program will
30echo help you cleanly remove software that you have auto-installed.
31echo
32echo Are you removing an installation from:
33echo 1. Your personal Athena account
34echo 2. A locker that you control \(a club, a course, etc.\)
35echo If you do not understand this question, you should answer 1.
36printf "Please enter either 1 or 2: "
37read whofor
38if [ "$whofor" -eq 1 ]; then
39    lname=$USER
40    lroot=$HOME
41elif [ "$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"
47else
48    echo
49    echo ERROR:
50    echo You must select either 1 or 2.
51    exit 1
52fi
53attach "$lname" 2>/dev/null
54
55echo
56echo When you installed the software, you chose a URL
57echo that starts with http://scripts.mit.edu/~"$lname"/.
58echo Please enter the full URL where this software was
59echo installed. \(This should correspond to a directory
60echo in /mit/"$lname"/web_scripts/.\)
61printf "URL: http://scripts.mit.edu/~$lname/"
62read addrend
63
64addrend=`echo "$addrend" | sed -n 's/^\([a-z0-9A-Z\/-]*[a-z0-9A-Z-]\)\/\?$/\1/ p'`
65if [ "$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
71fi
72
73if [ ! -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
81fi
82
83echo
84
85sqlinfo=`sshrun "sql/bin$scriptsdev/get-password"`
86if [ "$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...
102else
103    checksqlpass 0 'The MySQL login information in your .my.cnf file\n' 'appears to be incorrect.\n'
104fi
105
106sqldb=`sshrun "sql/bin$scriptsdev/get-next-database" "$addrend"`
107if [ "$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
117fi
118
119echo Removing files. Please wait...
120echo \(This may take several seconds for large software.\)
121if 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
128else
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
135fi
136
137echo
138if [ "$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
158fi
159echo
160echo The installation in "scripts.mit.edu/~$lname/$addrend"
161echo has been successfully uninstalled.
Note: See TracBrowser for help on using the repository browser.