Last active
October 7, 2015 03:38
-
-
Save bdrewery/3099160 to your computer and use it in GitHub Desktop.
FreeBSD pkgng Upgrade with shared library saving (Similar to `portmaster -w` and `portupgrade`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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