Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/Tools/scripts/BDB-upgrade-helper.sh
18157 views
1
#!/bin/sh
2
# $Id$
3
# ports/Tools/scripts/BDB-upgrade-helper.sh
4
#
5
# A helper script to upgrade applications that used to depend on
6
# BerkeleyDB ports 4.0...4.7 to use a newer version of BerkeleyDB.
7
#
8
# Written by Matthias Andree in 2014, and placed under the same
9
# license as FreeBSD itself, see /COPYRIGHT or /usr/src/COPYRIGHT.
10
11
set -eu
12
: ${PREFIX:=/usr/local}
13
: ${LOCALBASE:=${PREFIX}}
14
15
# check requisites
16
tool=
17
if [ -x ${LOCALBASE}/sbin/portmaster ] ; then tool=portmaster ;
18
elif [ -x ${LOCALBASE}/sbin/portupgrade ]; then tool=portupgrade;
19
else
20
echo >&2 "Neither portmaster nor portupgrade installed. Cannot continue."
21
echo >&2 "Please install ports-mgmt/portmaster before proceeding."
22
exit 1
23
fi
24
25
# check BerkeleyDB 4.0...4.7 versions
26
rx='db4[1-7]?(-nocrypto)?-4'
27
if pkg -N 2>/dev/null ; then pkg=yes ; else pkg= ; fi
28
if [ -n "$pkg" ] ; then
29
# pkg
30
dbnames=$(pkg info -x "$rx")
31
else
32
# old pkg_*
33
dbnames=$(pkg_info -E -X "$rx")
34
fi
35
36
# due to set -e, the script will not reach this point
37
# unless there have been matched packages - without packages,
38
# pkg_info or pkg will exit with failure.
39
40
# check if we need to pass in origins or package names
41
if [ "$tool" = portupgrade ] ; then
42
if [ -n "$pkg" ] ; then
43
dbnames=$(printf '%s\n' "$dbnames" | xargs -n1 pkg info -q -o)
44
else
45
dbnames=$(printf '%s\n' "$dbnames" | xargs -n1 pkg_info -q -o)
46
fi
47
fi
48
49
# generate the upgrade command
50
case "$tool" in
51
portmaster)
52
cmd="portmaster -R"
53
for i in $dbnames ; do cmd="$cmd -r $i" ; done
54
;;
55
portupgrade)
56
cmd="portupgrade -f -r"
57
for i in $dbnames ; do cmd="$cmd -x $i" ; done
58
for i in $dbnames ; do cmd="$cmd $i" ; done
59
;;
60
*)
61
echo >&2 "Internal error in $0." ; exit 1
62
;;
63
esac
64
65
echo "+ $cmd"
66
$cmd
67
68
# due to set -e, the script will not reach this point
69
# if there was an error or failure with the upgrade tool
70
71
if [ -n "$pkg" ] ; then
72
pkg delete $dbnames
73
else
74
pkg_delete $dbnames
75
fi
76
77
echo "Success."
78
79