|
0 |
#!/bin/bash
|
|
1 |
|
|
2 |
# Copyright (C) 2012 George Danchev <danchev@spnet.net>
|
|
3 |
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2, or (at your option)
|
|
7 |
# any later version.
|
|
8 |
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
17 |
# 02111-1307, USA.
|
|
18 |
|
|
19 |
SELF=$(basename "$0")
|
|
20 |
VER=0.3
|
|
21 |
|
|
22 |
OPT_CHECK_INSTALLED_PACKAGES=0
|
|
23 |
OPT_SHOW_INSTALLED_ENHANCEMENTS=0
|
|
24 |
OPT_VERBOSE=0
|
|
25 |
|
|
26 |
print_version() {
|
|
27 |
echo "$VER"
|
|
28 |
}
|
|
29 |
|
|
30 |
print_help() {
|
|
31 |
cat << HLP
|
|
32 |
${SELF} - show enhancement packages.
|
|
33 |
Options:
|
|
34 |
Program options start with dash or double dash, otherwise they
|
|
35 |
are interpreted as package names. Only non-installed enhancement
|
|
36 |
packages are printed out by default, use -ie to show them all.
|
|
37 |
|
|
38 |
-ip|--ip|-installed-packages|--installed-packages
|
|
39 |
Show enhancements of all installed packages (could be slow)
|
|
40 |
-ie|--ie|-installed-enhancements|--installed-enhancements
|
|
41 |
Show installed enhancement packages too
|
|
42 |
-h|-help|--help
|
|
43 |
-version|--version
|
|
44 |
-verbose|--verbose
|
|
45 |
|
|
46 |
Examples:
|
|
47 |
# check enhancement packages of all installed packages
|
|
48 |
${SELF} -ip
|
|
49 |
# check enhancement packages of selected packages
|
|
50 |
${SELF} pkg1 pkgN
|
|
51 |
|
|
52 |
HLP
|
|
53 |
}
|
|
54 |
|
|
55 |
pkgs_enhancing_pkg_status() {
|
|
56 |
# Figure out package Enhances:'ing a given package
|
|
57 |
EN=`grep-dctrl -n -s Package -F Enhances -X "${1}" /var/lib/apt/lists/*Packages`
|
|
58 |
case $? in
|
|
59 |
0) if test $OPT_VERBOSE != 0; then echo -e "Package <<$1>> could be Enhanced by:"; fi
|
|
60 |
;;
|
|
61 |
1) continue
|
|
62 |
;;
|
|
63 |
*) echo "${SELF}: Internal Error!"
|
|
64 |
exit 1
|
|
65 |
;;
|
|
66 |
esac
|
|
67 |
for e in `echo "${EN}" | sort | uniq | xargs` # now sort and unify
|
|
68 |
do
|
|
69 |
# Figure out whether those enhancements are installed or not.
|
|
70 |
# By default only output non-installed enhancements
|
|
71 |
OUT=""
|
|
72 |
case "${OPT_SHOW_INSTALLED_ENHANCEMENTS}" in
|
|
73 |
0) OUT=`apt-cache policy ${e} | head -3 | paste -s | grep "Installed: (none)"`
|
|
74 |
;;
|
|
75 |
1) OUT=`apt-cache policy ${e} | head -3 | paste -s`
|
|
76 |
;;
|
|
77 |
esac
|
|
78 |
if test x"$OUT" != x""; then printf "%2s => " "$1" && echo "${OUT}"; fi
|
|
79 |
done
|
|
80 |
}
|
|
81 |
|
|
82 |
# main
|
|
83 |
declare -a PKGS=()
|
|
84 |
for op in $@
|
|
85 |
do
|
|
86 |
case "${op}" in
|
|
87 |
-ip|--ip|-installed-packages|--installed-packages)
|
|
88 |
OPT_CHECK_INSTALLED_PACKAGES=1
|
|
89 |
;;
|
|
90 |
|
|
91 |
-ie|--ie|-installed-enhancements|--installed-enhancements)
|
|
92 |
OPT_SHOW_INSTALLED_ENHANCEMENTS=1
|
|
93 |
;;
|
|
94 |
|
|
95 |
-h|-help|--help)
|
|
96 |
print_help
|
|
97 |
exit 0
|
|
98 |
;;
|
|
99 |
|
|
100 |
-version|--version)
|
|
101 |
print_version
|
|
102 |
exit 0
|
|
103 |
;;
|
|
104 |
|
|
105 |
-verbose|--verbose)
|
|
106 |
OPT_VERBOSE=1
|
|
107 |
;;
|
|
108 |
|
|
109 |
-*)
|
|
110 |
echo "invalid option ${op}"
|
|
111 |
print_help
|
|
112 |
exit 1
|
|
113 |
;;
|
|
114 |
|
|
115 |
*)
|
|
116 |
# PKGS[$[${#PKGS[@]}+1]]="${op}"
|
|
117 |
PKGS+=(${op})
|
|
118 |
;;
|
|
119 |
esac
|
|
120 |
done
|
|
121 |
|
|
122 |
# no options, just show help
|
|
123 |
if test x"$1" == x""; then print_help; exit 0; fi
|
|
124 |
|
|
125 |
# process package names given on the cmdline
|
|
126 |
for cmdline_pkg in "${PKGS[@]}"
|
|
127 |
do
|
|
128 |
pkgs_enhancing_pkg_status $cmdline_pkg
|
|
129 |
done
|
|
130 |
|
|
131 |
# process installed packages, as well
|
|
132 |
case $OPT_CHECK_INSTALLED_PACKAGES in
|
|
133 |
1)
|
|
134 |
for installed in $(grep-status -FStatus "install ok installed" -n -s Package | sort | uniq)
|
|
135 |
do
|
|
136 |
pkgs_enhancing_pkg_status $installed
|
|
137 |
done
|
|
138 |
;;
|
|
139 |
esac
|
|
140 |
|
|
141 |
exit 0
|