diff --git a/check-enhancements b/check-enhancements new file mode 100755 index 0000000..2f70a90 --- /dev/null +++ b/check-enhancements @@ -0,0 +1,142 @@ +#!/bin/bash + +# Copyright (C) 2012 George Danchev + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +SELF=$(basename "$0") +VER=0.3 + +OPT_CHECK_INSTALLED_PACKAGES=0 +OPT_SHOW_INSTALLED_ENHANCEMENTS=0 +OPT_VERBOSE=0 + +print_version() { +echo "$VER" +} + +print_help() { +cat << HLP +${SELF} - show enhancement packages. +Options: + Program options start with dash or double dash, otherwise they + are interpreted as package names. Only non-installed enhancement + packages are printed out by default, use -ie to show them all. + + -ip|--ip|-installed-packages|--installed-packages + Show enhancements of all installed packages (could be slow) + -ie|--ie|-installed-enhancements|--installed-enhancements + Show installed enhancement packages too + -h|-help|--help + -version|--version + -verbose|--verbose + +Examples: +# check enhancement packages of all installed packages + ${SELF} -ip +# check enhancement packages of selected packages + ${SELF} pkg1 pkgN + +HLP +} + +pkgs_enhancing_pkg_status() { + # Figure out package Enhances:'ing a given package + EN=`grep-dctrl -n -s Package -F Enhances -X "${1}" /var/lib/apt/lists/*Packages` + case $? in + 0) if test $OPT_VERBOSE != 0; then echo -e "Package <<$1>> could be Enhanced by:"; fi + ;; + 1) continue + ;; + *) echo "${SELF}: Internal Error!" + exit 1 + ;; + esac + for e in `echo "${EN}" | sort | uniq | xargs` # now sort and unify + do + # Figure out whether those enhancements are installed or not. + # By default only output non-installed enhancements + OUT="" + case "${OPT_SHOW_INSTALLED_ENHANCEMENTS}" in + 0) OUT=`apt-cache policy ${e} | head -3 | paste -s | grep "Installed: (none)"` + ;; + 1) OUT=`apt-cache policy ${e} | head -3 | paste -s` + ;; + esac + if test x"$OUT" != x""; then printf "%2s => " "$1" && echo "${OUT}"; fi + done +} + +# main +declare -a PKGS=() +for op in $@ +do + case "${op}" in + -ip|--ip|-installed-packages|--installed-packages) + OPT_CHECK_INSTALLED_PACKAGES=1 + ;; + + -ie|--ie|-installed-enhancements|--installed-enhancements) + OPT_SHOW_INSTALLED_ENHANCEMENTS=1 + ;; + + -h|-help|--help) + print_help + exit 0 + ;; + + -version|--version) + print_version + exit 0 + ;; + + -verbose|--verbose) + OPT_VERBOSE=1 + ;; + + -*) + echo "invalid option ${op}" + print_help + exit 1 + ;; + + *) +# PKGS[$[${#PKGS[@]}+1]]="${op}" + PKGS+=(${op}) + ;; + esac +done + +# no options, just show help +if test x"$1" == x""; then print_help; exit 0; fi + +# process package names given on the cmdline +for cmdline_pkg in "${PKGS[@]}" +do + pkgs_enhancing_pkg_status $cmdline_pkg +done + +# process installed packages, as well +case $OPT_CHECK_INSTALLED_PACKAGES in + 1) + for installed in $(grep-status -FStatus "install ok installed" -n -s Package | sort | uniq) + do + pkgs_enhancing_pkg_status $installed + done + ;; +esac + +exit 0 diff --git a/debian/changelog b/debian/changelog index e6f9908..9e8c1f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,9 @@ * [dgrep] - Support (d)zegrep and (d)zfgrep. - Fix quoting to allow patterns with blanks + * [check-enhancements] + - New command by George Danchev (Closes: #679927) + - Add build-dependency on help2man for check-enhancements' man page * Bump debhelper compatibility to 9 to be able to use some more recent features. Update versioned debhelper build-dependency accordingly. * Revamp debian/rules diff --git a/debian/clean b/debian/clean new file mode 100644 index 0000000..9cfa9d5 --- /dev/null +++ b/debian/clean @@ -0,0 +1 @@ +check-enhancements.1 diff --git a/debian/control b/debian/control index a10ff57..e745aed 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,8 @@ Priority: optional Maintainer: Javier Fernandez-Sanguino Pen~a Uploaders: Axel Beckert -Build-Depends: debhelper (>= 9~) +Build-Depends: debhelper (>= 9~), + help2man Vcs-Git: git://anonscm.debian.org/collab-maint/debian-goodies.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/debian-goodies.git Standards-Version: 3.9.4 diff --git a/debian/copyright b/debian/copyright index 5e09008..5679c31 100644 --- a/debian/copyright +++ b/debian/copyright @@ -34,6 +34,10 @@ - debpaste Copyright (C) 2009 Hanno Hecker + + - check-enhancements + + Copyright (C) 2012 George Danchev - debian/ contents diff --git a/debian/install b/debian/install index d9a8797..c19edd3 100644 --- a/debian/install +++ b/debian/install @@ -1,4 +1,4 @@ -dgrep dglob debget dpigs debman popbugs which-pkg-broke dhomepage debmany/debmany usr/bin +dgrep dglob debget dpigs debman popbugs which-pkg-broke dhomepage debmany/debmany check-enhancements usr/bin checkrestart usr/sbin bash_completion/debian-goodies.pkgnames etc/bash_completion.d diff --git a/debian/manpages b/debian/manpages index b3aadfc..f54f0c0 100644 --- a/debian/manpages +++ b/debian/manpages @@ -7,6 +7,7 @@ dpigs.1 popbugs.1 which-pkg-broke.1 +check-enhancements.1 debmany/man/debmany.1 debmany/man/debmany.de.1diff --git a/debian/rules b/debian/rules index 89eb822..d1c7b08 100755 --- a/debian/rules +++ b/debian/rules @@ -10,6 +10,7 @@ override_dh_auto_install: for prog in $(PODDOC); do pod2man -c "Debian-goodies documentation" $$prog.pod > $$prog.1; done + help2man -N -m "Debian-goodies documentation" -o check-enhancements.1 ./check-enhancements override_dh_auto_clean: for prog in $(PODDOC); do rm -f $$prog.1; done