Re: autoup.sh & considerations on bail-out scripts
On Wed, 18 Feb 1998, Craig Sanders wrote:
> The trouble with it is that it makes a few assumptions about the format
> of the status file which I'm not sure will always be true.
> Firstly, it assumes that the "Status: " line is always immediately after
> the "Package: " line....which seems like a safe bet but i don't know if
> it will always be true.
It isn't in fact. I ran some tests on this; look at the output of:
awk 'BEGIN { FS = "\n"; RS = "" }
$1 !~ /^Package: / { print }
$2 !~ /^Status: / { print }' /var/lib/dpkg/status
"Package: " is always the first record, but "Status: " comes third if
there is an "Essential: " field in the record.
This should work regardless of which line has the "Status: " field:
awk '/^Package: / { package = $2 }
/^Status: / { if ( $4 == "installed" ) print package }' \
/var/lib/dpkg/status
Here's an extended version that reads a list of regexp's from stdin and
prints a single line of packages to be purged on stdout:
---cut here---
awk '# script to find installed packages that match
# a list of regexps on stdin.
BEGIN {
# write result on a single line to stdout.
ORS = " "
# first create a hash of installed packages
while ( ( getline < "/var/lib/dpkg/status" ) > 0 )
{ if ( /^Package: / )
package = $2
if ( /^Status: / && $4 == "installed" )
instpkgs[ package ] = 0
}
}
# main loop: now read regexps describing packages to purge
# from stdin and match them with list of installed packages.
{ for ( package in instpkgs )
if ( match( package, $1 ) )
instpkgs[ package ] = 1
}
END {
## crude hack: dpkg-dev as an exception must not be purged??
instpkgs[ "dpkg-dev" ] = 0
# write the list of installed packages that matched.
for ( package in instpkgs )
if ( instpkgs[ package ] == 1 )
print package
}' << END-OF-LIST
-dev
-pic
-dbg
^timezone$
xmanpages
perl-
locale
libptread0
xslib
splay
boot-floppies
END-OF-LIST
---cut here---
I took some liberties in the "regexp's" (dang, that apostroph in a
comment cost me 1.5 hours of debugging.)
I hope that dpkg-dev is the only package that needs to stay on the system,
or the script may become too much a crude hack altogether.
Cheers,
Joost
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: