-
Notifications
You must be signed in to change notification settings - Fork 0
/
apt-user-installed
executable file
·48 lines (39 loc) · 1.24 KB
/
apt-user-installed
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
#!/bin/bash
if test "x$1" = "x--install"
then
if test \! -f "/etc/sysgit/apt-packages"
then
echo "Info: No apt-package file found. Thanks."
exit 0
fi
apt install -y $(cat /etc/sysgit/apt-packages)
exit 0
fi
get_packages() {
manual="$(apt-mark showmanual | sort)"
# substract:
substract="$(dpkg-query -W -f='${Package};${Priority}\n' | grep -E ";(required|important)$" | sed -r 's/;.*$//' | sort -u)"
manual="$(comm -2 -3 <(echo "${manual}") <(echo "${substract}"))"
#echo "${manual}" | xargs apt-cache rdepends --installed --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances
depends="$(grep -E "^(Pre-)?Depends:" /var/lib/dpkg/status)"
for p in ${manual}
do
# check if no rdepends:
# if test "x$(apt-cache rdepends --installed --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances "${p}" | grep -vE "^ " | wc -l)" = "x2"
if test "x$(echo "${depends}" | grep -E " ${p} | ${p}, | ${p}:| ${p}\$")" = "x"
then
echo ${p}
fi
done
}
if test "x$1" = "x--save"
then
if test \! -f "/etc/sysgit/apt-packages" || test \
"/var/lib/dpkg/status" -nt "/etc/sysgit/apt-packages"
then
mkdir -p "/etc/sysgit"
get_packages >/etc/sysgit/apt-packages
fi
else
get_packages
fi