Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Oct 1998 15:08:29 +1000
From:      "John Saunders" <john.saunders@scitec.com.au>
To:        "FreeBSD current" <freebsd-current@FreeBSD.ORG>
Subject:   Package upgrade check program
Message-ID:  <001b01bdfd7a$021fd540$6cb611cb@saruman.scitec.com.au>

next in thread | raw e-mail | index | archive | help
With everybody hot into upgrading to 3.0, I thought I would
throw this script in that I have been working on the last
couple of days (bit at a time). This script suggests upgrades
to installed packages. I'm continuing to work on a version
that will do the upgrade for you (after prompting of course).

Enjoy...

#!/bin/sh
# pkg_check:
#
# Scan the installed packages and suggest upgrades or alternative
# packages to install.
#

# Change directory to the package database directory.
if cd /var/db/pkg 2>/dev/null; then
else
	echo "Cannot find package database directory /var/db/pkg"
	exit 1
fi

# Scan through all the installed packages.
for pkg in *; do
	# Try to determine the name of the package without the version
	# number postfix. Commented out line uses lazy checking.
	base=`echo $pkg | sed -e '1,$ s/\([a-zA-Z_]-\)[0-9].*$/\1/'`
	#base=`echo $pkg | sed -e '1,$ s/\([a-zA-Z_]\)-[0-9].*$/\1/'`

	# Get a list of ports matching the package base name.
	new=`grep "^$base" /usr/ports/INDEX | sed -e '1,$ s/|.*$//'`

	# Upgrade is yes when installed package doesn't match any in ports.
	upgrade="yes"

	# Alternatives is yes when one of the ports matches the installed
	# package, but multiple ports are available.
	alternatives="no"

	# Simple case no upgrade needed.
	if [ "$pkg" = "$new" ]; then
		upgrade="no"
	else
		# Scan the multiple available ports.
		for i in $new; do
			if [ "$pkg" = "$i" ]; then
				upgrade="no"
			else
				alternatives="yes"
			fi
		done
	fi

	# Dump the information.
	if [ "$upgrade" = "yes" ]; then
		echo "Upgrade package  $pkg to one of..."
		for i in $new; do
			echo "                 $i"
		done
	elif [ "$alternatives" = "yes" ]; then
		echo "Alternatives for $pkg exist..."
		for i in $new; do
			if [ "$pkg" = "$i" ]; then
				echo "                 $i (installed)"
			else
				echo "                 $i"
			fi
		done
	fi
done
exit 0

--   .   +-------------------------------------------------------+
 ,--_|\  | John Saunders    mailto:John.Saunders@scitec.com.au   |
/  Oz  \ | SCITEC LIMITED   Phone +61294289563  Fax +61294289933 |
\_,--\_/ | "By the time you make ends meet, they move the ends." |
      v  +-------------------------------------------------------+


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001b01bdfd7a$021fd540$6cb611cb>