summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-05-07 05:40:20 +0000
committerdteske <dteske@FreeBSD.org>2013-05-07 05:40:20 +0000
commit01469a18631d9718ac42f79693b6a118f9ba96fa (patch)
tree58929a83edc699caa7a21276520aeff1008014a2 /usr.sbin/bsdconfig/share
parent10fa20ef4fa0cb58cb905dd895eab6d587a359b1 (diff)
downloadFreeBSD-src-01469a18631d9718ac42f79693b6a118f9ba96fa.zip
FreeBSD-src-01469a18631d9718ac42f79693b6a118f9ba96fa.tar.gz
Commit first portion of package module -- this includes the ability to view
categories, view packages, mark packages for installation, de-installation, or re-installation, calculate and track dependencies, as well as ability to review selections. Still to come is the actual processing of selections (performing the various actions associated with the user's selections, such as installing dependencies first, then selections, etc.).
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r--usr.sbin/bsdconfig/share/Makefile2
-rw-r--r--usr.sbin/bsdconfig/share/media/options.subr24
-rw-r--r--usr.sbin/bsdconfig/share/packages/Makefile11
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/categories.subr203
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/index.subr244
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/packages.subr746
-rw-r--r--usr.sbin/bsdconfig/share/script.subr4
-rw-r--r--usr.sbin/bsdconfig/share/variable.subr5
8 files changed, 1238 insertions, 1 deletions
diff --git a/usr.sbin/bsdconfig/share/Makefile b/usr.sbin/bsdconfig/share/Makefile
index 4c20c2b..3392e2a 100644
--- a/usr.sbin/bsdconfig/share/Makefile
+++ b/usr.sbin/bsdconfig/share/Makefile
@@ -2,7 +2,7 @@
NO_OBJ=
-SUBDIR= media
+SUBDIR= media packages
FILESDIR= ${SHAREDIR}/bsdconfig
FILES= common.subr device.subr dialog.subr mustberoot.subr \
diff --git a/usr.sbin/bsdconfig/share/media/options.subr b/usr.sbin/bsdconfig/share/media/options.subr
index 2c8d3bd..5147056 100644
--- a/usr.sbin/bsdconfig/share/media/options.subr
+++ b/usr.sbin/bsdconfig/share/media/options.subr
@@ -111,6 +111,15 @@ f_media_options_menu()
'$msg_emit_extra_debugging_output'"
fi
+ f_getvar $VAR_NO_CONFIRM cp
+ if [ "$cp" ]; then menu_list="$menu_list
+ ' $msg_yes_to_all' 'YES'
+ '$msg_assume_yes_to_all_non_critical_dialogs'"
+ else menu_list="$menu_list
+ ' $msg_yes_to_all' 'NO'
+ '$msg_assume_yes_to_all_non_critical_dialogs'"
+ fi
+
f_getvar $VAR_TRY_DHCP cp
if [ "$cp" = "YES" ]; then menu_list="$menu_list
' $msg_dhcp' 'YES'
@@ -179,6 +188,11 @@ f_media_options_menu()
' $msg_media_timeout' '$cp'
'$msg_timeout_value_in_seconds_for_slow_media'"
+ f_getvar $VAR_PKG_TMPDIR cp
+ menu_list="$menu_list
+ ' $msg_package_temp' '$cp'
+ '$msg_directory_where_package_temporary_files_go'"
+
menu_list="$menu_list
' $msg_rescan_devices' '<*>'
'$msg_rerun_bsdconfig_initial_device_probe'
@@ -260,6 +274,12 @@ f_media_options_menu()
else
export $VAR_DEBUG=1
fi ;;
+ " $msg_yes_to_all")
+ if f_getvar $VAR_NO_CONFIRM cp && [ "$cp" ]; then
+ unset $VAR_NO_CONFIRM
+ else
+ export $VAR_NO_CONFIRM=1
+ fi ;;
" $msg_dhcp")
f_getvar $VAR_TRY_DHCP cp
if [ "$cp" = "YES" ]; then
@@ -290,6 +310,10 @@ f_media_options_menu()
f_variable_get_value $VAR_MEDIA_TIMEOUT \
"$msg_please_specify_the_number_of_seconds_to_wait"
;;
+ " $msg_package_temp")
+ f_variable_get_value $VAR_PKG_TMPDIR \
+ "$msg_please_specify_a_temporary_directory"
+ ;;
" $msg_rescan_devices")
f_device_rescan ;;
" $msg_use_defaults")
diff --git a/usr.sbin/bsdconfig/share/packages/Makefile b/usr.sbin/bsdconfig/share/packages/Makefile
new file mode 100644
index 0000000..2a02353
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+NO_OBJ=
+
+FILESDIR= ${SHAREDIR}/bsdconfig/packages
+FILES= categories.subr index.subr packages.subr
+
+beforeinstall:
+ mkdir -p ${DESTDIR}${FILESDIR}
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/bsdconfig/share/packages/categories.subr b/usr.sbin/bsdconfig/share/packages/categories.subr
new file mode 100755
index 0000000..ebe9cb0
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/categories.subr
@@ -0,0 +1,203 @@
+if [ ! "$_PACKAGES_CATEGORIES_SUBR" ]; then _PACKAGES_CATEGORIES_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INLUDING, 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.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." packages/categories.subr
+f_include $BSDCFG_SHARE/strings.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ GLOBALS
+
+CATEGORIES=
+
+############################################################ FUNCTIONS
+
+# f_category_desc_get $category [$var_to_set]
+#
+# Fetch the description of a given category. Returns success if a match was
+# found, otherwise failure.
+#
+# If $var_to_set is missing or NULL, the category description is printed to
+# standard out for capturing in a sub-shell (which is less-recommended because
+# of performance degredation; for example, when called in a loop).
+#
+f_category_desc_get()
+{
+ local __category="$1" __var_to_set="$2" __cat __varcat
+
+ # Return failure if $category
+ [ "$__category" ] || return $FAILURE
+
+ for __cat in $CATEGORIES; do
+ [ "$__cat" = "$__category" ] || continue
+ f_str2varname $__cat __varcat
+ f_getvar _category_$__varcat $__var_to_set
+ return $?
+ done
+ return $FAILURE
+}
+
+# f_category_desc_set $category $desc
+#
+# Store a description in-association with a category. $category should be
+# alphanumeric and can include the underscore [_] but should not contain
+# whitespace. Returns success unless $category is NULL or no arguments. Use the
+# f_category_desc_get() routine with the same $category to retrieve the stored
+# description.
+#
+f_category_desc_set()
+{
+ local category="$1" desc="$2"
+ local cat varcat found=
+ [ "$category" ] || return $FAILURE
+ for cat in $CATEGORIES; do
+ [ "$cat" = "$category" ] || continue
+ f_str2varname $cat varcat
+ f_quietly f_getvar _category_$varcat || continue
+ found=1 && break
+ done
+ if [ ! "$found" ]; then
+ CATEGORIES="$CATEGORIES $category"
+ fi
+ f_str2varname $category varcat
+ setvar "_category_$varcat" "$desc"
+ # Export the variable for awk(1) ENVIRON visibility
+ export "_category_$varcat"
+ return $SUCCESS
+}
+
+############################################################ MAIN
+
+#
+# Load descriptions for package categories
+#
+f_category() { f_category_desc_set "$1" "$2"; }
+f_category All "$msg_all_available_packages_in_all_categories"
+f_category accessibility "$msg_accessibility_desc"
+f_category afterstep "$msg_afterstep_desc"
+f_category arabic "$msg_arabic_desc"
+f_category archivers "$msg_archivers_desc"
+f_category astro "$msg_astro_desc"
+f_category audio "$msg_audio_desc"
+f_category benchmarks "$msg_benchmarks_desc"
+f_category biology "$msg_biology_desc"
+f_category cad "$msg_cad_desc"
+f_category chinese "$msg_chinese_desc"
+f_category comms "$msg_comms_desc"
+f_category converters "$msg_converters_desc"
+f_category databases "$msg_databases_desc"
+f_category deskutils "$msg_deskutils_desc"
+f_category devel "$msg_devel_desc"
+f_category dns "$msg_dns_desc"
+f_category docs "$msg_docs_desc"
+f_category editors "$msg_editors_desc"
+f_category elisp "$msg_elisp_desc"
+f_category emulators "$msg_emulators_desc"
+f_category enlightenment "$msg_enlightenment_desc"
+f_category finance "$msg_finance_desc"
+f_category french "$msg_french_desc"
+f_category ftp "$msg_ftp_desc"
+f_category games "$msg_games_desc"
+f_category geography "$msg_geography_desc"
+f_category german "$msg_german_desc"
+f_category gnome "$msg_gnome_desc"
+f_category gnustep "$msg_gnustep_desc"
+f_category graphics "$msg_graphics_desc"
+f_category hamradio "$msg_hamradio_desc"
+f_category haskell "$msg_haskell_desc"
+f_category hebrew "$msg_hebrew_desc"
+f_category hungarian "$msg_hungarian_desc"
+f_category ipv6 "$msg_ipv6_desc"
+f_category irc "$msg_irc_desc"
+f_category japanese "$msg_japanese_desc"
+f_category java "$msg_java_desc"
+f_category kde "$msg_kde_desc"
+f_category kld "$msg_kld_desc"
+f_category korean "$msg_korean_desc"
+f_category lang "$msg_lang_desc"
+f_category linux "$msg_linux_desc"
+f_category lisp "$msg_lisp_desc"
+f_category mail "$msg_mail_desc"
+f_category math "$msg_math_desc"
+f_category mbone "$msg_mbone_desc"
+f_category misc "$msg_misc_desc"
+f_category multimedia "$msg_multimedia_desc"
+f_category net "$msg_net_desc"
+f_category net-im "$msg_net_im_desc"
+f_category net-mgmt "$msg_net_mgmt_desc"
+f_category net-p2p "$msg_net_p2p_desc"
+f_category news "$msg_news_desc"
+f_category palm "$msg_palm_desc"
+f_category parallel "$msg_parallel_desc"
+f_category pear "$msg_pear_desc"
+f_category perl5 "$msg_perl5_desc"
+f_category plan9 "$msg_plan9_desc"
+f_category polish "$msg_polish_desc"
+f_category ports-mgmt "$msg_ports_mgmt_desc"
+f_category portuguese "$msg_portuguese_desc"
+f_category print "$msg_print_desc"
+f_category python "$msg_python_desc"
+f_category ruby "$msg_ruby_desc"
+f_category rubygems "$msg_rubygems_desc"
+f_category russian "$msg_russian_desc"
+f_category scheme "$msg_scheme_desc"
+f_category science "$msg_science_desc"
+f_category security "$msg_security_desc"
+f_category shells "$msg_shells_desc"
+f_category spanish "$msg_spanish_desc"
+f_category sysutils "$msg_sysutils_desc"
+f_category tcl "$msg_tcl_desc"
+f_category textproc "$msg_textproc_desc"
+f_category tk "$msg_tk_desc"
+f_category ukrainian "$msg_ukrainian_desc"
+f_category vietnamese "$msg_vietnamese_desc"
+f_category windowmaker "$msg_windowmaker_desc"
+f_category www "$msg_www_desc"
+f_category x11 "$msg_x11_desc"
+f_category x11-clocks "$msg_x11_clocks_desc"
+f_category x11-drivers "$msg_x11_drivers_desc"
+f_category x11-fm "$msg_x11_fm_desc"
+f_category x11-fonts "$msg_x11_fonts_desc"
+f_category x11-servers "$msg_x11_servers_desc"
+f_category x11-themes "$msg_x11_themes_desc"
+f_category x11-toolkits "$msg_x11_toolkits_desc"
+f_category x11-wm "$msg_x11_wm_desc"
+f_category xfce "$msg_xfce_desc"
+f_category zope "$msg_zope_desc"
+
+f_dprintf "%s: Initialized %u package category descriptions." \
+ packages/categories.subr "$( set -- $CATEGORIES; echo $# )"
+
+f_dprintf "%s: Successfully loaded." packages/categories.subr
+
+fi # ! $_PACKAGES_CATEGORIES_SUBR
diff --git a/usr.sbin/bsdconfig/share/packages/index.subr b/usr.sbin/bsdconfig/share/packages/index.subr
new file mode 100755
index 0000000..9aade0c
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/index.subr
@@ -0,0 +1,244 @@
+if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INLUDING, 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.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." packages/index.subr
+f_include $BSDCFG_SHARE/device.subr
+f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/strings.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ GLOBALS
+
+PACKAGE_INDEX=
+_INDEX_INITTED=
+
+############################################################ FUNCTIONS
+
+# f_index_initialize $path [$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.
+#
+# 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}"
+
+ [ "$_INDEX_INITTED" ] && return $SUCCESS
+ [ "$__path" ] || return $FAILURE
+
+ # Got any media?
+ f_media_verify || return $FAILURE
+
+ # Does it move when you kick it?
+ f_device_init media || return $FAILURE
+
+ f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \
+ "$__path"
+ eval "$__var_to_set"='$( f_device_get media "$__path" | sort )'
+ if [ $? -ne $SUCCESS ]; then
+ f_show_msg "$msg_unable_to_get_file_from_selected_media" \
+ "$__path"
+ f_device_shutdown media
+ return $FAILURE
+ 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"
+ return $FAILURE
+ fi
+
+ _INDEX_INITTED=1
+ return $SUCCESS
+}
+
+# f_index_read [$var_to_get]
+#
+# Process the INDEX file (contents contained in $var_to_get) and...
+#
+# 1. create a list ($CATEGORY_MENU_LIST) of categories with package counts
+# 2. For convenience, create $_npkgs holding the total number of all packages
+# 3. extract associative categories for each package into $_categories_$varpkg
+# 4. extract runtime dependencies for each package into $_rundeps_$varpkg
+# 5. extract a [sorted] list of categories into $PACKAGE_CATEGORIES
+# 6. create $_npkgs_$varcat holding the total number of packages in category
+#
+# NOTE: $varpkg is the product of f_str2varname $package varpkg
+# NOTE: $package is the name as it appears in the INDEX (no archive suffix)
+# NOTE: We only show categories for which there are at least one package.
+# NOTE: $varcat is the product of f_str2varname $category varcat
+#
+f_index_read()
+{
+ local var_to_get="${1:-PACKAGE_INDEX}"
+
+ # Export variables required by awk(1) below
+ export msg_no_description_provided
+ export msg_all msg_all_desc
+ export VALID_VARNAME_CHARS
+
+ eval "$( debug= f_getvar "$var_to_get" | awk -F'|' '
+ function asorti(src, dest)
+ {
+ # Copy src indices to dest and calculate array length
+ nitems = 0; for (i in src) dest[++nitems] = i
+
+ # Sort the array of indices (dest) using insertion sort method
+ for (i = 1; i <= nitems; k = i++)
+ {
+ idx = dest[i]
+ while ((k > 0) && (dest[k] > idx))
+ {
+ dest[k+1] = dest[k]
+ k--
+ }
+ dest[k+1] = idx
+ }
+
+ return nitems
+ }
+ function print_category(category, npkgs, desc)
+ {
+ cat = category
+ # Accent the category if the first page has been
+ # cached (also acting as a visitation indicator)
+ if ( ENVIRON["_index_page_" varcat "_1"] )
+ cat = cat "*"
+ printf "'\''%s'\'' '\''%s packages'\'' '\''%s'\''\n",
+ cat, npkgs, desc
+ }
+ BEGIN {
+ valid_chars = ENVIRON["VALID_VARNAME_CHARS"]
+ default_desc = ENVIRON["msg_no_description_provided"]
+ npkgs = 0
+ prefix = ""
+ }
+ {
+ npkgs++
+ varpkg = $1
+ gsub("[^" valid_chars "]", "_", varpkg)
+ print "_categories_" varpkg "=\"" $7 "\""
+ split($7, pkg_categories, /[[:space:]]+/)
+ for (pkg_category in pkg_categories)
+ categories[pkg_categories[pkg_category]]++
+ print "_rundeps_" varpkg "=\"" $9 "\""
+ }
+ END {
+ print "_npkgs=" npkgs # For convenience, total package count
+
+ n = asorti(categories, categories_sorted)
+
+ # Produce package counts for each category
+ for (i = 1; i <= n; i++)
+ {
+ cat = varcat = categories_sorted[i]
+ npkgs = categories[cat]
+ gsub("[^" valid_chars "]", "_", varcat)
+ print "_npkgs_" varcat "=\"" npkgs "\""
+ }
+
+ # Create menu list and generate list of categories at same time
+ print "CATEGORY_MENU_LIST=\""
+ print_category(ENVIRON["msg_all"], npkgs,
+ ENVIRON["msg_all_desc"])
+ category_list = ""
+ for (i = 1; i <= n; i++)
+ {
+ cat = varcat = categories_sorted[i]
+ npkgs = categories[cat]
+ cur_prefix = tolower(substr(cat, 1, 1))
+ if ( prefix != cur_prefix )
+ prefix = cur_prefix
+ else
+ cat = " " cat
+ gsub("[^" valid_chars "]", "_", varcat)
+ desc = ENVIRON["_category_" varcat]
+ if ( ! desc ) desc = default_desc
+ print_category(cat, npkgs, desc)
+ category_list = category_list " " cat
+ }
+ print "\""
+
+ # Produce the list of categories (calculated in above block)
+ sub(/^ /, "", category_list)
+ print "PACKAGE_CATEGORIES=\"" category_list "\""
+
+ }' )" # End-Quote
+}
+
+# f_index_extract_pages $var_to_get $var_basename $pagesize [$category]
+#
+# Extracts the package INDEX into a series of sequential variables
+# corresponding to "pages" containing up to $pagesize packages. The package
+# INDEX data must be contained in the variable $var_to_get. The extracted pages
+# are stored in variables ${var_basename}_# -- where "#" is a the page number.
+# If $category is set, only packages for that category are extracted.
+# Otherwise, if $category is "All", missing, or NULL, all packages are
+# extracted and no filtering is done.
+#
+f_index_extract_pages()
+{
+ local var_to_get="$1" var_basename="$2" pagesize="$3"
+ local category="$4" # Optional
+
+ eval "$(
+ debug= f_getvar "$var_to_get" | awk -F'|' \
+ -v cat="$category" \
+ -v pagesize="$pagesize" \
+ -v var_basename="$var_basename" '
+ BEGIN { n = page = 0 }
+ /'\''/{ gsub(/'\''/, "'\''\\'\'\''") }
+ {
+ if ( cat !~ /(^$|^All$)/ && $7 !~ \
+ "(^|[[:space:]])" cat "([[:space:]]|$)" ) next
+ starting_new_page = (n++ == (pagesize * page))
+ if ( starting_new_page )
+ printf "%s%s", ( n > 1 ? "'\''\n" : "" ),
+ var_basename "_" ++page "='\''"
+ printf "%s%s", ( starting_new_page ? "" : "\n" ), $0
+ }
+ END { if ( n > 0 ) print "'\''" }'
+ )"
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." packages/index.subr
+
+fi # ! $_PACKAGES_INDEX_SUBR
diff --git a/usr.sbin/bsdconfig/share/packages/packages.subr b/usr.sbin/bsdconfig/share/packages/packages.subr
new file mode 100755
index 0000000..0d602d4
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/packages.subr
@@ -0,0 +1,746 @@
+if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INLUDING, 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.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." "$0"
+f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/strings.subr
+f_include $BSDCFG_SHARE/packages/categories.subr
+f_include $BSDCFG_SHARE/packages/index.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ CONFIGURATION
+
+#
+# How many packages to display (maximum) per dialog menubox.
+#
+: ${PACKAGE_MENU_PAGESIZE:=2000}
+
+############################################################ GLOBALS
+
+PACKAGE_CATEGORIES=
+SELECTED_PACKAGES=
+
+#
+# Options
+#
+[ "${SHOW_DESC+set}" ] || SHOW_DESC=1
+
+############################################################ FUNCTIONS
+
+# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST
+#
+# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see
+# packages/index.subr). Accented information includes adding an asterisk to the
+# category name if its index has been cached, adding the number of installed
+# packages for each category, and adding the number _selected_ packages for
+# each category.
+#
+# NOTE: The reason `eval' is recommended/shown for the syntax above is because
+# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded
+# prior to execution (it contains a series of pre-quoted strings which act as
+# the interpolated command arguments).
+#
+f_package_accent_category_menu()
+{
+ local var_to_set="$1" cat desc help varcat menu_buf n
+ shift 1 # var_to_set
+ while [ $# -gt 0 ]; do
+ cat="${1%\*}" desc="${2%%; *}" help="$3"
+ shift 3 # cat/desc/help
+ f_str2varname "${cat# }" varcat
+
+ # Add an asterisk to the category if its index has been cached
+ f_isset _index_page_${varcat}_1 && cat="$cat*"
+
+ # Add number of installed packages for this category (if any)
+ n=0
+ debug= f_getvar "_${varcat}_ninstalled" n &&
+ [ $n -ge 1 ] && desc="$desc; $n installed"
+
+ # Add number of selected packages for this category (if any)
+ n=0
+ debug= f_getvar "_${varcat}_nselected" n &&
+ [ $n -ge 1 ] && desc="$desc; $n selected"
+
+ # Update buffer with modified elements
+ menu_buf="$menu_buf
+ '$cat' '$desc' '$help'" # End-Quote
+ done
+ setvar "$var_to_set" "$menu_buf" # return our buffer
+}
+
+# f_package_select $package ...
+#
+# Add $package to the list of tracked/selected packages. If $package is already
+# being tracked (already apears in $SELECTED_PACKAGES), this function amounts
+# to having no effect.
+#
+f_package_select()
+{
+ local package pkgsel
+ while [ $# -gt 0 ]; do
+ package="$1"
+ shift 1 # package
+ for pkgsel in $SELECTED_PACKAGES; do
+ [ "$package" = "$pkgsel" ] && return
+ done
+ SELECTED_PACKAGES="$SELECTED_PACKAGES $package"
+ done
+ SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space
+}
+
+# f_package_deselect $package ...
+#
+# Remove $package from teh list of tracked/selected packages. If $package is
+# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function
+# amounts to having no effet.
+#
+f_package_deselect()
+{
+ local package pkgsel
+ while [ $# -gt 1 ]; do
+ local new_list=""
+ package="$1"
+ shift 1 # package
+ for pkgsel in $SELECTED_PACKAGES; do
+ [ "$pkgsel" = "$package" ] && continue
+ new_list="$new_list${new_list:+ }$pkgsel"
+ done
+ SELECTED_PACKAGES="$new_list"
+ done
+}
+
+# f_package_detect_installed
+#
+# Detect installed packages. Currently this searches /var/db/pkg for directory
+# entries and marks each entry as an installed/selected package.
+#
+f_package_detect_installed()
+{
+ local installed package varpkg
+ installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d |
+ sed -e 's:/var/db/pkg/::' )
+ for package in $installed; do
+ f_str2varname $package varpkg
+ export _mark_$varpkg=X # exported for awk(1) ENVIRON[]
+ f_package_select $package
+ done
+}
+
+# f_package_calculate_totals
+#
+# Calculate number of installed/selected packages for each category listed in
+# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored
+# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname
+# $category varcat' -- and number selected packages as $_${varcat}_nselected).
+# Also calculates the total number of installed/selected packages stored as
+# $_All_ninstalled and $_All_nselected.
+#
+# Calculations are peformed by checking "marks". A "mark" is stored as
+# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package
+# varpkg'. A mark can be "X" for an installed package, `I' for a package that
+# is marked for installation, "R" for a package that is marked for re-install,
+# and "U" for a package that is marked for uninstallation. If a package mark is
+# NULL or a single space (e.g., " "), the package is considered to be NOT
+# selected (and therefore does not increment the counts calculated herein).
+#
+f_package_calculate_totals()
+{
+ local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0
+ for cat in $PACKAGE_CATEGORIES; do
+ f_str2varname $cat varcat
+ setvar _${varcat}_ninstalled=0
+ setvar _${varcat}_nselected=0
+ done
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ f_getvar _mark_$varpkg mark
+ case "$mark" in
+ ""|" ") : ;;
+ X) tinstalled=$(( $tinstalled + 1 ));;
+ *) tselected=$(( $tselected + 1 ))
+ esac
+ f_getvar _categories_$varpkg pkgcat
+ for cat in $pkgcat; do
+ f_str2varname $cat varcat
+ case "$mark" in
+ ""|" ") : ;;
+ X) debug= f_getvar _${varcat}_ninstalled n
+ setvar _${varcat}_ninstalled $(( $n + 1 ));;
+ *) debug= f_getvar _${varcat}_nselected n
+ setvar _${varcat}_nselected $(( $n + 1 ))
+ esac
+ done
+ done
+ _All_nselected=$tselected
+ _All_ninstalled=$tinstalled
+}
+
+# f_package_calculate_rundeps
+#
+# Update package dependencies by first unmarking all dependencies and then
+# re-marking all dependencies of packages marked for either install ("I") or
+# re-install ("R").
+#
+f_package_calculate_rundeps()
+{
+ local pkg varpkg mark rundeps dep vardep
+
+ #
+ # First unmark all the existing run-dependencies
+ #
+ f_dprintf "Unselecting package run-dependencies..."
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ debug= f_getvar _mark_$varpkg mark
+ # Only unmark if it's marked as a Dependency
+ if [ "$mark" = "D" ]; then
+ f_dprintf "%s unselected" $pkg
+ unset _mark_$varpkg
+ f_package_deselect $pkg
+ fi
+ done
+
+ #
+ # Processes selected packages, adding dependencies
+ #
+ f_dprintf "Re-selecting package run-dependencies..."
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ debug= f_getvar _mark_$varpkg mark
+ # Skip pkg unless marked for [Re-]Install
+ [ "$mark" = "I" -o "$mark" = "R" ] || continue
+ f_getvar _rundeps_$varpkg rundeps
+ for dep in $rundeps; do
+ f_str2varname $dep vardep
+ mark=
+ debug= f_getvar _mark_$vardep mark
+ # Skip dep if already marked
+ [ "${mark:- }" = " " ] || continue
+ export _mark_$vardep="D"
+ f_package_select $dep
+ done
+ done
+
+ f_dprintf "Finished recalculating dependencies."
+}
+
+# f_package_menu_categories $var_to_set $defaultitem
+#
+# Dislay the menu of package categories, complete with package counts for each
+# category, accents, and other miscellany. If $defaultitem is non-NULL and
+# matches one of the existing menu-items, it will be pre-highlighted in the
+# menu dialog (HINT: Use f_dialog_menutag() to populate a local variable that
+# is passed as $defaultitem to highlight the user's last selection by default).
+#
+f_package_menu_categories()
+{
+ local var_to_get="$1" defaultitem="$2" category_list menu_list
+
+ f_package_calculate_rundeps
+ # updates package mark variables and SELECTED_PACKAGES
+ f_package_calculate_totals
+ # creates _{varcat}_ninstalled and _{varcat}_nselected
+
+ debug= f_getvar "$var_to_get" category_list || return $FAILURE
+
+ # Accent the category menu list with ninstalled/nselected
+ eval f_package_accent_category_menu category_list $category_list
+
+ local prompt="$msg_please_select_a_category_to_display"
+ local hline=""
+
+ menu_list="
+ '> $msg_review' '$msg_review_desc' '$msg_review_help'
+ $category_list
+ " # End-Quote
+
+ local size dialog_menu
+ size=$( eval f_dialog_menu_with_help_size \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list )
+ dialog_menu=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --item-help \
+ --default-item \"\$defaultitem\" \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_cancel\" \
+ --menu \"\$prompt\" $size \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ setvar DIALOG_MENU_$$ "$dialog_menu"
+ return $retval
+}
+
+# f_package_index_get_page $category $page [$var_to_set [$var_to_get]]
+#
+# Obtain a [potentially cached] page of the INDEX file for a given $category.
+# If $page is 1 and the cache has not yet been generated, the cache-generating
+# function f_index_extract_pages() (above) is called to generate all pages
+# (not just the requested page) in cache before returning the requested page.
+# If $page is not 1 and there is no cached page, failure status is returned.
+#
+f_package_index_get_page()
+{
+ local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat
+ f_str2varname "$category" varcat
+ if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set &&
+ [ "$page" = "1" ]
+ then
+ f_show_info "$msg_building_package_menus"
+ local pagesize="$PACKAGE_MENU_PAGESIZE"
+ f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \
+ _index_page_${varcat} "$pagesize" "$category"
+ debug= f_getvar _index_page_${varcat}_$page $var_to_set
+
+ # Update category default-item because now we're cached
+ [ $page -eq 1 ] &&
+ category_defaultitem="${category_defaultitem%\*}*"
+ else
+ return $FAILURE
+ fi
+}
+
+# f_package_menu_select $category [ $page [ $defaultitem ] ]
+#
+# Display list of packages for $category, optionally $page N and with a default
+# item selected. If $page is omitted, the first page is displayed (but this
+# only matters if there are multiple pages; which is determined by the global
+# maximum $PACKAGE_MENU_PAGESIZE).
+#
+# On success, if the user doesn't press ESC or choose Cancel, the environment
+# variable $DIALOG_MENUITEM_$$ will hold the item associated with the chosen
+# tag (accessible through f_dialog_menutag()).
+#
+f_package_menu_select()
+{
+ local category="$1" page="${2:-1}" defaultitem="$3"
+ local varcat npkgs=0 npages menu_list
+
+ f_isinteger "$page" || return $FAILURE
+
+ f_str2varname "$category" varcat
+ f_package_index_get_page "$category" $page index_page
+
+ # Get number of packages for this category
+ case "$category" in
+ "All"|"") npkgs="${_npkgs:-0}";;
+ *) f_getvar _npkgs_$varcat npkgs
+ esac
+
+ # Calculate number of pages
+ npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
+
+ # Add a page to the pagecount if not evenly divisible
+ [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] &&
+ npages=$(( $npages + 1 ))
+
+ # Print some debugging information
+ f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \
+ "$category" "$npkgs" "$npages"
+
+ local add_prev="" add_next=""
+ local previous_page="$msg_previous_page" next_page="$msg_next_page"
+ if [ $page -gt 1 ]; then
+ add_prev=1
+ # Accent the `Previous Page' item with an asterisk
+ # if the page-before-previous is loaded/cached
+ f_isset _index_page_${varcat}_$(( $page - 1 )) &&
+ previous_page="$previous_page*"
+ fi
+ if [ $page -lt $npages ]; then
+ add_next=1
+ # Accent the `Next Page' item with an asterisk
+ # if the page-after-next is loaded/cached
+ f_isset _index_page_${varcat}_$(( $page + 1 )) &&
+ next_page="$next_page*"
+ fi
+
+ menu_list="
+ ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
+ ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
+ $(
+ export SHOW_DESC
+ export VALID_VARNAME_CHARS
+ echo "$index_page" | awk -F'|' -v view="port" '
+ BEGIN {
+ valid_chars = ENVIRON["VALID_VARNAME_CHARS"]
+ prefix = ""
+ }
+ {
+ cur_prefix = tolower(substr($1, 1, 1))
+ printf "'\''"
+ if ( prefix != cur_prefix )
+ prefix = cur_prefix
+ else
+ printf " "
+ package = $1
+ if ( view == "port" )
+ desc = $2
+ varpkg = package
+ gsub("[^" valid_chars "]", "_", varpkg)
+ mark = ENVIRON["_mark_" varpkg]
+ if ( ! mark ) mark = " "
+ printf "%s'\'' '\''[%c] %s'\''",
+ package, mark, desc
+ if ( ENVIRON["SHOW_DESC"] ) {
+ help = $4
+ gsub(/'\''/, "'\''\\'\'\''", help)
+ printf " '\''%s'\''", help
+ }
+ printf "\n"
+ }'
+ )
+ ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
+ ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
+ " # End-Quote
+
+ local prompt=""
+ f_category_desc_get "$category" prompt
+ prompt="$prompt $( printf "$msg_page_of_npages" \
+ "$page" "$npages" )"
+
+ local hline="$hline_arrows_tab_punc_enter"
+ local size isize dialog_menu item
+ size=$( eval f_dialog_menu${SHOW_DESC:+_with_help}_size \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list )
+ isize=$( f_dialog_infobox_size \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$msg_processing_selection" )
+ dialog_menu=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --keep-tite \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_back\" \
+ ${SHOW_DESC:+--item-help} \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" $size \
+ $menu_list \
+ --and-widget \
+ ${USE_XDIALOG:+--no-buttons} \
+ --infobox \"\$msg_processing_selection\" $isize \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ setvar DIALOG_MENU_$$ "$dialog_menu"
+
+ if [ $retval -eq $SUCCESS ]; then
+ item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \
+ \"\$dialog_menu\" $menu_list )
+ setvar DIALOG_MENUITEM_$$ "$item"
+ fi
+
+ return $retval
+}
+
+# f_package_menu_deselect $package
+#
+# Display a menu, asking the user what they would like to do with $package
+# with regard to "deselecting" an already installed package. Choices include
+# uninstall, re-install, or cancel (leave $package marked as installed).
+# Returns success if the user does not press ESC or choose Cnacel. Use the
+# f_dialog_menutag() function upon success to retrieve the user's choice.
+#
+f_package_menu_deselect()
+{
+ local package="$1" prompt menu_list size dialog_menu
+ prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
+ local hline="$hline_alnum_arrows_punc_tab_enter"
+ menu_list="
+ 'X $msg_installed' '$msg_installed_desc'
+ 'R $msg_reinstall' '$msg_reinstall_desc'
+ 'U $msg_uninstall' '$msg_uninstall_desc'
+ " # End-Quote
+ size=$( eval f_dialog_menu_size \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list )
+ dialog_menu=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_cancel\" \
+ --menu \"\$prompt\" $size \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ setvar DIALOG_MENU_$$ "$dialog_menu"
+ return $retval
+}
+
+# f_package_review
+#
+# Display a review screen, showing selected packages and what they are marked
+# for, before proceeding (if the user does not press ESC or choose Cancel) to
+# operate on each selection. Returns error if no packages have been selected,
+# or the user has pressed ESC, or if they have chosen Cancel.
+#
+f_package_review()
+{
+ local prompt size dialog_menu package varpkg mark menu_list=
+ prompt=$( printf "$msg_reviewing_selected_packages" \
+ "$_All_nselected" )
+ local hline="$hline_alnum_arrows_punc_tab_enter"
+ f_dprintf "f_package_review: SELECTED_PACKAGES=[%s]" \
+ "$SELECTED_PACKAGES"
+ for package in $SELECTED_PACKAGES; do
+ mark=
+ f_str2varname "$package" varpkg
+ f_getvar _mark_$varpkg mark
+ [ "$mark" -a ! "${mark#[IRUD]}" ] || continue
+ menu_list="$menu_list
+ '$mark' '$package'
+ " # End-Quote
+ done
+ if [ ! "$menu_list" ]; then
+ f_show_msg "$msg_no_packages_were_selected_for_extraction"
+ return $FAILURE # They might have selected this by accident
+ fi
+ menu_list=$( echo "$menu_list" | sort )
+ size=$( eval f_dialog_menu_size \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list )
+ dialog_menu=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_proceed\" \
+ --cancel-label \"\$msg_cancel\" \
+ --menu \"\$prompt\" $size \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ setvar DIALOG_MENU_$$ "$dialog_menu"
+
+ #
+ # XXX
+ #
+ f_show_msg "Coming soon..."
+ #
+ # XXX
+ #
+
+ return $retval
+}
+
+# f_package_config
+#
+# Allow the user to configure packages and install them. Initially, a list of
+# package categories is loaded/displayed. When the user selects a category,
+# the menus for that category are built (unlike sysinstall which built all
+# category menus up-front -- which also took forever, despite the fact that
+# few people visit more than a couple of categories each time).
+#
+f_package_config()
+{
+ # Did we get an INDEX?
+ f_index_initialize packages/INDEX || return $FAILURE
+ # Creates following variables (indirectly via f_index_read())
+ # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg}
+ # PACKAGE_CATEGORIES _npkgs
+
+ # Detect installed packages (updates marks/SELECTED_PACKAGES)
+ f_package_detect_installed
+
+ local retval category varcat defaultitem category_defaultitem=""
+ while :; do
+ # Display the list of package categories
+ f_package_menu_categories \
+ CATEGORY_MENU_LIST "$category_defaultitem"
+ retval=$?
+ category=$( f_dialog_menutag )
+ f_dprintf "retval=%u mtag=[%s]" $retval "$category"
+ category_defaultitem="$category"
+
+ [ $retval -eq $SUCCESS ] || break
+
+ # Maybe the user chose an action (like `Review')
+ case "$category" in
+ "> $msg_review")
+ f_package_review && break
+ continue ;;
+ "> "*)
+ continue
+ esac
+
+ # Anything else is a package category
+
+ category=${category# } # Trim leading space if present
+ category=${category%\*} # Trim trailing asterisk if present
+
+ f_str2varname "$category" varcat
+
+ local page package varpkg mark
+ while :; do
+ # Display the list of packages for selected category
+ page=1 defaultitem=""
+ f_getvar _defaultitem_$varcat defaultitem
+ f_getvar _defaultpage_$varcat page
+ f_package_menu_select \
+ "$category" "${page:=1}" "$defaultitem"
+ retval=$?
+ dialog_menu=$( f_dialog_menutag )
+ f_dprintf "retval=%u mtag=[%s]" $retval "$dialog_menu"
+
+ # NOTE: When --and-widget is used only ESC will cause
+ # dialog(1) to return without going to the next widget.
+ # This is alright in our case as we can still detect
+ # the Cancel button because stdout will be NULL.
+ # Alternatively, Xdialog(1) will terminate with 1
+ # if/when Cancel is chosen on any widget.
+ if [ $retval -eq 255 -o ! "$dialog_menu" ]; then
+ # User pressed ESC or chose Cancel
+ break
+ elif [ $retval -eq 1 ]; then
+ # Using X11, Xdialog(1) returned 1 for Cancel
+ f_show_msg "%s" "$dialog_menu"
+ break
+ elif [ $retval -ne $SUCCESS ]; then
+ # X11-related error occurred using Xdialog(1)
+ f_show_msg "%s" "$dialog_menu"
+ break
+ fi
+
+ defaultitem="$dialog_menu"
+
+ # NOTE: f_package_menu_select() does not show the
+ # `Previous Page' or `Next Page' items unless needed
+ case "$dialog_menu" in
+ "> $msg_previous_page"|"> $msg_previous_page*")
+ page=$(( $page - 1 ))
+ setvar _defaultpage_$varcat $page
+ # Update default-item to match accent that will
+ # be applied by f_package_menu_select(); if the
+ # page-before-prev is cached, add an asterisk.
+ if f_isset \
+ _index_page_${varcat}_$(( $page - 1 ))
+ then
+ defaultitem="${defaultitem%\*}*"
+ else
+ defaultitem="${defaultitem%\*}"
+ fi
+ setvar _defaultitem_$varcat "$defaultitem"
+ continue ;;
+ "> $msg_next_page"|"> $msg_next_page*")
+ page=$(( $page + 1 ))
+ setvar _defaultpage_$varcat $page
+ # Update default-item to match accent that will
+ # be applied by f_package_menu_select(); if the
+ # page-after-next is cached, add an asterisk.
+ if f_isset \
+ _index_page_${varcat}_$(( $page + 1 ))
+ then
+ defaultitem="${defaultitem%\*}*"
+ else
+ defaultitem="${defaultitem%\*}"
+ fi
+ setvar _defaultitem_$varcat "$defaultitem"
+ continue ;;
+ "> "*) # Unknown navigation/action item
+ setvar _defaultpage_$varcat $page
+ continue ;; # Do not treat as a package
+ *)
+ setvar _defaultitem_$varcat "$defaultitem"
+ esac
+
+ # Treat any other selection as a package
+ package="${dialog_menu# }" # Trim leading space
+ f_str2varname $package varpkg
+ f_getvar DIALOG_MENUITEM_$$ mark
+ mark="${mark#?}"
+ mark="${mark%%\] *}"
+ case "$mark" in
+ "I")
+ mark=" "
+ f_package_deselect $package
+ ;;
+ " "|"D")
+ mark="I"
+ f_package_select $package
+ ;;
+ "X"|"R"|"U")
+ f_package_menu_deselect $package || continue
+ dialog_menu=$( f_dialog_menutag )
+ case "$dialog_menu" in
+ "X $msg_installed")
+ f_package_deselect "$package"
+ mark="X"
+ ;;
+ "R $msg_reinstall")
+ f_package_select "$package"
+ mark="R"
+ ;;
+ "U $msg_uninstall")
+ f_package_select "$package"
+ mark="U"
+ ;;
+ esac
+ ;;
+ esac
+ export _mark_$varpkg="$mark"
+ # NOTE: exported for awk(1) ENVIRON[]
+ done
+ done
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." packages/packages.subr
+
+fi # ! $_PACKAGES_PACKAGES_SUBR
diff --git a/usr.sbin/bsdconfig/share/script.subr b/usr.sbin/bsdconfig/share/script.subr
index ece34cf..1943be2 100644
--- a/usr.sbin/bsdconfig/share/script.subr
+++ b/usr.sbin/bsdconfig/share/script.subr
@@ -35,6 +35,7 @@ f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/any.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
+f_include $BSDCFG_SHARE/packages/packages.subr
############################################################ GLOBALS
@@ -188,6 +189,9 @@ f_resword_new mediaSetFTPUserPass f_media_set_ftp_userpass
f_resword_new mediaSetHTTP f_media_set_http_proxy
f_resword_new mediaSetHTTPProxy f_media_set_http_proxy
+# packages/packages.subr
+f_resword_new configPackages f_package_config
+
f_dprintf "%s: Successfully loaded." script.subr
fi # ! $_SCRIPT_SUBR
diff --git a/usr.sbin/bsdconfig/share/variable.subr b/usr.sbin/bsdconfig/share/variable.subr
index 7a066421..f51ebd6 100644
--- a/usr.sbin/bsdconfig/share/variable.subr
+++ b/usr.sbin/bsdconfig/share/variable.subr
@@ -117,6 +117,7 @@ f_variable_set_defaults()
setvar $VAR_NFS_SECURE "NO"
setvar $VAR_NFS_TCP "NO"
setvar $VAR_NFS_V3 "YES"
+ setvar $VAR_PKG_TMPDIR "/var/tmp"
setvar $VAR_RELNAME "$UNAME_R"
f_dprintf "f_variable_set_defaults: Defaults initialized."
@@ -224,8 +225,12 @@ f_variable_new VAR_NFS_SECURE nfs_reserved_port_only
f_variable_new VAR_NFS_TCP nfs_use_tcp
f_variable_new VAR_NFS_V3 nfs_use_v3
f_variable_new VAR_NONINTERACTIVE nonInteractive
+f_variable_new VAR_NO_CONFIRM noConfirm
f_variable_new VAR_NO_ERROR noError
f_variable_new VAR_NO_INET6 noInet6
+f_variable_new VAR_PACKAGE package
+f_variable_new VAR_PKG_TMPDIR PKG_TMPDIR
+f_variable_new VAR_PORTS_PATH ports
f_variable_new VAR_RELNAME releaseName
f_variable_new VAR_SLOW_ETHER slowEthernetCard
f_variable_new VAR_TRY_DHCP tryDHCP
OpenPOWER on IntegriCloud