-
Notifications
You must be signed in to change notification settings - Fork 3
/
delete-old-package.sh
executable file
·65 lines (51 loc) · 1.44 KB
/
delete-old-package.sh
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
#!/bin/bash
debs="$1"
if [[ "$debs" == "" ]]; then
echo "Usage: $0 <debs dir>"
exit
fi
echo "Cleaning old debs in $debs"
function package_name() {
local file="$1"
dpkg-deb --info $file | grep Package: | cut -d':' -f2 | sed 's| ||g'
}
function package_version() {
local file="$1"
dpkg-deb --info $file | grep Version: | cut -d':' -f2 | sed 's| ||g'
}
function package_arch() {
local file="$1"
dpkg-deb --info $file | grep Architecture: | cut -d':' -f2 | sed 's| ||g'
}
declare -A aarch64_PKG
declare -A x86_64_PKG
declare -A arm_PKG
declare -A i686_PKG
declare -A all_PKG
for pkg_file in $debs/*.deb; do
package_name="$(package_name $pkg_file)"
package_arch="$(package_arch $pkg_file)"
package_version="$(package_version $pkg_file)"
# echo "Checking for $package_name @ $package_arch - $package_version"
declare -n T="${package_arch}_PKG"
if [[ "${T[$package_name]}" == "" ]]; then
T["$package_name"]="$pkg_file"
continue
else
prev_file="${T["$package_name"]}"
prev_version="$(package_version $prev_file)"
./compare-version.sh "$package_version" "$prev_version" &>/dev/null
retval=$?
case $retval in
0 ) # Package version is the same.
;;
2 ) # package_version < prev_version
;;
1 ) # package_version > prev_version
T["$package_name"]="$pkg_file"
echo " Replacing $package_name @ $package_arch: $package_version, deleting old one: $prev_version ($prev_file)"
rm -f "$prev_file"
;;
esac
fi
done