You are not logged in.

#1 2016-05-19 02:43:47

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,652
Website

Script for quick package lookup

This doesn't do anything remarkable - it just strings together some dpkg and apt-cache commands to give you information about a package which might be on your system. A shortcut for people like me who are too lazy to remember all those options and who don't like typing. It will give you the usual apt information, whether it was auto or manually installed, and if auto a list of the packages which might have brought it in, apt-cache's "policy" output, and a list of the commands it provides. All of this can be done easily with simple commands, but this does it all at once. I use it quite often every day, so thought i'd share it.

Usage

pkg package [more packages...]

(you can give it a bunch of packagenames together)

Sample output of 'pkg pbuilder':

john@bunsen1:~$ pkg pbuilder
Package: pbuilder
Status: install ok installed
Priority: extra
Section: devel
Installed-Size: 998
Maintainer: Debian pbuilder maintenance team <pbuilder-maint@lists.alioth.debian.org>
Architecture: all
Version: 0.215+nmu3
Depends: coreutils (>= 4.5.8-1), debootstrap | cdebootstrap, dpkg-dev, debianutils (>= 1.13.1), wget, debconf (>= 0.5) | debconf-2.0
Recommends: fakeroot, net-tools | iproute2, sudo, devscripts
Suggests: pbuilder-uml, gdebi-core, cowdancer
Conffiles:
 /etc/bash_completion.d/pbuilder 433b7e04e36e6583033af83386d72bb2
 /etc/pbuilder/buildd-config.sh 48b942cabcc5fcfe94f28538239573ba
Description: personal package builder for Debian packages
 pbuilder constructs a chroot system, and builds a package inside the
 chroot.
 It is an ideal system to use to check
 that a package has correct build-dependencies.
 It uses apt extensively, and a local mirror, or a fast connection
 to a Debian mirror is ideal, but not necessary.
 .
 "pbuilder create" uses debootstrap to create a chroot image.
 .
 "pbuilder update" updates the image to the current state of
 testing/unstable/whatever
 .
 "pbuilder build" takes a *.dsc file and builds a binary in the chroot
 image.
 .
 pdebuild is a wrapper for Debian Developers, to allow running
 pbuilder just like "debuild", as a normal user.
Homepage: http://pbuilder.alioth.debian.org

Auto-installed
pbuilder
Reverse Depends:
  bunsen-meta-packaging

Policy:
pbuilder:
  Installed: 0.215+nmu3
  Candidate: 0.215+nmu3
  Version table:
     0.223~bpo8+1 0
        100 http://httpredir.debian.org/debian/ jessie-backports/main amd64 Packages
 *** 0.215+nmu3 0
        500 http://httpredir.debian.org/debian/ jessie/main amd64 Packages
        100 /var/lib/dpkg/status

Commands:
/usr/bin/debuild-pbuilder
/usr/bin/pdebuild
/usr/sbin/pbuilder

pbuilder: OK INSTALLED

And here's the code:

#!/bin/bash
# get info about packages, installed or not

output=''
for i in "$@"
do
    package=$( dpkg-query -s $i 2>/dev/null )
    if grep 'Status: install ok installed' > /dev/null <<< "$package"
    then
        if entry=$( grep -A2 " $1\$" /var/lib/apt/extended_states ) && grep -q 'Auto-Installed: 1' <<<"$entry"
        then
            package+="

Auto-installed
$(apt-cache rdepends --installed $i)"
        else
            package+="

Manually installed"
        fi
        package+="

Policy:
$(apt-cache policy $i)

Commands:
$( dpkg -L $i | grep 'bin/' )

$i: OK INSTALLED"
    else package="$i: NOT INSTALLED
$( apt-cache show $i 2>&1 )

$i: NOT INSTALLED"
    fi
output+="$package
--------------------------------------
"
done

if [ -t 1 ]
then
    echo "$output"
else
     leafpad <(echo "$output")
fi

exit

I make a symlink called "pkg" to the actual script, in ~/bin:

ln -s ~/scripts/pkg.sh ~/bin/pkg

Maybe some day I'll add an option to do a lookup on the Debian online package info...

Last edited by johnraff (2016-05-20 03:53:42)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#2 2016-05-19 16:10:22

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Script for quick package lookup

Thanks for this. It is a time-saver, as you say smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

Board footer

Powered by FluxBB