-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapttool-installed.sh
executable file
·87 lines (74 loc) · 2.01 KB
/
apttool-installed.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# ...Lists all non-base packages (packages installed after OS install).
# This is much faster than `apttool -I`.
# -Christopher Welborn 04-07-2019
appname="apttool-installed"
appversion="0.0.1"
apppath="$(readlink -f "${BASH_SOURCE[0]}")"
appscript="${apppath##*/}"
# appdir="${apppath%/*}"
function echo_err {
# Echo to stderr.
echo -e "$@" 1>&2
}
function fail {
# Print a message to stderr and exit with an error status code.
echo_err "$@"
exit 1
}
function fail_usage {
# Print a usage failure message, and exit with an error status code.
print_usage "$@"
exit 1
}
function list_installed {
comm -13 \
<(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort) \
<(comm -23 \
<(dpkg-query -W -f='${Package}\n' | sed 1d | sort) \
<(apt-mark showauto | sort) \
)
}
function print_usage {
# Show usage reason if first arg is available.
[[ -n "$1" ]] && echo_err "\n$1\n"
echo "$appname v. $appversion
Usage:
$appscript -h | -v
$appscript [PATTERN...]
Options:
PATTERN : One or more text/regex patterns to filter patterns.
This is just a shorter way to build multiple grep
patterns.
-h,--help : Show this message.
-v,--version : Show $appname version and exit.
"
}
declare -a nonflags
for arg; do
case "$arg" in
"-h" | "--help")
print_usage ""
exit 0
;;
"-v" | "--version")
echo -e "$appname v. $appversion\n"
exit 0
;;
-*)
fail_usage "Unknown flag argument: $arg"
;;
*)
nonflags+=("$arg")
esac
done
if ((${#nonflags[@]})); then
filterpat=""
for pkgname in "${nonflags[@]}"; do
[[ -n "$filterpat" ]] && filterpat="${filterpat}|"
filterpat="${filterpat}($pkgname)"
done
list_installed | grep -E "$filterpat"
else
list_installed
fi