Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #129 from xzhavilla/master
Baptiste Daroussin committed 14 years ago
commit 443ad5c4e05134dcf92e442b44bf915db16fbadd
parent cd8dd1f
1 file changed +295 -122
modified ports/portmaster.patch
@@ -1,29 +1,29 @@
-
--- /usr/local/sbin/portmaster	2011-12-11 21:50:47.000000000 +0100
-
+++ ~/pkgng/portmaster	2011-12-12 12:23:56.000000000 +0100
-
@@ -286,7 +286,13 @@
+
--- portmaster.orig	2012-01-31 03:17:17.681285114 +0100
+
+++ portmaster	2012-01-31 04:36:56.231159190 +0100
+
@@ -292,7 +292,13 @@
 			 unset -v PM_URB_LIST;
 			 $PM_SU_CMD /usr/bin/nice /usr/bin/make $PM_MAKE_ARGS $*; ); }
 pm_mkdir_s        () { $PM_SU_CMD /bin/mkdir -p $1; }
-pm_pkg_delete_s   () { $PM_SU_CMD /usr/sbin/pkg_delete $*; }
+pm_pkg_delete_s   () { 
-
+	if [ -z "${use_pkgng}" ]; then
+
+	if [ -z "$use_pkgng" ]; then
+		$PM_SU_CMD /usr/sbin/pkg_delete $*;
+	else
-
+		$PM_SU_CMD /usr/sbin/pkg delete -y $*;
+
+		$PM_SU_CMD /usr/local/sbin/pkg delete -y $*;
+	fi
+}
 pm_rm_s           () { $PM_SU_CMD /bin/rm $*; }
 pm_rmdir_s        () { $PM_SU_CMD /bin/rmdir $*; }
 pm_unlink_s       () { [ -e "$1" ] && $PM_SU_CMD /bin/unlink $1; }
-
@@ -490,12 +496,16 @@
+
@@ -496,12 +502,16 @@
 
 	pattern=`globstrip $1`
 
-	glob_dirs=`find $pdb -maxdepth 1 -type d -name ${pattern}\*`
-
+	if [ -z "${use_pkgng}" ]; then
+
+	if [ -z "$use_pkgng" ]; then
+		glob_dirs=`find $pdb -maxdepth 1 -type d -name ${pattern}\*`
+	else
-
+		glob_dirs=`pkg info -qg ${pattern}\*`
+
+		glob_dirs=`pkg query -g "%n-%v" ${pattern}\*`
+	fi
 	case "$glob_dirs" in
 	# Match a newline in multiple responses from find
@@ -34,20 +34,22 @@
 	esac
 
 	unset glob_dirs
