Skip to content

Instantly share code, notes, and snippets.

@grahamperrin
Created March 9, 2026 07:07
Show Gist options
  • Select an option

  • Save grahamperrin/4cd3e0872721b323a61b3bd1cff0fb15 to your computer and use it in GitHub Desktop.

Select an option

Save grahamperrin/4cd3e0872721b323a61b3bd1cff0fb15 to your computer and use it in GitHub Desktop.
pkgsave_cleanup script from Roger Marquis
#!/bin/sh -
## pkgsave_cleanup
# Archive .pkgsave files created in multiple locations by messy upgrade apps,
# preserving the original path and deleting unchanged files.
## to do:
# Check-in as appropriate.
# See also: etcupdate, zfs snapshot, beadm, ...
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
set -a
DBPATH=/var/db/pkgsave/`date +%G%m%d%H%M`
SEARCHROOT=/
usage () {
echo " USAGE: `basename $0` [search_root]"
exit
}
if [ $# -gt 0 ]; then
if [ $# -gt 1 ] || [ $1 = -h ]; then
usage
elif [ ! -d $1 ]; then
echo " ERROR: directory $1 not found"
usage
else
SEARCHROOT=$1
fi
fi
for f in `find ${SEARCHROOT}/ -type f -name \*.pkgsave | grep -v $DBPATH` ; do
fori="`echo $f | sed 's/.pkgsave//'`"
diff $f $fori >/dev/null 2>&1
if [ $? = 0 ]; then
rm -f $f
else
oripath="`dirname $f`"
if [ ! -d $DBPATH/$oripath ]; then
mkdir -p $DBPATH/$oripath || exit 1
fi
mv -f $f $DBPATH/$oripath || exit 1
fi
done
if [ -d $DBPATH ]; then
echo
echo " Cleaned up: "
ls -lt `find $DBPATH/ -type f` | sed 's/^/ /'
echo
fi
@grahamperrin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment