-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdel-pkg
67 lines (55 loc) · 1.08 KB
/
del-pkg
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
#!/bin/sh
set -e # Exit immediately if a command exits with a non-zero status.
usage() {
echo "usage: $(basename "$0") PKG [PKG...]"
}
#
# Alpine functions
#
del_pkg_alpine() {
apk --no-cache del "$@"
rm -rf /var/cache/misc/*
}
#
# Debian functions
#
del_pkg_debian() {
PKGS=
for PKG in "$@"
do
if ! dpkg --status "$1" 2>&1 | grep -q "^Status: install ok installed"; then
if [ -f /var/lib/apt/$PKG.virtual ]; then
PKGS="$PKGS $(cat /var/lib/apt/$PKG.virtual)"
rm /var/lib/apt/$PKG.virtual
else
PKGS="$PKGS $PKG"
fi
else
PKGS="$PKGS $PKG"
fi
done
if [ -n "$PKGS" ]; then
apt-get -q purge -y $PKGS
apt-get -q --purge autoremove -y
rm -rf /var/log/dpkg.log \
/var/log/apt/*
fi
}
#
# OS agnostic functions
#
del_pkg() {
if [ -n "$(which apk)" ]; then
del_pkg_alpine "$@"
else
del_pkg_debian "$@"
fi
}
#
# Main
#
if [ -z "$1" ]; then
usage
exit 1
fi
del_pkg "$@"