-
@@ -505,8 +515,12 @@
+
@@ -511,8 +521,12 @@
 origin_from_pdb () {
 	local o
 
-
+	if [ -z "${use_pkgng}" ]; then
-
 	o=`grep -m1 '@comment ORIGIN:' $pdb/$1/+CONTENTS 2>/dev/null` && {
-
 		echo ${o#@comment ORIGIN:}; return 0; }
+
-	o=`grep -m1 '@comment ORIGIN:' $pdb/$1/+CONTENTS 2>/dev/null` && {
+
-		echo ${o#@comment ORIGIN:}; return 0; }
+
+	if [ -z "$use_pkgng" ]; then
+
+		o=`grep -m1 '@comment ORIGIN:' $pdb/$1/+CONTENTS 2>/dev/null` && {
+
+			echo ${o#@comment ORIGIN:}; return 0; }
+	else
-
+		pkg info -qo $1; return 0;
+
+		pkg query "%o" $1; return 0;
+	fi
 
 	case "$1" in bsdpan-*) return 3 ;; esac
 
-
@@ -660,6 +674,7 @@
+
@@ -666,6 +680,7 @@
 	o)	REPLACE_ORIGIN=oopt ;;
 	p)	fail 'The -p option has been deprecated' ;;
 	r)	PM_URB=ropt
@@ -55,12 +57,12 @@
 		if [ -d "$pdb/$OPTARG" ]; then
 			glob_dirs=$OPTARG
 		else
-
@@ -812,7 +827,12 @@
+
@@ -818,7 +833,12 @@
 		fi
 		unset INDEXFILE INDEXDIR
 
-		PM_INDEX_PORTS=`pkg_version -Ivl\< $PM_INDEX | cut -f1 -d\<`
-
+		if [ -z "${use_pkgng}" ]; then
+
+		if [ -z "$use_pkgng" ]; then
+			pkg_version="pkg_version"
+		else
+			pkg_version="pkg version"
@@ -69,26 +71,26 @@
 		export PM_INDEX_PORTS
 
 		if [ -z "$pd" -o "$pd" != /usr/ports ]; then
-
@@ -869,6 +889,10 @@
+
@@ -875,6 +895,10 @@
 iport_from_origin () {
 	local sn dir
 
-
+	if [ -n "${use_pkgng}" ]; then
+
+	if [ -n "$use_pkgng" ]; then
+		pkg info -q ${1} || return 1
+		return
+	fi
 	sn=${1#*/} ; sn=${sn%-*} ; sn=${sn%%[0-9]*}
 
 	if ! dir=`grep -l "@comment ORIGIN:${1}$" $pdb/${sn}*/+CONTENTS 2>/dev/null`; then
-
@@ -897,6 +921,7 @@
+
@@ -903,6 +927,7 @@
 	done
 }
 
-
+#userless with pkgng
+
+# useless with pkgng
 check_dependency_files () {
 	# Global: grep_deps
 	local origin iport ro_opd
-
@@ -979,6 +1004,7 @@
+
@@ -985,6 +1010,7 @@
 	fi
 }
 
@@ -96,7 +98,7 @@
 update_contents () {
 	local IFS delete contents origin n_port old_origin iport new_cont
 	local o_seen line d_missing d_origin d_iport prev_line answer
-
@@ -1123,35 +1149,62 @@
+
@@ -1129,35 +1155,62 @@
 	echo '############' > $DI_FILES		# Make the file > 0 bytes
 	echo "===>>> Gathering distinfo list for installed ports"
 	echo ''
@@ -121,9 +123,17 @@
+				[ -n "$moved_npd" ] || continue
+				origin=$moved_npd
+			fi
-
+
+
 
+
-		origin="${pd}/${origin}"
+			origin="${pd}/${origin}"
-
+
+
 
+
-		if [ -s "${origin}/distinfo" ]; then
+
-			distinfo="${origin}/distinfo"
+
-		else
+
-			pm_cd $origin || continue
+
-			distinfo=`pm_make -V DISTINFO_FILE`
+
-			[ -n "$distinfo" ] || fail "No DISTINFO_FILE in $origin"
+
-		fi
+			if [ -s "${origin}/distinfo" ]; then
+				distinfo="${origin}/distinfo"
+			else
@@ -131,7 +141,14 @@
+				distinfo=`pm_make -V DISTINFO_FILE`
+				[ -n "$distinfo" ] || fail "No DISTINFO_FILE in $origin"
+			fi
-
+
+
 
+
-		if [ -s "$distinfo" ]; then
+
-			grep '^SHA256 ' $distinfo | while read disc1 f disc2; do
+
-				f=${f#(} ; f=${f%)}
+
-				echo $f >> $DI_FILES
+
-			done
+
-		fi
+
-	done
+			if [ -s "$distinfo" ]; then
+				grep '^SHA256 ' $distinfo | while read disc1 f disc2; do
+					f=${f#(} ; f=${f%)}
@@ -146,16 +163,9 @@
+				[ -n "$moved_npd" ] || continue
+				origin=$moved_npd
+			fi
-
 
-
 		origin="${pd}/${origin}"
-
 
-
-		if [ -s "${origin}/distinfo" ]; then
-
-			distinfo="${origin}/distinfo"
-
-		else
-
-			pm_cd $origin || continue
-
-			distinfo=`pm_make -V DISTINFO_FILE`
-
-			[ -n "$distinfo" ] || fail "No DISTINFO_FILE in $origin"
-
-		fi
+
+
+
+			origin="${pd}/${origin}"
+
+
+			if [ -s "${origin}/distinfo" ]; then
+				distinfo="${origin}/distinfo"
+			else
@@ -163,14 +173,7 @@
+				distinfo=`pm_make -V DISTINFO_FILE`
+				[ -n "$distinfo" ] || fail "No DISTINFO_FILE in $origin"
+			fi
-
 
-
-		if [ -s "$distinfo" ]; then
-
-			grep '^SHA256 ' $distinfo | while read disc1 f disc2; do
-
-				f=${f#(} ; f=${f%)}
-
-				echo $f >> $DI_FILES
-
-			done
-
-		fi
-
-	done
+
+
+			if [ -s "$distinfo" ]; then
+				grep '^SHA256 ' $distinfo | while read disc1 f disc2; do
+					f=${f#(} ; f=${f%)}
@@ -182,40 +185,74 @@
 
 	# Tell safe_exit that we are done
 	pm_unlink ${DI_FILES}-e
-
@@ -1200,6 +1253,24 @@
-
 	local pkg
+
@@ -1203,25 +1256,45 @@
+
 }
+
 
+
 ports_by_category () {
+
-	local pkg
+
+	local pkg dep rdep
 	pm_v "===>>> Sorting ports by category"
 
-
+	if [ -n "${use_pkgng}" ]; then
-
+		pkg query -a "%n-%v %?d %?r" | while read pkg dep rdep; do
-
+			if [ $rdep -eq 0 ]; then
-
+				if [ $dep -eq 0 ]; then
-
+					branches="$branches ${pkg}"
+
-	for pkg in $pdb/*; do
+
-		if [ -s "$pkg/+REQUIRED_BY" ]; then
+
-			if grep -ql '^@pkgdep ' $pkg/+CONTENTS 2>/dev/null; then
+
-				branches="$branches ${pkg#$pdb/}"
+
+	if [ -z "$use_pkgng" ]; then
+
+		for pkg in $pdb/*; do
+
+			if [ -s "$pkg/+REQUIRED_BY" ]; then
+
+				if grep -ql '^@pkgdep ' $pkg/+CONTENTS 2>/dev/null; then
+
+					branches="$branches ${pkg#$pdb/}"
+				else
-
+					trunks="$trunks ${pkg}"
+
+					trunks="$trunks ${pkg#$pdb/}"
+				fi
-
+			else
-
+				if [ $dep -eq 0 ]; then
-
+					leaves="$leaves ${pkg}"
+
 			else
+
-				trunks="$trunks ${pkg#$pdb/}"
+
+				if grep -ql '^@pkgdep ' $pkg/+CONTENTS 2>/dev/null; then
+
+					leaves="$leaves ${pkg#$pdb/}"
+				else
-
+					roots="$roots ${pkg}"
+
+					[ -d "$pkg" ] || continue
+
+					roots="$roots ${pkg#$pdb/}"
+				fi
-
+			fi
+
 			fi
+
-		else
+
-			if grep -ql '^@pkgdep ' $pkg/+CONTENTS 2>/dev/null; then
+
-				leaves="$leaves ${pkg#$pdb/}"
+		done
-
+		return
+
+	else
+
+		while read pkg dep rdep; do
+
+			if [ $rdep -eq 1 ]; then
+
+				if [ $dep -eq 1 ]; then
+
+					branches="$branches $pkg"
+
+				else
+
+					trunks="$trunks $pkg"
+
+				fi
+
 			else
+
-				[ -d "$pkg" ] || continue
+
-				roots="$roots ${pkg#$pdb/}"
+
+				if [ $dep -eq 1 ]; then
+
+					leaves="$leaves $pkg"
+
+				else
+
+					roots="$roots $pkg"
+
+				fi
+
 			fi
+
-		fi
+
-	done
+
+		done << EOF
+
+`pkg query -a "%n-%v %?d %?r"`
+
+EOF
+	fi
-
 	for pkg in $pdb/*; do
-
 		if [ -s "$pkg/+REQUIRED_BY" ]; then
-
 			if grep -ql '^@pkgdep ' $pkg/+CONTENTS 2>/dev/null; then
-
@@ -1266,6 +1337,7 @@
+
 }
+
 
+
 delete_empty_dist_subdirs () {
+
@@ -1272,6 +1345,7 @@
 update_required_by () {
 	# Global: grep_deps
 	local do_update
-
+	[ -n "${use_pkgng}" ] && /bin/unlink $grep_deps && unset grep_deps
+
+	[ -n "$use_pkgng" ] && /bin/unlink $grep_deps && unset grep_deps
 
 	if [ -e "$pdb/$1/+REQUIRED_BY" ]; then
 		sort $pdb/$1/+REQUIRED_BY | cmp -s $grep_deps - || do_update=do_update
-
@@ -1317,12 +1389,19 @@
+
@@ -1323,12 +1397,19 @@
 	init_packages_var
 
 	echo "===>>> Checking for stale packages"
@@ -229,17 +266,17 @@
-		origin=`tar -O -zxvf $package '+CONTENTS' 2>/dev/null | grep '@comment ORIGIN:'` ||
-			fail Empty origin in $package
-		origin=${origin#@comment ORIGIN:}
-
+		if [ -n "$use_pkgng" ]; then
-
+			origin=`pkg query -f $package "%o"` || fail Empty origin in $package
-
+		else
+
+		if [ -z "$use_pkgng" ]; then
+			origin=`tar -O -zxvf $package '+CONTENTS' 2>/dev/null | grep '@comment ORIGIN:'` ||
+				fail Empty origin in $package
+			origin=${origin#@comment ORIGIN:}
+
+		else
+
+			origin=`pkg query "%o" $package` || fail Empty origin in $package
+		fi
 
 		if [ -z "$PM_INDEX" ]; then
 			if [ -d "$pd/$origin" ]; then
-
@@ -1338,8 +1417,21 @@
+
@@ -1344,8 +1425,21 @@
 		fi
 
 		if [ -n "$port_ver" ]; then
@@ -256,13 +293,13 @@
+								pm_unlink_s $package ;;
+						esac
+					fi
-
+				unset port_ver
-
+				continue
+
+					unset port_ver
+
+					continue
+				fi
 				if [ ! -d "${pdb}/${pkg_dir}" ]; then
 					echo "	===>>> $pkg_dir is not installed"
 					echo "	===>>> Path: ${package}"
-
@@ -1400,6 +1492,7 @@
+
@@ -1406,6 +1500,7 @@
 fi	# [ -n "$CLEAN_PACKAGES" ]
 
 if [ -n "$CHECK_DEPENDS" ]; then
@@ -270,7 +307,7 @@
 	PM_VERBOSE=pmv_check_depends
 IFS='
 '
-
@@ -1440,6 +1533,7 @@
+
@@ -1446,6 +1541,7 @@
 fi
 
 if [ -n "$CHECK_PORT_DBDIR" ]; then
@@ -278,12 +315,12 @@
 	[ -d "$port_dbdir" ] ||
 		fail 'PORT_DBIR is empty, or the directory $port_dbdir does not exist'
 
-
@@ -1604,14 +1698,19 @@
+
@@ -1610,14 +1706,19 @@
 				unset port_ver
 			fi
 		else
-			case `pkg_version -t $iport $port_ver` in
-
+			if [ -z "${use_pkgng}" ]; then
+
+			if [ -z "$use_pkgng" ]; then
+				pkg_version="pkg_version"
+			else
+				pkg_version="pkg version"
@@ -300,13 +337,13 @@
 			esac
 
 			[ -z "$do_update" ] && {
-
@@ -1683,7 +1782,13 @@
+
@@ -1689,7 +1790,13 @@
 	fi
 
 	pm_cd $pkgdir || fail "Cannot cd into $pkgdir to create a package"
-	if $PM_SU_CMD pkg_create -b $2; then
+	local pkg_create
-
+	if [ -z "${use_pkgng}" ]; then
+
+	if [ -z "$use_pkgng" ]; then
+		pkg_create="pkg_create -b"
+	else
+		pkg_create="pkg create "
@@ -315,62 +352,143 @@
 		if [ "$1" = "$pbu" ]; then
 			if [ -n "$BACKUP" ]; then
 				echo "	===>>> Package saved to $1" ; echo ''
-
@@ -2034,7 +2139,11 @@
+
@@ -2028,19 +2135,28 @@
+
 fi
+
 
+
 if [ -n "$EXPUNGE" ]; then
+
-	if [ ! -d "$pdb/$EXPUNGE" ]; then
+
-		find_glob_dirs $EXPUNGE
+
-		case $? in
+
-		1)	fail "No such directory/port: $pdb/$EXPUNGE" ;;
+
-		2)	echo "===>>> $EXPUNGE matched multiple ports"
+
-			fail "The -e option works with only one port at a time" ;;
+
-		0)	EXPUNGE=${glob_dirs#$pdb/}
+
-			unset glob_dirs ;;
+
-		esac
+
+	if [ -z "$use_pkgng" ]; then
+
+		if [ ! -d "$pdb/$EXPUNGE" ]; then
+
+			find_glob_dirs $EXPUNGE
+
+			case $? in
+
+			1)	fail "No such directory/port: $pdb/$EXPUNGE" ;;
+
+			2)	echo "===>>> $EXPUNGE matched multiple ports"
+
+				fail "The -e option works with only one port at a time" ;;
+
+			0)	EXPUNGE=${glob_dirs#$pdb/}
+
+				unset glob_dirs ;;
+
+			esac
+
+		fi
+
+	else
+
+		pkg info -e $EXPUNGE || fail "No such port: $EXPUNGE"
+
+		EXPUNGE=`pkg query "%n-%v" $EXPUNGE`
 	fi
 
 	origin=`origin_from_pdb $EXPUNGE`
-	deplist=`grep -l DEPORIGIN:$origin$ $pdb/*/+CONTENTS`
-
+	if [ -n "${use_pkgng}" ]; then
-
+		deplist=`pkg query "%rn-%rv" $origin`
-
+	else
+
+	if [ -z "$use_pkgng" ]; then
+		deplist=`grep -l DEPORIGIN:$origin$ $pdb/*/+CONTENTS`
+
+	else
+
+		deplist=`pkg query "%rn-%rv" $origin`
+	fi
 	if [ -n "$deplist" ]; then
 		echo "===>>> Warning: Ports with dependencies on ${EXPUNGE}:"
 		for dep in $deplist; do
-
@@ -2042,7 +2151,9 @@
+
@@ -2048,7 +2164,8 @@
 		done
 		get_answer_yn n "\n\t===>>> Delete this dependency data"
 		case "$?" in
-		0)	for f in $deplist; do
-
+		0)	
-
+			[ -n "$use_pkgng" ] && exit 0
+
+		0)	[ -n "$use_pkgng" ] && exit 0
+			for f in $deplist; do
 				update_contents delete $f $origin
 			done ;;
 		*)	exit 1 ;;
-
@@ -2069,7 +2180,11 @@
+
@@ -2058,8 +2175,13 @@
+
 	[ -n "$BACKUP" ] && { init_packages ; pm_pkg_create $pbu $EXPUNGE; }
+
 	[ -z "$DONT_SCRUB_DISTFILES" ] && { delete_all_distfiles $origin; delete_dist_list; }
+
 
+
-	echo "===>>> Running pkg_delete -f $EXPUNGE"
+
-	pm_pkg_delete_s -f $EXPUNGE || fail 'pkg_delete failed'
+
+	if [ -z "$use_pkgng" ]; then
+
+		pkg_delete="pkg_delete"
+
+	else
+
+		pkg_delete="pkg delete"
+
+	fi
+
+	echo "===>>> Running $pkg_delete -f $EXPUNGE"
+
+	pm_pkg_delete_s -f $EXPUNGE || fail "$pkg_delete failed"
+
 
+
 	echo '' ; echo "===>>> Running ${0##*/} -s $ARGS"
+
 	exec $0 -s $ARGS
+
@@ -2069,13 +2191,22 @@
+
 if [ -n "$CLEAN_STALE" ]; then
+
 	[ -z "$no_del_list" ] && export no_del_list=':'
+
 
+
-	for file in `find $pdb -type f -name \+REQUIRED_BY -empty` ; do
+
+	#TODO: will use pkg autoremove when it works
+
+	if [ -z "$use_pkgng" ]; then
+
+		find_stale_ports="find $pdb -type f -name \+REQUIRED_BY -empty"
+
+	else
+
+		find_stale_ports="pkg query -a \"%?r %n-%v\" | awk '/^0/ { print \$2 }'"
+
+	fi
+
+	for file in `eval $find_stale_ports` ; do
+
 		iport="${file%/+REQUIRED_BY}" ; iport=${iport#$pdb/}
+
 
 		case "$no_del_list" in *:${iport}:*) continue ;; esac
 
 		origin=`origin_from_pdb $iport`
-		deplist=`grep -l DEPORIGIN:$origin$ $pdb/*/+CONTENTS`
-
+		if [ -n "${use_pkgng}" ]; then
-
+			deplist=`pkg query "%rn-%rv" $origin`
-
+		else
+
+		deplist=""
+
+		if [ -z "$use_pkgng" ]; then
+			deplist=`grep -l DEPORIGIN:$origin$ $pdb/*/+CONTENTS`
+		fi
 		if [ -n "$deplist" ]; then
 			echo ''
 			echo "===>>> Warning: Unrecorded dependencies on ${iport}:"
-
@@ -2082,7 +2197,11 @@
+
@@ -2088,22 +2219,32 @@
 			continue
 		fi
 
-		pkg_info $iport
+		if [ -z "$use_pkgng" ]; then
+			pkg_info $iport
+
+			pkg_delete="pkg_delete"
+		else
-
+			pkg info $iport
+
+			pkg info -f $iport
+
+			pkg_delete="pkg delete"
+		fi
 
 		get_answer_yn n "\t===>>> ${iport} is no longer depended on, delete"
 		case "$?" in
-
@@ -2237,7 +2356,12 @@
+
 		0)	[ -n "$BACKUP" ] && { init_packages ; pm_pkg_create $pbu $iport; }
+
 			[ -z "$DONT_SCRUB_DISTFILES" ] && { delete_all_distfiles $origin; delete_dist_list; }
+
 
+
-			echo "===>>> Running pkg_delete -f $iport"
+
-			pm_pkg_delete_s -f $iport || fail 'pkg_delete failed'
+
+			echo "===>>> Running $pkg_delete -f $iport"
+
+			pm_pkg_delete_s -f $iport || fail "$pkg_delete failed"
+
 
+
 			exec $0 -s $ARGS ;;
+
-		*)	get_answer_yn n "\t===>>> Delete this dependency data"
+
-			case "$?" in
+
-			0)	pm_unlink_s $file ;;
+
-			*)	no_del_list="${no_del_list}${iport}:" ;;
+
-			esac ;;
+
+		*)	if [ -z "$use_pkgng" ]; then
+
+				get_answer_yn n "\t===>>> Delete this dependency data"
+
+				case "$?" in
+
+				0)	pm_unlink_s $file ;;
+
+				*)	no_del_list="${no_del_list}${iport}:" ;;
+
+				esac
+
+			else
+
+				no_del_list="${no_del_list}${iport}:"
+
+			fi ;;
+
 		esac
+
 	done
+
 	exit 0
+
@@ -2243,7 +2384,12 @@
 			fail "No entry for $origin in $PM_INDEX"
 	fi
 
-	case `pkg_version -t $iport $new_port 2>/dev/null` in
-
+	if [ -z "${use_pkgng}" ]; then
+
+	if [ -z "$use_pkgng" ]; then
+		pkg_version="pkg_version"
+	else
+		pkg_version="pkg version"
@@ -379,37 +497,37 @@
 	\<)	build_l="${build_l}\tUpgrade $iport to $new_port\n" ;;
 	=)	build_l="${build_l}\tRe-install $iport\n" ;;
 	\>)	build_l="${build_l}\tDowngrade $iport to $new_port\n" ;;
