NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Possible helper script, perhaps an addition to pkgin?



Hello,

I am very happy to use pkgin, I think it has functionality I have NOT
seen in other package managers.

For example, I find pkgin ex(port) extremely elegant and useful. In
combination with pkgin im(port), it allows duplicating installed
packages from one system to another (e.g. during upgrades).

However, I would think further automation would be useful, especially
to anyone who has to administer more than one system. I have not seen
any other ways to do that (yet?).

TO that end, I cobbled together (for myself, but wanted to share in
case it is useful to others) a shell script which I run instead of
pkgin in. Why?

pkgin in by itself doesn't log the pre-installation or
post-installation state, when it was done, or other useful meta-data.

So instead of pkgin in foo
I run my script:

export-pkg-install-new.sh foo

It creates logs in the $USER/Documents directory.
First a Previous-export and Previous-showkeep (export is most useful
for import, but showkeep is more human readable, and has more detail)
This is the before install log

Then it installs foo

Then it logs the after install log as:
YYYY-MM-DD-export-$USER
and
YYYY_MM_DD-showkeep-$USER

The script runs as su, because it leverages pkgin commands that are by
default restricted to root, but the log is readable by the group wheel,
which the first created non-root account usually is. Modification to
run as non-root would also be an enhancement. As would adding the
ability to transfer logs via scp or similar, to a separate server, so
centralized backup of package lists for each system can be setup.

The script can be invoked manually, but with the right configuration,
also automatically, such as via cron or the like.

The script:

#!/usr/bin/env ksh
#export-pkg-install-new.sh
#created/modified by LGD, 2026-03-30
#

	#requires the presence of pkgin
	mkdir -p /home/$USER/Documents
	cd /home/$LOGNAME/Documents
	#backup prior export and showkeep lists if from same date, and create new one, before installing new package so changes can be tracked!
	cp -p $(date +%C%y-%m-%d)-export-$USER Previous-export-$LOGNAME
	cp -p $(date +%C%y-%m-%d)-showkeep-$USER Previous-showkeep-$LOGNAME
	echo "Format is: export-pkg-install-new (new_package)"
        echo "You are installing: "$1
        #ex for import on other system, sk for manual reference and one line package description
        pkgin in $1
        pkgin ex >      $(date +%C%y-%m-%d)-export-$USER
        pkgin sk >      $(date +%C%y-%m-%d)-showkeep-$LOGNAME
	touch Previous-export-$LOGNAME
	touch Previous-showkeep-$LOGNAME
	touch $(date +%C%y-%m-%d)-export-$USER
	touch $(date +%C%y-%m-%d)-showkeep-$USER
	cd $OLDPWD || exit

Regards,
Lubo

P.S. I have other scripts, (mostly short and simple), to automate other
tasks. For example, one to check what methods of authentication ssh
accepts (assuming it is on), another to harden by ONLY allowing key
auth. (NO passwords!), and finally one to soften, (re-enable passwords,
for example to upload a new key for the first time).



Home | Main Index | Thread Index | Old Index