forked from gambit/gambit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall-gambc.in
201 lines (156 loc) · 4.23 KB
/
uninstall-gambc.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#! /bin/sh
# Copyright (c) 1994-2009 by Marc Feeley, All Rights Reserved.
PROGRAMS="@PROGRAMS@"
LIBRARIES="@LIBRARIES@"
INCLUDES="@INCLUDES@"
BIN_DIR="@BIN_DIR@"
LIB_DIR="@LIB_DIR@"
INCLUDE_DIR="@INCLUDE_DIR@"
INSTALL_DIR="@INSTALL_DIR@"
GAMBC_BIN_DIR="$INSTALL_DIR/current/bin"
GAMBC_LIB_DIR="$INSTALL_DIR/current/lib"
GAMBC_INCLUDE_DIR="$INSTALL_DIR/current/include"
PACKAGE_NAME="@PACKAGE_NAME@"
if [ "`id -un`" != "root" ] ; then
echo "You must execute this script as root!"
echo "Try executing the command:"
echo " sudo $0"
exit 1
fi
split_version() # version, sets `$ver1', `$ver2', and `$ver3'
{
ver1="`echo \"$1\" | sed -e 's&^v\([0-9][0-9]*\).\([0-9][0-9]*\).\([0-9][0-9]*\)$&\1&g'`"
ver2="`echo \"$1\" | sed -e 's&^v\([0-9][0-9]*\).\([0-9][0-9]*\).\([0-9][0-9]*\)$&\2&g'`"
ver3="`echo \"$1\" | sed -e 's&^v\([0-9][0-9]*\).\([0-9][0-9]*\).\([0-9][0-9]*\)$&\3&g'`"
}
compare_versions() # version_a, version_b, sets `$result' to -1, 0, or 1
{
split_version "$2"
b_ver1="$ver1"
b_ver2="$ver2"
b_ver3="$ver3"
split_version "$1"
if [ "$ver1" -lt "$b_ver1" ] ; then
result=-1
else
if [ "$ver1" -gt "$b_ver1" ] ; then
result=1
else
if [ "$ver2" -lt "$b_ver2" ] ; then
result=-1
else
if [ "$ver2" -gt "$b_ver2" ] ; then
result=1
else
if [ "$ver3" -lt "$b_ver3" ] ; then
result=-1
else
if [ "$ver3" -gt "$b_ver3" ] ; then
result=1
else
result=0
fi
fi
fi
fi
fi
fi
}
max_version() # versions, sets $max_vers
{
max_vers=""
for vers in $1 ; do
if [ "$max_vers" == "" ] ; then
max_vers="$vers"
else
compare_versions "$vers" "$max_vers"
if [ "$result" == "1" ] ; then
max_vers="$vers"
fi
fi
done
}
get_versions() # dir
{
versions="`ls -a "$1" | read_versions`"
}
read_versions()
{
versions=""
while read file ; do
split_version "$file"
if [ "$ver1" != "$file" ] ; then
versions="$versions $file"
fi
done
echo "$versions"
}
remove_all()
{
echo "Removing directory $INSTALL_DIR and all Gambit programs in $BIN_DIR, $LIB_DIR and $INCLUDE_DIR."
rm -rf "$INSTALL_DIR"
for f in $PROGRAMS ; do
rm -f "$BIN_DIR/$f"
done
for f in $LIBRARIES ; do
rm -f "$LIB_DIR/$f"
done
for f in $INCLUDES ; do
rm -f "$INCLUDE_DIR/$f"
done
}
if [ ! -d "$INSTALL_DIR" ] ; then
echo "$PACKAGE_NAME is not installed on this computer ($INSTALL_DIR does not exist)"
else
get_versions "$INSTALL_DIR"
if [ "$versions" == "" ] ; then
echo "No version of $PACKAGE_NAME are installed"
remove_all
else
if [ -L "$INSTALL_DIR/current" ] ; then
current=`readlink "$INSTALL_DIR/current"`
current_version="`basename \"$current\"`"
else
current_version=""
fi
version_to_remove="$1"
if [ "$version_to_remove" == "" ] ; then
if [ "$current_version" != "" -a -d "$INSTALL_DIR/$current_version" ] ; then
version_to_remove="$current_version"
else
max_version "$versions"
version_to_remove="$max_vers"
fi
fi
if [ ! -d "$INSTALL_DIR/$version_to_remove" ] ; then
echo "$PACKAGE_NAME $version_to_remove is not installed!"
echo "The following versions of $PACKAGE_NAME can be uninstalled:"
for version in $versions ; do
if [ "$version" == "$current_version" ] ; then
echo " $version (current version)"
else
echo " $version"
fi
done
else
versions_remaining=""
for version in $versions ; do
if [ "$version" != "$version_to_remove" ] ; then
versions_remaining="$versions_remaining $version"
fi
done
if [ "$versions_remaining" == "" ] ; then
remove_all
else
echo "Removing $INSTALL_DIR/$version_to_remove"
rm -rf "$INSTALL_DIR/$version_to_remove"
if [ "$current_version" == "$version_to_remove" ] ; then
max_version "$versions_remaining"
echo "$PACKAGE_NAME $max_vers is now the current version"
rm -f "$INSTALL_DIR/current"
ln -s "$INSTALL_DIR/$max_vers" "$INSTALL_DIR/current"
fi
fi
fi
fi
fi