-
@@ -2452,7 +2576,11 @@
+
@@ -2466,7 +2612,11 @@
 				fail "Cannot cd to $d_port"
 			fi
 			for glob in $conflicts; do
-				confl_p=`pkg_info -I $glob 2>/dev/null`
-
+				if [ -z "${use_pkgng}" ]; then
+
+				if [ -z "$use_pkgng" ]; then
+					confl_p=`pkg_info -I $glob 2>/dev/null`
+				else
-
+					confl_p=`pkg info -qg $glob 2>/dev/null` 
+
+					confl_p=`pkg query -g "%n-%v" $glob 2>/dev/null`
+				fi
 				if [ -n "$confl_p" ]; then
 					confl_p=${confl_p%% *}
 					echo ''
-
@@ -2585,6 +2713,10 @@
+
@@ -2601,6 +2751,10 @@
 		done
 
 		for dep in $build_only_dl_g; do
-
+			if [ -n "${use_pkgng}" ]; then
-
+				[ `pkg query "%?r"` = "0" ] || temp_bodlg="$temp_bodlg $dep"
+
+			if [ -n "$use_pkgng" ]; then
+
+				[ "`pkg query "%?r" $dep`" = "0" ] || temp_bodlg="$temp_bodlg $dep"
+				continue
+			fi
 			grep -q "@comment DEPORIGIN:${dep#$pd/}$" $pdb/*/+CONTENTS ||
 				temp_bodlg="$temp_bodlg $dep"
 		done
-
@@ -2619,7 +2751,14 @@
+
@@ -2635,7 +2789,14 @@
 	echo "===>>> Begin $verb ports that depend on $PM_URB_IPORTS"
 	echo ''
 
+	#TODO
 	for origin in $PM_URB_ORIGINS; do
-
+		if [ -n "${use_pkgng}" ]; then
+
+		if [ -n "$use_pkgng" ]; then
+			for req_by in `pkg query "%rn-%rv" ${origin}`; do
+				PM_URB_LIST="${PM_URB_LIST} ${req_by}"
+			done
@@ -418,48 +536,47 @@
 		for req_by in `grep -l DEPORIGIN:${origin}$ $pdb/*/+CONTENTS`; do
 			req_by="${req_by%/+CONTENTS}"
 			req_by="${req_by##*/}"
-
@@ -2785,9 +2924,17 @@
+
@@ -2806,9 +2967,16 @@
 		*/*)	origin=$port ;;
 		*)	# If an installed version does not exist at this
 			# point it probably got updated as a dependency
-			if [ ! -d "$pdb/$port" ]; then
-				numports=$(( $numports - 1 ))
-				continue
-
+			if [ -n "$use_pkgng" ]; then
-
+				if ! pkg info -e $port; then
+
+			if [ -z "$use_pkgng" ]; then
+
+				if [ ! -d "$pdb/$port" ]; then
+					numports=$(( $numports - 1 ))
+					continue
+				fi
+			else
-
+
-
+				if [ ! -d "$pdb/$port" ]; then
+
+				if ! pkg info -e $port; then
+					numports=$(( $numports - 1 ))
+					continue
+				fi
 			fi
 			origin=`origin_from_pdb $port` ;;
 		esac
-
@@ -3009,7 +3156,12 @@
+
@@ -3036,7 +3204,12 @@
 	/*)	echo '' ; no_valid_port ;;
 	*/*)	portdir=$argv ;;
 	\.)	portdir=${PWD##*/ports/} ;; # Not always $pd, could be symlink
-	*)	[ -d "$pdb/$argv" ] && upg_port=$argv ;;
-
+	*)	if [ -z "${use_pkgng}" ]; then
+
+	*)	if [ -z "$use_pkgng" ]; then
+			[ -d "$pdb/$argv" ] && upg_port=$argv
+		else
-
+			pkg info -e $argv && upg_port=$argv
+
+			pkg info -e $argv && upg_port=`pkg query "%n-%v" $argv`
+		fi
+		;;
 	esac
 
 	if [ -z "$portdir" -a -z "$upg_port" ]; then
-
@@ -3042,11 +3194,20 @@
+
@@ -3069,11 +3242,20 @@
 
 	case "$arg2" in
 	*/*)	ro_opd=$arg2 ; ro_upg_port=`iport_from_origin $ro_opd` ;;
-	*)	if [ -d "$pdb/$arg2" ]; then
-			ro_upg_port=$arg2
-
+	*)	if [ -z "${use_pkgng}" ]; then
+
+	*)	if [ -z "$use_pkgng" ]; then
+			if [ -d "$pdb/$arg2" ]; then
+				ro_upg_port=$arg2
+			else
@@ -469,7 +586,7 @@
 		else
-			find_glob_dirs $arg2 && ro_upg_port=${glob_dirs#$pdb/}
-			unset glob_dirs
-
+			if pkg -e $arg2; then
+
+			if pkg info -e $arg2; then
+				ro_upg_port=$arg2
+			else
+				find_glob_dirs $arg2 && ro_upg_port=${glob_dirs}
@@ -478,12 +595,12 @@
 		fi
 		[ -n "$ro_upg_port" ] && ro_opd=`origin_from_pdb $ro_upg_port`
 	esac
-
@@ -3498,7 +3659,12 @@
+
@@ -3525,7 +3707,12 @@
 		pm_v "===>>> Available package ($latest_pv) matches the current version"
 	elif [ -n "$latest_pv" -a -n "$PM_PACKAGES_NEWER" ]; then
 		if [ -n "$upg_port" ]; then
-			case `pkg_version -t $upg_port $latest_pv` in
-
+			if [ -z "${use_pkgng}" ]; then
+
+			if [ -z "$use_pkgng" ]; then
+				pkg_version="pkg_version"
+			else
+				pkg_version="pkg version"
@@ -492,12 +609,12 @@
 			\<)	use_package=up_newer
 				pm_v "===>>> Available package ($latest_pv)"
 				pm_v "       is newer than installed ($upg_port)" ;;
-
@@ -3514,7 +3680,12 @@
+
@@ -3541,7 +3728,12 @@
 			pm_v "===>>> There is a package available ($latest_pv)"
 		fi
 	elif [ -n "$latest_pv" ]; then
-		case `pkg_version -t $new_port $latest_pv` in
-
+		if [ -z "${use_pkgng}" ]; then
+
+		if [ -z "$use_pkgng" ]; then
+			pkg_version="pkg_version"
+		else
+			pkg_version="pkg version"
@@ -506,45 +623,101 @@
 		\<)	# Could happen if ports tree is out of date
 			use_package=up_old_tree
 			pm_v "===>>> Available package ($latest_pv)"
-
@@ -3613,7 +3784,12 @@
+
@@ -3640,7 +3832,12 @@
 		    grep -v ^$LOCALBASE_COMPAT > $ldconfig_out
 
 		unset temp
-		for file in `pkg_info -q -L $UPGRADE_PORT |
-
+		if [ -z "$usr_pkgng" ]; then
+
+		if [ -z "$use_pkgng" ]; then
+			pkglist="pkg_info -q -L"
+		else
-
+			pkglist="pkg info -q -l -a"
+
+			pkglist="pkg query %Fp"
+		fi
+		for file in `$pkglist $UPGRADE_PORT |
 		    sort - $ldconfig_out | uniq -d`; do
 			temp="${temp}$file "
 		done
