#!/usr/pkg/bin/perl # Author : Stefan Schumacher stefan[at]net-tex[dot]de PGP:0xb3fbae33 # License : BSD # /home/stefan/daten/cvs/net-tex.de/code/pkg_db.pl.txt,v 1.1 2025/06/24 15:09:06 stefan Exp # Requires : pkg_info and some basic binaries (grep, sort, hostname, date) # Purpose : creates 3 HTML files, 1 containing a list of all installed pkgs # linked to one with the detailed description of the pkg and one # with a list of installed files ### create filenames using current date my $date = `date +%y%m%d`; my $longdate = `date '+%y-%m-%d %H:%M'`; chomp $date; my $file = $date.'-pkg_db.html'; my $detailfile = $date.'-pkg_db-details.html'; my $filesfile = $date.'-pkg_db-files.html'; ### open file for details open DFILE,">>$detailfile" or die; my $detailhandle = select DFILE; ### open file for fileslist open FFILE,">>$filesfile" or die; my $filehandle = select FFILE; ### index open FILE,">>$file" or die; my $handle = select FILE; ### HTML Header $hostname=`hostname`; print("\nList of installed packages on $hostname as of $longdate\n"); print FFIlE "\nfiles of installed packages on $hostname as of $longdate\n"; print DFILE "\nDetailed list of installed packages on $hostname as of $longdate
\n"; my $installedbytes = 0; my $installedfiles = 0; my @pkglist= `pkg_info | sort`; my $installedpkgs = $#pkglist; for my $pkglistline (@pkglist) { ### get name of installed pkg my $ipkg=(split / /, $pkglistline)[0]; ### get short description of pkg my $sdesc=(split / /, $pkglistline,2)[1]; ### get size of pkg my $pkgsize=`pkg_info -s $ipkg | grep bytes`; my $pkgsize=(split / /, $pkgsize)[6]; $pkgsize=$pkgsize/1024/1024; $pkgsize = sprintf("%.2f", $pkgsize); $installedbytes += $pkgsize; ### remove CR/LF & leading whitespace (space not followed by a char) chomp($sdesc); $sdesc =~ s/ [^\w,\(]//g; ### get list of files per pkg my @fileslist=`pkg_info -L $ipkg`; $installedfiles += $#fileslist; print FFILE "


\n
@fileslist
"; ### print a HTML formatted text (
) print FILE ("\n\n\n\n"; ### get detailed info per pkg my $pkglinfo =`pkg_info $ipkg`; ### substitute HTML entities $pkglinfo =~ s//>/g; $pkglinfo =~ s/^([\w]+.[\w]+):\n/$1:<\/b>\n/g; # print field descriptor bold $pkglinfo =~ s/http:\/\/([a-zA-Z0-9_\/\-.~]+)/http:\/\/$1<\/a>/g;# html-lize links $pkglinfo =~ s/\n/
\n/g; print DFILE "\n

\n$pkglinfo"; } ### HTML footer $installedbytes=$installedbytes/1024; $installedbytes=sprintf("%.2f",$installedbytes); print("
There are $installedpkgs Packages installed in $installedfiles files using $installedbytes MB

\n
$ipkg
$sdesc
"); print FILE "$#fileslist installed Files
"; print FILE "Size of this pkg in mB : $pkgsize
\n"); print FFILE "\n"; print DFILE "\n";