Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jun 2014 17:57:30 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r267683 - in stable/9/usr.sbin/bsdconfig: include share share/media share/packages
Message-ID:  <201406201757.s5KHvUQa040279@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Fri Jun 20 17:57:29 2014
New Revision: 267683
URL: http://svnweb.freebsd.org/changeset/base/267683

Log:
  MFC revisions 257795,257817,257819,257937-257938,258264-258265,258267,
  258854,259113,259427 (11 revisions; summarized below).
  r257795: Replace pkg-tools with pkgng
  r257817: Fix cosmetic typos
  r257819: Use `pkg -vv' to obtain ABI
  r257937: Unbreak the installer
  r257938: Remove the env(1) but keep the var
  r258264: Kick an unused orphan to the curb ;)
  r258265: Improve debugging with f_eval_catch()
  r258267: Fix package installation from physical media such as DVD
  r258854: Fix PKG_ABI detection after pkg-1.2
  r259113: Fix failed attempt to send pkg(8) stderr to /dev/null
  r259427: Export 'REPOS_DIR' when selected source medium is cdrom
  
  MFC after:	3 days

Modified:
  stable/9/usr.sbin/bsdconfig/include/messages.subr
  stable/9/usr.sbin/bsdconfig/share/common.subr
  stable/9/usr.sbin/bsdconfig/share/media/http.subr
  stable/9/usr.sbin/bsdconfig/share/packages/index.subr
  stable/9/usr.sbin/bsdconfig/share/packages/packages.subr
  stable/9/usr.sbin/bsdconfig/share/variable.subr
Directory Properties:
  stable/9/usr.sbin/bsdconfig/   (props changed)

Modified: stable/9/usr.sbin/bsdconfig/include/messages.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/include/messages.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/include/messages.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -49,7 +49,7 @@ msg_assume_yes_to_all_non_critical_dialo
 msg_astro_desc="Applications related to astronomy."
 msg_attempt_automatic_dhcp_configuration="Attempt automatic DHCP configuration of interfaces"
 msg_attempt_ipv6_configuration_of_interfaces="Attempt IPv6 configuration of interfaces"
-msg_attempting_to_fetch_file_from_selected_media="Attempting to fetch %s file from selected media."
+msg_attempting_to_update_repository_catalogue="Attempting to update repository catalogue from selected media."
 msg_audio_desc="Audio utilities - most require a supported sound card."
 msg_australia="Australia"
 msg_austria="Austria"
@@ -138,9 +138,12 @@ msg_ftp_desc="FTP client and server util
 msg_ftp_passive="FTP Passive"
 msg_ftp_username="FTP username"
 msg_games_desc="Various games and sundry amusements."
+msg_generating_index_from_pkg_database="Generating INDEX from pkg(8) database\n(this can take a while)..."
 msg_geography_desc="Geography-related software."
 msg_german_desc="Ported software for Germanic countries."
 msg_germany="Germany"
+msg_getting_package_categories_via_pkg_rquery="Getting package categories via pkg-rquery(8)..."
+msg_getting_package_dependencies_via_pkg_rquery="Getting package dependencies via pkg-rquery(8)\n(this can take a while)..."
 msg_gnome_desc="Components of the Gnome Desktop environment."
 msg_gnustep_desc="Software for GNUstep desktop environment."
 msg_graphics_desc="Graphics libraries and utilities."
@@ -176,7 +179,7 @@ msg_invalid_name_server_ip_address_speci
 msg_invalid_netmask_value="Invalid netmask value"
 msg_invalid_nfs_path_specification="Invalid NFS path specification.  Must be of the form:\nhost:/full/pathname/to/FreeBSD/distdir"
 msg_io_error_while_reading_in_the_package="I/O error while reading in the %s package."
-msg_io_or_format_error_on_index_file="I/O or format error on %s file.\nPlease verify media (or path to media) and try again."
+msg_io_or_format_error_on_index_file="I/O or format error on INDEX file.\nPlease verify media (or path to media) and try again."
 msg_ipv4_address="IPv4 Address"
 msg_ipv4_gateway="IPv4 Gateway"
 msg_ipv6="IPv6"
@@ -246,6 +249,7 @@ msg_no_gateway_has_been_set="No gateway 
 msg_no_network_devices="No network devices available!"
 msg_no_package_name_passed_in_package_variable="No package name passed in package variable"
 msg_no_packages_were_selected_for_extraction="No packages were selected for extraction."
+msg_no_pkg_database_found="No pkg(8) database found!"
 msg_no_such_file_or_directory="%s: %s: No such file or directory"
 msg_no_usb_devices_found="No USB devices found (try Options/Re-scan Devices)"
 msg_no_username="No username provided!"
@@ -257,10 +261,8 @@ msg_ok="OK"
 msg_options="Options"
 msg_options_editor="Options Editor"
 msg_other="other"
-msg_pkg_delete_failed="Warning: pkg_delete of %s failed.\n  Run with debugging for details."
 msg_package_is_needed_by_other_installed_packages="Warning: Package %s is needed by\n  %d other installed package%s."
 msg_package_not_installed_cannot_delete="Warning: package %s not installed\n No package can be deleted."
-msg_package_read_successfully_waiting_for_pkg_add="Package %s read successfully - waiting for pkg_add(1)"
 msg_package_temp="Package Temp"
 msg_package_was_added_successfully="Package %s was added successfully"
 msg_packages="packages"
@@ -270,7 +272,8 @@ msg_parallel_desc="Applications dealing 
 msg_pear_desc="Software related to the Pear PHP framework."
 msg_perl5_desc="Utilities/modules for the PERL5 language."
 msg_permission_denied="%s: %s: Permission denied"
-msg_pkg_add_apparently_did_not_like_the_package="pkg_add(1) apparently did not like the %s package."
+msg_pkg_delete_failed="Warning: pkg-delete(8) of %s failed.\n  Run with debugging for details."
+msg_pkg_install_apparently_did_not_like_the_package="pkg-install(8) apparently did not like the %s package."
 msg_plan9_desc="Software from the Plan9 operating system."
 msg_please_check_the_url_and_try_again="No such directory: %s\nplease check the URL and try again.\n"
 msg_please_enter_password="Please enter your password for sudo(8):"
@@ -373,9 +376,12 @@ msg_unable_to_get_proper_ftp_path="Unabl
 msg_unable_to_initialize_media_type_for_package_extract="Unable to initialize media type for package extract."
 msg_unable_to_make_directory_mountpoint="Unable to make %s directory mountpoint for %s!"
 msg_unable_to_open="Unable to open %s"
+msg_unable_to_pkg_rquery_package_categories="Unable to pkg-rquery(8) package categories!"
+msg_unable_to_pkg_rquery_package_dependencies="Unable to pkg-rquery(8) package dependencies!"
+msg_unable_to_update_pkg_from_selected_media="Unable to update pkg(8) from selected media."
 msg_uninstall="Uninstall"
 msg_uninstall_desc="Mark this package for deletion"
-msg_uninstalling_package_waiting_for_pkg_delete="Uninstalling %s package - waiting for pkg_delete(1)"
+msg_uninstalling_package_waiting_for_pkg_delete="Uninstalling %s package - waiting for pkg-delete(8)"
 msg_unknown="unknown"
 msg_unknown_user="Unknown user: %s"
 msg_url_was_not_found="%s was not found, maybe directory or release-version are wrong?"

Modified: stable/9/usr.sbin/bsdconfig/share/common.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/share/common.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/share/common.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -60,7 +60,14 @@ FAILURE=1
 #
 export UNAME_S="$( uname -s )" # Operating System (i.e. FreeBSD)
 export UNAME_P="$( uname -p )" # Processor Architecture (i.e. i386)
+export UNAME_M="$( uname -m )" # Machine platform (i.e. i386)
 export UNAME_R="$( uname -r )" # Release Level (i.e. X.Y-RELEASE)
+if [ ! "${PKG_ABI+set}" ]; then
+	export PKG_ABI="$(
+		ASSUME_ALWAYS_YES=1 pkg -vv 2> /dev/null |
+			awk '$1=="ABI"{print $3;exit}'
+	)"
+fi
 
 #
 # Default behavior is to call f_debug_init() automatically when loaded.

Modified: stable/9/usr.sbin/bsdconfig/share/media/http.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/share/media/http.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/share/media/http.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -77,7 +77,8 @@ f_dialog_menu_media_http()
 	f_dialog_title_restore
 	local prompt="$msg_please_select_the_site_closest_to_you_or_other"
 	local menu_list="
-		'$msg_main_site'      'ftp.freebsd.org'
+		'dist $msg_main_site' 'ftp.freebsd.org'
+		'pkg $msg_main_site'  'pkg.freebsd.org'
 		'URL'                 '$msg_specify_some_other_http_site'
 	" # END-QUOTE
 	local hline="$msg_select_a_site_thats_close"
@@ -322,7 +323,7 @@ f_media_set_http()
 	device_http set type     $DEVICE_TYPE_HTTP
 	device_http set init     f_media_init_http
 	device_http set get      f_media_get_http
-	device_http set shutdown :
+	device_http set shutdown f_media_shutdown_http
 	device_http set private  device_network
 	f_struct_copy device_http device_media
 	f_struct_free device_http
@@ -453,6 +454,11 @@ f_media_init_http()
 	local dev="$1"
 	f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
 
+	if [ "$HTTP_INITIALIZED" ]; then
+		f_dprintf "HTTP device already initialized."
+		return $SUCCESS
+	fi
+
 	#
 	# First verify access
 	#
@@ -494,22 +500,31 @@ f_media_init_http()
 			#
 			local fdir hp
 			f_getvar $VAR_HTTP_PATH%/ hp
-			for fdir in $HTTP_DIRS; do
-				setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
-				if f_http_check_access; then
-					http_found=$SUCCESS
-					break
-				fi
-			done
+			setvar $VAR_HTTP_PATH "$hp/$PKG_ABI/latest"
+			if [ "$PKG_ABI" ] && f_http_check_access; then
+				http_found=$SUCCESS
+				setvar $VAR_HTTP_PATH "$hp"
+			else
+				for fdir in $HTTP_DIRS; do
+					setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
+					if f_http_check_access; then
+						http_found=$SUCCESS
+						break
+					fi
+				done
+			fi
 		esac
 
-		[ $http_found -eq $SUCCESS ] && break
+		if [ $http_found -eq $SUCCESS ]; then
+			HTTP_INITIALIZED=YES
+			break
+		fi
 
 		f_getvar $VAR_HTTP_PATH http_path
 		f_show_msg "$msg_please_check_the_url_and_try_again" \
 		           "$http_path"
 
-		unset $VAR_HTTP_PATH
+		unset HTTP_INITIALIZED $VAR_HTTP_PATH
 		f_media_set_http || break
 	done
 
@@ -561,6 +576,11 @@ f_media_get_http()
 	f_getvar $VAR_HTTP_HOST http_host
 	f_getvar $VAR_HTTP_PORT http_port
 
+	if [ ! "$HTTP_INITIALIZED" ]; then
+		f_dprintf "No HTTP connection open, can't get file %s" "$file"
+		return $FAILURE
+	fi
+
 	if ! {
 		f_validate_ipaddr "$http_host" ||
 		f_validate_ipaddr6 "$http_host" ||
@@ -652,6 +672,18 @@ f_media_get_http()
 	return $FAILURE
 }
 
+# f_media_shutdown_http $device
+#
+# Shuts down the HTTP device. Return status should be ignored. Note that since
+# we don't maintain an open connection to the HTTP server, nothing to do.
+#
+f_media_shutdown_http()
+{
+	[ "$HTTP_INITIALIZED" ] || return $SUCCESS
+
+	unset HTTP_INITIALIZED
+}
+
 ############################################################ MAIN
 
 f_dprintf "%s: Successfully loaded." media/http.subr

Modified: stable/9/usr.sbin/bsdconfig/share/packages/index.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/share/packages/index.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/share/packages/index.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -43,24 +43,53 @@ f_include_lang $BSDCFG_LIBE/include/mess
 PACKAGE_INDEX=
 _INDEX_INITTED=
 
+#
+# Default path to pkg(8) repo-packagesite.sqlite database
+#
+SQLITE_REPO="/var/db/pkg/repo-packagesite.sqlite"
+
+#
+# Default path to on-disk cache INDEX file
+#
+PACKAGES_INDEX_CACHEFILE="/var/run/bsdconfig/packages_INDEX.cache"
+
+#
+# INDEX format for FreeBSD-6.0 or higher:
+#
+# 	package|port-origin|install-prefix|comment|port-desc-file|maintainer|
+# 	categories|build-deps|run-deps|www-site|reserve|reserve|reserve|disc
+#
+INDEX_FORMAT="%n-%v" # package
+INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o"	# port-origin
+INDEX_FORMAT="$INDEX_FORMAT|%p"			# install-prefix
+INDEX_FORMAT="$INDEX_FORMAT|%c"			# comment
+INDEX_FORMAT="$INDEX_FORMAT|/usr/ports/%o/pkg-descr"	# port-desc-file
+INDEX_FORMAT="$INDEX_FORMAT|%m"			# maintainer
+INDEX_FORMAT="$INDEX_FORMAT|@CATEGORIES@"	# place-holder
+INDEX_FORMAT="$INDEX_FORMAT|"			# build-deps
+INDEX_FORMAT="$INDEX_FORMAT|@RUNDEPS@"		# place-holder
+INDEX_FORMAT="$INDEX_FORMAT|%w"			# www-site
+INDEX_FORMAT="$INDEX_FORMAT|"			# reserved
+INDEX_FORMAT="$INDEX_FORMAT|"			# reserved
+INDEX_FORMAT="$INDEX_FORMAT|"			# reserved
+INDEX_FORMAT="$INDEX_FORMAT|"			# disc
+
 ############################################################ FUNCTIONS
 
-# f_index_initialize $path [$var_to_set]
+# f_index_initialize [$var_to_set]
 #
-# Read and initialize the global index. $path is to be relative to the chosen
-# media (not necessarily the filesystem; e.g. FTP) -- this is usually going to
-# be `packages/INDEX'. Returns success unless media cannot be initialized for
-# any reason (e.g. user cancels media selection dialog) or an error occurs. The
-# index is sorted before being loaded into $var_to_set.
+# Read and initialize the global index. Returns success unless media cannot be
+# initialized for any reason (e.g. user cancels media selection dialog or an
+# error occurs). The index is sorted before being loaded into $var_to_set.
 #
 # NOTE: The index is processed with f_index_read() [below] after being loaded.
 #
 f_index_initialize()
 {
-	local __path="$1" __var_to_set="${2:-PACKAGE_INDEX}"
+	local __funcname=f_index_initialize
+	local __var_to_set="${2:-PACKAGE_INDEX}"
 
 	[ "$_INDEX_INITTED" ] && return $SUCCESS
-	[ "$__path" ] || return $FAILURE
 
 	# Got any media?
 	f_media_verify || return $FAILURE
@@ -68,20 +97,177 @@ f_index_initialize()
 	# Does it move when you kick it?
 	f_device_init device_media || return $FAILURE
 
-	f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \
-	            "$__path"
-	eval "$__var_to_set"='$( f_device_get device_media "$__path" )'
-	if [ $? -ne $SUCCESS ]; then
-		f_show_msg "$msg_unable_to_get_file_from_selected_media" \
-		           "$__path"
+	f_show_info "$msg_attempting_to_update_repository_catalogue"
+
+	#
+	# Generate $PACKAGESITE variable for pkg(8) based on media type
+	#
+	local __type __data __site
+	device_media get type __type
+	device_media get private __data
+	case "$__type" in
+	$DEVICE_TYPE_DIRECTORY)
+		__site="file://$__data/packages/$PKG_ABI" ;;
+	$DEVICE_TYPE_FLOPPY)
+		__site="file://${__data:-$MOUNTPOINT}/packages/$PKG_ABI" ;;
+	$DEVICE_TYPE_FTP)
+		f_getvar $VAR_FTP_PATH __site
+		__site="$__site/packages/$PKG_ABI" ;;
+	$DEVICE_TYPE_HTTP)
+		f_getvar $VAR_HTTP_PATH __site
+		__site="$__site/$PKG_ABI/latest" ;;
+	$DEVICE_TYPE_HTTP_PROXY)
+		f_getvar $VAR_HTTP_PROXY_PATH __site
+		__site="$__site/packages/$PKG_ABI" ;;
+	$DEVICE_TYPE_CDROM)
+		__site="file://$MOUNTPOINT/packages/$PKG_ABI"
+		export REPOS_DIR="$MOUNTPOINT/packages/repos" ;;
+	*) # UFS, DISK, CDROM, USB, DOS, NFS, etc.
+		__site="file://$MOUNTPOINT/packages/$PKG_ABI"
+	esac
+
+	export PACKAGESITE="$__site"
+	f_dprintf "PACKAGESITE=[%s]" "$PACKAGESITE"
+	if ! f_eval_catch $__funcname pkg "pkg update"; then
+		f_show_err "$msg_unable_to_update_pkg_from_selected_media"
+		f_device_shutdown device_media
+		return $FAILURE
+	fi
+
+	#
+	# Try to get contents from validated on-disk cache
+	#
+
+	#
+	# Calculate digest used to determine if the on-disk persistant cache
+	# INDEX (containing this digest on the first line) is valid and can be
+	# used to quickly populate the environment.
+	#
+	local __sqlite_digest
+	if ! __sqlite_digest=$( md5 < "$SQLITE_REPO" 2> /dev/null ); then
+		f_show_err "$msg_no_pkg_database_found"
+		f_device_shutdown device_media
+		return $FAILURE
+	fi
+
+	#
+	# Check to see if the persistant cache INDEX file exists
+	#
+	if [ -f "$PACKAGES_INDEX_CACHEFILE" ]; then
+		#
+		# Attempt to populate the environment with the (soon to be)
+		# validated on-disk cache. If validation fails, fall-back to
+		# generating a fresh cache.
+		#
+		if eval $__var_to_set='$(
+			(	# Get digest as the first word on first line
+				read digest rest_ignored
+
+				#
+				# If the stored digest matches the calculated-
+				# one populate the environment from the on-disk
+				# cache and provide success exit status.
+				#
+				if [ "$digest" = "$__sqlite_digest" ]; then
+					cat
+					exit $SUCCESS
+				else
+					# Otherwise, return the current value
+					eval echo \"\$__var_to_set\"
+					exit $FAILURE
+				fi
+			) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null
+		)'; then
+			f_show_info \
+			  "$msg_located_index_now_reading_package_data_from_it"
+			if ! f_index_read "$__var_to_set"; then
+				f_show_err \
+					"$msg_io_or_format_error_on_index_file"
+				return $FAILURE
+			fi
+			_INDEX_INITTED=1
+			return $SUCCESS
+		fi
+		# Otherwise, fall-thru to create a fresh cache from scratch
+	fi
+
+	#
+	# If we reach this point, we need to generate the data from scratch
+	#
+
+	f_show_info "$msg_getting_package_categories_via_pkg_rquery"
+	if ! eval "$( pkg rquery "%n-%v %C" | awk '
+	{ categories[$1] = categories[$1] " " $2 }
+	END {
+		for (package in categories)
+		{
+			cats = categories[package]
+			sub(/^ /, "", cats)
+			gsub(/[^[:alnum:]_]/, "_", package)
+			printf "local _%s_categories=\"%s\";\n", package, cats
+		}
+	}' )"; then
+		f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
 		f_device_shutdown device_media
 		return $FAILURE
 	fi
+
+	f_show_info "$msg_getting_package_dependencies_via_pkg_rquery"
+	if ! eval "$( pkg rquery "%n-%v %dn-%dv" | awk '
+	{ rundeps[$1] = rundeps[$1] " " $2 }
+	END {
+		for (package in rundeps)
+		{
+			deps = rundeps[package]
+			sub(/^ /, "", deps)
+			gsub(/[^[:alnum:]_]/, "_", package)
+			printf "local _%s_rundeps=\"%s\";\n", package, deps
+		}
+	}' )"; then
+		f_show_err "$msg_unable_to_pkg_rquery_package_dependencies"
+		f_device_shutdown device_media
+		return $FAILURE
+	fi
+
+	f_show_info "$msg_generating_index_from_pkg_database"
+	eval "$__var_to_set"='$( pkg rquery "$INDEX_FORMAT" |
+		while read LINE; do
+			package="${LINE%%|*}";
+			f_str2varname "$package" varpkg;
+			eval f_replaceall \"\$LINE\" \"\|@CATEGORIES@\|\" \
+				\"\|\$_${varpkg}_categories\|\" LINE
+			eval f_replaceall \"\$LINE\" \"\|@RUNDEPS@\|\" \
+				\"\|\$_${varpkg}_rundeps\|\" LINE
+			echo "$LINE"
+		done
+	)' # always returns true (status of last item in pipe-chain)
 	eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
 