-
@@ -3711,7 +3887,12 @@
+
@@ -3743,29 +3940,32 @@
+
 	fi
+
 fi
+
 
+
-for file in $preserve_port_files; do
+
-	mv $file ${file}-new
+
-	mv ${preserve_dir}/${file##*/} $file
+
-	oldmd5="MD5:`md5 -q $file`"
+
-
+
-	new_cont=`pm_mktemp contents`
+
-	while read left right; do
+
-		case "$left" in
+
-		@cwd)		short_file="${file#${right}/}" ;;
+
-		$short_file)	found_it=found_it ; continue;;
+
-		@comment)	if [ -n "$found_it" ]; then
+
-					echo -e "${short_file}-new\n$left $right"
+
-					echo -e "$short_file\n@comment $oldmd5"
+
-					unset found_it
+
-					continue
+
-				fi ;;
+
-		esac
+
-		echo "$left $right"
+
-	done < $pdb/$new_port/+CONTENTS > $new_cont
+
-	pm_install_s $new_cont $contents
+
-	pm_unlink $new_cont
+
-	unset file oldmd5 new_cont left right short_file
+
-done
+
+#TODO
+
+if [ -z "$use_pkgng" ]; then
+
+	for file in $preserve_port_files; do
+
+		mv $file ${file}-new
+
+		mv ${preserve_dir}/${file##*/} $file
+
+		oldmd5="MD5:`md5 -q $file`"
+
+
+
+		new_cont=`pm_mktemp contents`
+
+		while read left right; do
+
+			case "$left" in
+
+			@cwd)		short_file="${file#${right}/}" ;;
+
+			$short_file)	found_it=found_it ; continue;;
+
+			@comment)	if [ -n "$found_it" ]; then
+
+						echo -e "${short_file}-new\n$left $right"
+
+						echo -e "$short_file\n@comment $oldmd5"
+
+						unset found_it
+
+						continue
+
+					fi ;;
+
+			esac
+
+			echo "$left $right"
+
+		done < $pdb/$new_port/+CONTENTS > $new_cont
+
+		pm_install_s $new_cont $contents
+
+		pm_unlink $new_cont
+
+		unset file oldmd5 new_cont left right short_file
+
+	done
+
+fi
+
 if [ -n "$preserve_dir" ]; then
