Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FreeBSD pkgng Upgrade with shared library saving (Similar to `portmaster -w` and `portupgrade`)
#! /bin/sh
COMPAT_DIR=/usr/local/lib/compat/pkg
if ! [ -d ${COMPAT_DIR} ]; then
mkdir -p ${COMPAT_DIR}
fi
pkg update
# Get a list of origins to be upgraded
installed_packages=$(pkg query '%o %v')
packages_to_upgrade=$({ echo "${installed_packages}"; pkg rquery '%o %v' ${installed_packages}; } | sort | uniq -u | awk '{print $1}' | uniq)
if [ -z "${packages_to_upgrade}" ]; then
echo "Nothing to update"
exit 0
fi
# Backup files of packages to be upgraded, that are in use
{ ldconfig -r | sed -e 's#.* ##' -e '1,2d' | grep -v ^${COMPAT_DIR}; pkg query '%Fp' ${packages_to_upgrade}; } | sort | uniq -d | while read file
do
cp -pf ${file} ${COMPAT_DIR}/
done
/usr/sbin/service ldconfig start > /dev/null 2>&1
# Perform upgrade
pkg upgrade -U
# Cleanup duplicated libs
pkg query '%Fp' ${packages_to_upgrade} | while read file
do
compat_file=${COMPAT_DIR}/${file##*/}
if [ -f ${compat_file} ]; then
echo "Removing duplicated shared library: ${compat_file}"
rm -f ${compat_file}
fi
done
/usr/sbin/service ldconfig start > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment