  	\<)	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" ;;
-@@ -2982,7 +3074,12 @@
+@@ -2452,7 +2576,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
++					confl_p=`pkg_info -I $glob 2>/dev/null`
++				else
++					confl_p=`pkg info -qg $glob 2>/dev/null` 
++				fi
+ 				if [ -n "$confl_p" ]; then
+ 					confl_p=${confl_p%% *}
+ 					echo ''
+@@ -2585,6 +2713,10 @@
+ 		done
+ 
+ 		for dep in $build_only_dl_g; do
++			if [ -n "${use_pkgng}" ]; then
++				[ `pkg query "%?r"` = "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 @@
+ 	echo "===>>> Begin $verb ports that depend on $PM_URB_IPORTS"
+ 	echo ''
+ 
++	#TODO
+ 	for origin in $PM_URB_ORIGINS; do
++		if [ -n "${use_pkgng}" ]; then
++			for req_by in `pkg query "%rn-%rv" ${origin}`; do
++				PM_URB_LIST="${PM_URB_LIST} ${req_by}"
++			done
++			continue
++		fi
+ 		for req_by in `grep -l DEPORIGIN:${origin}$ $pdb/*/+CONTENTS`; do
+ 			req_by="${req_by%/+CONTENTS}"
+ 			req_by="${req_by##*/}"
+@@ -2785,9 +2924,17 @@
+ 		*/*)	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
++					numports=$(( $numports - 1 ))
++					continue
++				fi
++			else
++
++				if [ ! -d "$pdb/$port" ]; then
++					numports=$(( $numports - 1 ))
++					continue
++				fi
+ 			fi
+ 			origin=`origin_from_pdb $port` ;;
+ 		esac
+@@ -3009,7 +3156,12 @@
  	/*)	echo '' ; no_valid_port ;;
  	*/*)	portdir=$argv ;;
  	\.)	portdir=${PWD##*/ports/} ;; # Not always $pd, could be symlink

 			esac
 
 			[ -z "$do_update" ] && {
@@ -1682,6 +1764,11 @@
 	fi
 
 	pm_cd $pkgdir || fail "Cannot cd into $pkgdir to create a package"
+	if [ -z "${use_pkgng}" ]; then
+		pm_pkg_create="pkg_create -b"
+	else
+		pm_pkg_create="pkg create "
+	fi
 	if $PM_SU_CMD pkg_create -b $2; then
 		if [ "$1" = "$pbu" ]; then
 			if [ -n "$BACKUP" ]; then
@@ -2224,7 +2311,12 @@
 			fail "No entry for $origin in $PM_INDEX"
 	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 @@
 
 	pattern=`globstrip $1`
 
-	glob_dirs=`find $pdb -maxdepth 1 -type d -name ${pattern}\*`
+	if [ -z "${use_pkgng}" ]; then
+		glob_dirs=`find $pdb -maxdepth 1 -type d -name ${pattern}\*`
+	else
+		glob_dirs=`pkg info -qg ${pattern}\*`
+	fi
 	case "$glob_dirs" in
 	# Match a newline in multiple responses from find
 	*'
 '*)		return 2 ;;
-	$pdb/*)	return ;;
+	*)	return ;;
 	esac
 
 	unset glob_dirs
@@ -505,8 +515,12 @@
 origin_from_pdb () {
 	local o
 