+
 	rmdir $preserve_dir 2>/dev/null
+
 	unset preserve_dir preserve_port_files
+
@@ -3781,7 +3981,12 @@
 temp=`find $LOCALBASE_COMPAT -type d -empty 2>/dev/null`
 if [ -z "$temp" ] && [ -d "$LOCALBASE_COMPAT" ]; then
 	unset files
-	for file in `pkg_info -q -L $new_port`; do
-
+	if [ -z "$usr_pkgng" ]; then
+
+	if [ -z "$use_pkgng" ]; then
+		pkglist="pkg_info -q -L"
+	else
-
+		pkglist="pkg info -q -l -a"
+
+		pkglist="pkg query %Fp"
+	fi
+	for file in `$pkglist $new_port`; do
 		[ -f "${LOCALBASE_COMPAT}/${file##*/}" ] &&
 			files="${files}${LOCALBASE_COMPAT}/${file##*/} "
 	done
-
@@ -3774,7 +3955,8 @@
+
@@ -3844,7 +4049,8 @@
 	/bin/unlink $dist_list_temp ; unset ds dist_list_temp
 fi
 
-if [ -n "$use_package" ]; then
+# pkgng does not need this
-
+if [ -n "$use_package" -a -z "${use_pkgng}" ]; then
+
+if [ -n "$use_package" -a -z "$use_pkgng" ]; then
 	if grep -q DEPORIGIN $pdb/$new_port/+CONTENTS; then
 		echo "===>>> Updating dependencies for $new_port to match installed versions"
 		update_contents $pdb/$new_port/+CONTENTS
-
@@ -3809,27 +3991,29 @@
+
@@ -3879,27 +4085,29 @@
 	echo ''
 fi