+	#
+	# Attempt to create the persistant on-disk cache
+	#
+
+	# Create a new temporary file to write to
+	local __tmpfile
+	if f_eval_catch -dk __tmpfile $__funcname mktemp \
+		'mktemp -t "%s"' "$pgm"
+	then
+		# Write the temporary file contents
+		echo "$__sqlite_digest" > "$__tmpfile"
+		debug= f_getvar "$__var_to_set" >> "$__tmpfile"
+
+		# Finally, move the temporary file into place
+		case "$PACKAGES_INDEX_CACHEFILE" in
+		*/*) f_eval_catch -d $funcname mkdir \
+			'mkdir -p "%s"' "${PACKAGES_INDEX_CACHEFILE%/*}"
+		esac
+		f_eval_catch -d $__funcname mv 'mv -f "%s" "%s"' \
+			"$__tmpfile" "$PACKAGES_INDEX_CACHEFILE"
+	fi
+
 	f_show_info "$msg_located_index_now_reading_package_data_from_it"
 	if ! f_index_read "$__var_to_set"; then
-		f_show_msg "$msg_io_or_format_error_on_index_file" "$__path"
+		f_show_err "$msg_io_or_format_error_on_index_file"
 		return $FAILURE
 	fi
 

Modified: stable/9/usr.sbin/bsdconfig/share/packages/packages.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/share/packages/packages.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/share/packages/packages.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -53,7 +53,7 @@ f_include_lang $BSDCFG_LIBE/include/mess
 #
 # Package extensions to try
 #
-PACKAGE_EXTENSIONS=".tbz .tbz2 .tgz"
+PACKAGE_EXTENSIONS=".txz .tbz .tbz2 .tgz"
 
 #
 # Variables used to track runtime states
@@ -164,24 +164,13 @@ f_package_deselect()
 
 # f_package_detect_installed
 #
-# Detect installed packages. Currently this searches /var/db/pkg for directory
+# Detect installed packages. Currently this uses pkg-query(8) for querying
 # entries and marks each entry as an installed/selected package.
 #
 f_package_detect_installed()
 {
-	local installed package varpkg
-	#
-	# XXX KLUDGE ALERT! This makes evil assumptions about how XXX
-	# packages register themselves and should *really* be done with
-	# `pkg_info -e <name>' except that this is too slow for an
-	# item check routine.. :-(
-	#
-	# NOTE: When transitioning to pkgng, make a single fork to `pkg' to
-	#       produce a list of all installed packages and parse _that_
-	#
-	installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d |
-			sed -e 's:/var/db/pkg/::' )
-	for package in $installed; do
+	local package varpkg
+	for package in $( pkg query "%n-%v" ); do
 		f_str2varname $package varpkg
 		export _mark_$varpkg=X # exported for awk(1) ENVIRON[]
 		f_package_select $package
@@ -983,23 +972,31 @@ f_package_extract()
 	f_getvar $VAR_PKG_TMPDIR:-/var/tmp tmpdir
 	f_quietly mkdir -p -m 1777 "$tmpdir"
 
-	local path
+	local path device_type
+	$device get type device_type
 	case "$name" in
 	*/*) path="$name" ;;
 	*)
