Path: blob/main/Tools/scripts/BDB-upgrade-helper.sh
16462 views
#!/bin/sh1# $Id$2# ports/Tools/scripts/BDB-upgrade-helper.sh3#4# A helper script to upgrade applications that used to depend on5# BerkeleyDB ports 4.0...4.7 to use a newer version of BerkeleyDB.6#7# Written by Matthias Andree in 2014, and placed under the same8# license as FreeBSD itself, see /COPYRIGHT or /usr/src/COPYRIGHT.910set -eu11: ${PREFIX:=/usr/local}12: ${LOCALBASE:=${PREFIX}}1314# check requisites15tool=16if [ -x ${LOCALBASE}/sbin/portmaster ] ; then tool=portmaster ;17elif [ -x ${LOCALBASE}/sbin/portupgrade ]; then tool=portupgrade;18else19echo >&2 "Neither portmaster nor portupgrade installed. Cannot continue."20echo >&2 "Please install ports-mgmt/portmaster before proceeding."21exit 122fi2324# check BerkeleyDB 4.0...4.7 versions25rx='db4[1-7]?(-nocrypto)?-4'26if pkg -N 2>/dev/null ; then pkg=yes ; else pkg= ; fi27if [ -n "$pkg" ] ; then28# pkg29dbnames=$(pkg info -x "$rx")30else31# old pkg_*32dbnames=$(pkg_info -E -X "$rx")33fi3435# due to set -e, the script will not reach this point36# unless there have been matched packages - without packages,37# pkg_info or pkg will exit with failure.3839# check if we need to pass in origins or package names40if [ "$tool" = portupgrade ] ; then41if [ -n "$pkg" ] ; then42dbnames=$(printf '%s\n' "$dbnames" | xargs -n1 pkg info -q -o)43else44dbnames=$(printf '%s\n' "$dbnames" | xargs -n1 pkg_info -q -o)45fi46fi4748# generate the upgrade command49case "$tool" in50portmaster)51cmd="portmaster -R"52for i in $dbnames ; do cmd="$cmd -r $i" ; done53;;54portupgrade)55cmd="portupgrade -f -r"56for i in $dbnames ; do cmd="$cmd -x $i" ; done57for i in $dbnames ; do cmd="$cmd $i" ; done58;;59*)60echo >&2 "Internal error in $0." ; exit 161;;62esac6364echo "+ $cmd"65$cmd6667# due to set -e, the script will not reach this point68# if there was an error or failure with the upgrade tool6970if [ -n "$pkg" ] ; then71pkg delete $dbnames72else73pkg_delete $dbnames74fi7576echo "Success."777879