pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Upgrade all installed packages





On Wed, 19 Apr 2023 at 21:58, Jason Bacon <jtocino%gmx.com@localhost> wrote:
I don't know if there's a foolproof way to determine the location of the
pkgsrc tree, but I will look into this when I get a chance.  pkg_chk
relies on $PKGSRCDIR for example, but I don't know if anything like that
is guaranteed to be defined for every installation.


[I took the OP off the Cc list, as this is mainly about general pkgsrc updating issues. Sorry if I was overzealous, nothing meant or implied -- agc]
 
I think you're looking at this the wrong way - since there is no single canonical place to put a pkgsrc tree, (indeed, I know of a number of people who have current and latest branch trees), you need to pass the pkgsrc directory to the script which updates it. The scm tools and other locations should flow from that (if building packages from source, or building binary packages to later distribute with pkgin).

Disclaimer - I took a look at auto-admin, and there are some things that I really like, and some effects that I'm less keen on (it updated the whole tree to the latest branch, for example, which, while being cool, was not what I wanted).

However, we're all different, and have different needs and ways of working (different scm, different users, different trees, binary/source packages, different prefix/localbases, pkg_chk/pkg_comp/pkg_rolling-replace  etc)

And in case anyone's wondering what I use, I derive most info from the specific pkgsrc tree, and then tag on the back of pkg_rolling-replace. I usually build everything from source:

[2023/04/19 Wed 22:32:44] agc@netbsd-012 ~ [582] > sudo freshen /usr/pkgsrc
Password:
Using cvs to update /usr/pkgsrc
Updating pkgsrc sources in /usr/pkgsrc using cvs as agc
? editors/vile/patches
M editors/vile/distinfo
U lang/qore/patches/patch-include_qore_macros.h
U math/nickle/patches/patch-configure
U math/nickle/patches/patch-main.c
U textproc/icu/patches/patch-common_unicode_ures.h
Using pkg_rolling-replace to freshen packages in /usr/pkg from /usr/pkgsrc as root
RR> Checking for mismatched installed packages using pkg_chk
RR> Excluding the following mismatched packages:
rr> EXCLUDE=[]
RR> Checking for rebuild-requested installed packages (rebuild=YES)
RR> Checking for unsafe installed packages (unsafe_depends_strict=YES)
RR> Packages to rebuild:
rr> MISMATCH_TODO=[]
rr> REBUILD_TODO=[]
rr> UNSAFE_TODO=[]
RR> No more packages to replace; done.
[2023/04/20 Thu 10:30:04] agc@netbsd-012 ~ [583] >

I've slapped a copyright notice on it, and whipped up a man page, and will add them to this mail, if anyone's interested. Probably still a WIP

(Not trying to rain on anyone's parade - the auto-admin script base is huge, well done, and very detailed. And nicely all in POSIX sh. Just not for me, sorry)

Best,
Alistair

Attachment: freshen.1
Description: Binary data

#! /bin/sh

# $NetBSD$

# Copyright (c) 2023 Alistair Crooks <agc%NetBSD.org@localhost>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

# utility function to warn and then exit
die()
{
        echo >&2 "$*"
        exit 1
}

# utility function to find an executable
check_prog()
{
        _var="$1"; _name="$2"

        eval _tmp=\"\$$_var\"
        if [ "x$_tmp" != "x" ]; then
                # Variable is already set (by the user, for example)
                return 0
        fi

        for _d in `echo $PATH | tr ':' ' '`; do
                if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then
                        # Program found
                        eval $_var=\""$_d/$_name"\"
                        return 1
                fi
        done

        die "$_name not found in path."
}

freshen_version="20230419"
user=""
scmupdate=true
pkgsrc=""
localbase=""
while getopts "Vnu:v" arg; do
	case "${arg}" in
	V)	echo "freshen version ${freshen_version}"
		exit 0
		;;
	o)	case "${OPTARG}" in
		localbase=*)	localbase="${OPTARG#localbase=}"
				;;
		owner=*)	owner="${OPTARG#owner=}"
				;;
		pkgsrc=*)	pkgsrc="${OPTARG#pkgsrc=}"
				;;
		*)		echo "Unknown option \"${OPTARG}\"" >&2
				;;
		esac
		;;
	n)	scmupdate=false ;;
	v)	set -x ;;
	\?)	printf >&2 '%s\n' \
		    "Usage: $0 [-V] [-n] [-o pkgsrc=dir] [-o owner=owner] \\" \
		    "	[-o localbase=localbase] [-o tool=toolname] [-v] [pkgsrcdir]"
		exit 2
	esac