-		case "$name" in
-		*-*|*_*) path="packages/All/$name" ;;
-		      *) path="packages/Latest/$name"
-		esac
+		if [ "$device_type" = "$DEVICE_TYPE_HTTP" ]; then
+			path="$PKG_ABI/latest/All/$name"
+		else
+			path="packages/$PKG_ABI/All/$name"
+		fi
 	esac
 
-	# We have a path, call the device strategy routine to get the file
+	# We have a path, call the device strategy routine to check the file
 	local pkg_ext found=
 	for pkg_ext in "" $PACKAGE_EXTENSIONS; do
 		if f_device_get $device "$path$pkg_ext" $PROBE_EXIST; then
 			path="$path$pkg_ext"
-			f_dprintf "$funcname: found path=[%s] dev=[%s]" \
-			          "$path" "$device"
+			found=1
+			break
+		elif [ "$device_type" = "$DEVICE_TYPE_HTTP" ] &&
+		     f_device_get $device \
+			"packages/$PKG_ABI/All/$name$pkg_ext" $PROBE_EXIST
+		then
+			# Mirroring physical media over HTTP
+			path="packages/$PKG_ABI/All/$name$pkg_ext"
 			found=1
 			break
 		fi
@@ -1027,27 +1024,14 @@ f_package_extract()
 		f_show_info "$msg_adding_package_from_media" "$name" "$devname"
 	fi
 
-	# Get package data and pipe into pkg_add(1) while providing feedback
-	{
-		if ! f_device_get $device "$path"; then
-			$alert "$msg_io_error_while_reading_in_the_package" \
-			       "$name" \
-			       >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null
-			[ "$no_confirm" ] && sleep 2
-		else
-			f_show_info \
-			 "$msg_package_read_successfully_waiting_for_pkg_add" \
-			 "$name" >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null
-		fi
-	} | {
-		if f_debugging; then
-			/usr/sbin/pkg_add -v -
-		else
-			f_quietly /usr/sbin/pkg_add -
-		fi
-	}
+	# Request the package be added via pkg-install(8)
+	if f_debugging; then
+		f_eval_catch $funcname pkg 'pkg -d install -y "%s"' "$name"
+	else
+		f_eval_catch $funcname pkg 'pkg install -y "%s"' "$name"
+	fi
 	if [ $? -ne $SUCCESS ]; then
-		$alert "$msg_pkg_add_apparently_did_not_like_the_package" \
+		$alert "$msg_pkg_install_apparently_did_not_like_the_package" \
 		       "$name"
 		[ "$no_confirm" ] && sleep 2
 	else
@@ -1173,9 +1157,9 @@ f_package_delete()
 	#
 	f_show_info "$msg_uninstalling_package_waiting_for_pkg_delete" "$name"
 	if f_debugging; then
-		pkg_delete -v "$name"
+		f_eval_catch $funcname pkg 'pkg -d delete -y "%s"' "$name"
 	else
-		f_quietly pkg_delete "$name"
+		f_eval_catch $funcname pkg 'pkg delete -y "%s"' "$name"
 	fi
 	if [ $? -ne $SUCCESS ]; then
 		f_show_msg "$msg_pkg_delete_failed" "$name"

Modified: stable/9/usr.sbin/bsdconfig/share/variable.subr
==============================================================================
--- stable/9/usr.sbin/bsdconfig/share/variable.subr	Fri Jun 20 17:45:00 2014	(r267682)
+++ stable/9/usr.sbin/bsdconfig/share/variable.subr	Fri Jun 20 17:57:29 2014	(r267683)
@@ -205,7 +205,7 @@ f_netinteractive()
 	f_getvar $VAR_NETINTERACTIVE value && [ "$value" ]
 }
 
-# f_zfsinteractive()
+# f_zfsinteractive
 #
 # Has the user specifically requested the ZFS-portion of configuration and
 # setup to be performed interactively? Returns success if the user has asked



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406201757.s5KHvUQa040279>