done
shift $((OPTIND - 1))

check_prog awk awk
check_prog grep grep
check_prog id id
check_prog ls ls
check_prog make make
check_prog pkg_info pkg_info
check_prog sudo sudo

# check this script is run as root. yeah :(
case "$(${id} -u)" in
0)	;;
*)	die "Must be root to run this"
	;;
esac

# see if pkgsrc has been passed as an argument
case "${pkgsrc}" in
"")	if [ $# -eq 1 ]; then
		pkgsrc=$1
	fi
	;;
esac

# where else would it be?
case "${pkgsrc}" in
"")	pkgsrc=/usr/pkgsrc
	;;
esac

# if we need to update the sources, do it
if ${scmupdate}; then
	case "${pkgsrc}" in
	"")	die "No pkgsrc directory found"
		;;
	esac
	# now work out which scm tool we're going to use
	if [ ! -d "${pkgsrc}" -o ! -d ${pkgsrc}/pkgtools/digest ]; then
		die "\"${pkgsrc}\" is not a checked-out pkgsrc tree"
	fi
	if [ -d ${pkgsrc}/.git ]; then
		tool=git
		echo "Using git to update ${pkgsrc}"
		check_prog git git
	elif [ -d ${pkgsrc}/.hg ]; then
		tool=hg
		echo "Using hg to update ${pkgsrc}"
		check_prog hg hg
	else
		# there are some people who rename cvs directories, so just assume this for now
		tool=cvs
		echo "Using cvs to update ${pkgsrc}"
		check_prog cvs cvs
	fi
	case "${user}" in
	"")	user="$(${ls} -al ${pkgsrc}/Makefile | ${awk} '{ print $3}')"
		;;
	esac
	${grep} "^${user}:" /etc/passwd > /dev/null || die "${user} is not an active user on this system"
	case "${tool}" in
	cvs)	updatecmd="${cvs} -q update -dP ." ;;
	git)	updatecmd="${git} pull" ;;
	hg)	updatecmd="${hg} pull -u" ;;
	"")	die "unknown tool \"${tool}\" - please send patches to agc%netbsd.org@localhost"
		;;
	esac
	echo "Updating pkgsrc sources in ${pkgsrc} using ${tool} as ${user}"
	(cd ${pkgsrc} && ${sudo} -u "${user}" ${updatecmd})
else
	echo "Skipping pkgsrc update"
fi

# discover localbase
case "${localbase}" in
"")	localbase=$(cd ${pkgsrc}/pkgtools/digest && ${make} show-var VARNAME=LOCALBASE)
	;;
esac
case "${localbase}" in
"")	localbase="$(${pkg_info} -Q LOCALBASE digest)"
	;;
esac
case "${localbase}" in
"")	die "Cannot find localbase directory"
	;;
esac

# discover binary package owner
case "${owner}" in
"")	owner="$(${ls} -al ${localbase}/bin/digest | ${awk} '{print $3}')" ;;
esac
case "${owner}" in
"")	die "Cannot work out binary packagee owner"
	;;
esac

echo "Using pkg_rolling-replace to freshen packages in ${localbase} from ${pkgsrc} as ${owner}"
(cd ${pkgsrc} && ${sudo} -u "${owner}" pkg_rolling-replace -rsuv)


Home | Main Index | Thread Index | Old Index