head	1.38;
access;
symbols
	RELENG_9:1.38.0.2;
locks; strict;
comment	@# @;


1.38
date	2013.07.06.01.07.53;	author svnexp;	state Exp;
branches
	1.38.2.1;
next	1.37;

1.37
date	2013.07.06.01.07.09;	author svnexp;	state Exp;
branches;
next	1.36;

1.36
date	2013.07.06.00.58.56;	author svnexp;	state Exp;
branches;
next	1.35;

1.35
date	2013.07.06.00.57.28;	author svnexp;	state Exp;
branches;
next	1.34;

1.34
date	2013.06.25.00.35.22;	author svnexp;	state Exp;
branches;
next	1.33;

1.33
date	2013.06.25.00.34.37;	author svnexp;	state Exp;
branches;
next	1.32;

1.32
date	2013.06.21.00.27.05;	author svnexp;	state Exp;
branches;
next	1.31;

1.31
date	2013.06.20.03.23.11;	author svnexp;	state Exp;
branches;
next	1.30;

1.30
date	2013.06.16.00.37.34;	author svnexp;	state Exp;
branches;
next	1.29;

1.29
date	2013.06.05.00.30.29;	author svnexp;	state Exp;
branches;
next	1.28;

1.28
date	2013.06.03.00.48.49;	author svnexp;	state Exp;
branches;
next	1.27;

1.27
date	2013.06.03.00.44.56;	author svnexp;	state Exp;
branches;
next	1.26;

1.26
date	2013.06.03.00.44.12;	author svnexp;	state Exp;
branches;
next	1.25;

1.25
date	2013.06.03.00.43.28;	author svnexp;	state Exp;
branches;
next	1.24;

1.24
date	2013.06.03.00.32.49;	author svnexp;	state Exp;
branches;
next	1.23;

1.23
date	2013.06.02.00.37.30;	author svnexp;	state Exp;
branches;
next	1.22;

1.22
date	2013.06.01.00.35.21;	author svnexp;	state Exp;
branches;
next	1.21;

1.21
date	2013.05.15.00.26.05;	author svnexp;	state Exp;
branches;
next	1.20;

1.20
date	2013.04.23.00.30.01;	author svnexp;	state Exp;
branches;
next	1.19;

1.19
date	2013.04.23.00.29.17;	author svnexp;	state Exp;
branches;
next	1.18;

1.18
date	2013.04.23.00.27.07;	author svnexp;	state Exp;
branches;
next	1.17;

1.17
date	2013.01.15.00.26.09;	author svnexp;	state Exp;
branches;
next	1.16;

1.16
date	2013.01.07.00.34.18;	author svnexp;	state Exp;
branches;
next	1.15;

1.15
date	2013.01.06.00.26.20;	author svnexp;	state Exp;
branches;
next	1.14;

1.14
date	2012.12.25.11.03.38;	author svnexp;	state Exp;
branches;
next	1.13;

1.13
date	2012.12.25.09.37.00;	author svnexp;	state Exp;
branches;
next	1.12;

1.12
date	2012.12.21.19.30.51;	author svnexp;	state Exp;
branches;
next	1.11;

1.11
date	2012.11.17.04.41.47;	author svnexp;	state Exp;
branches;
next	1.10;

1.10
date	2012.11.17.01.54.38;	author svnexp;	state Exp;
branches;
next	1.9;

1.9
date	2012.10.26.00.31.25;	author dteske;	state Exp;
branches;
next	1.8;

1.8
date	2012.10.25.21.04.11;	author dteske;	state Exp;
branches;
next	1.7;

1.7
date	2012.10.22.18.01.38;	author dteske;	state Exp;
branches;
next	1.6;

1.6
date	2012.10.18.18.43.54;	author dteske;	state Exp;
branches;
next	1.5;

1.5
date	2012.09.21.19.03.25;	author dteske;	state Exp;
branches;
next	1.4;

1.4
date	2012.09.21.01.36.20;	author dteske;	state Exp;
branches;
next	1.3;

1.3
date	2012.09.20.23.44.13;	author dteske;	state Exp;
branches;
next	1.2;

1.2
date	2012.09.18.22.28.42;	author dteske;	state Exp;
branches;
next	1.1;

1.1
date	2012.07.14.03.16.57;	author dteske;	state Exp;
branches;
next	;

1.38.2.1
date	2013.07.06.01.07.53;	author svnexp;	state dead;
branches;
next	1.38.2.2;

1.38.2.2
date	2013.07.07.20.03.17;	author svnexp;	state Exp;
branches;
next	1.38.2.3;

1.38.2.3
date	2014.03.27.04.02.36;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.38
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252849
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-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 (INCLUDING, 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: head/usr.sbin/bsdconfig/bsdconfig 252849 2013-07-05 22:25:40Z dteske $
#
############################################################ INCLUDES

# When common.subr is included, it automatically scans "$@@" for `-d' and/or
# `-D file' arguments to conditionally enable debugging. Similarly, when
# dialog.subr is included, it automatically scans "$@@" for `-X' and/or `-S'.
# To prevent this scanning from becoming confused by extra options, define
# any/all extra arguments to use in the optstring to getopts when scanning
# for dedicated options such as those described.
#
# NOTE: This needs to be declared before including `common.subr'.
# NOTE: You really only need to list flags that require an argument as unknown
#       flags are silently accepted unless they take an argument (in which case
#       the following argument will terminate option processing unless it looks
#       like a flag).
#
GETOPTS_EXTRA="f:"

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/mustberoot.subr
f_include $BSDCFG_SHARE/strings.subr

BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr

BSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp
USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp

############################################################ CONFIGURATION

#
# Alternate `local' libexec directory for add-on modules (e.g., from ports)
#
BSDCFG_LOCAL_LIBE="/usr/local/libexec/bsdconfig"

############################################################ FUNCTIONS

# usage
#
# display usage and exit
#
usage()
{
	local index="INDEX"
	local cmd_list # Calculated below

	cd $BSDCFG_LIBE
		# No need to preserve CWD (headed toward exit)

	# Test for language-specific indices
	f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
		index="$index.${LANG:-$LC_ALL}"

	cmd_list=$(
		awk '/^menu_selection="/ {
			sub(/\|.*/, "")
			sub(/^menu_selection="/, "")
			print
		}' */$index | sort
	)

	local alt_cmd_list # Calculated below (if $BSDCFG_LOCAL_LIBE exists)
	if f_quietly cd $BSDCFG_LOCAL_LIBE; then
		# No need to preserve CWD (headed toward exit)

		# Test for language-specific indices
		f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
			index="$index.${LANG:-$LC_ALL}"

		alt_cmd_list=$(
			awk '/^menu_selection="/ {
				sub(/\|.*/, "")
				sub(/^menu_selection="/, "")
				print
			}' */$index 2> /dev/null | sort
		)

		# Conflate lists, removing duplicates
		cmd_list=$( printf "%s\n%s\n" \
		                   "$cmd_list" "$alt_cmd_list" | sort -u )
	fi

	#
	# Determine the longest command-length (in characters)
	#
	local longest_cmd
	longest_cmd=$( echo "$cmd_list" | f_longest_line_length )
	f_dprintf "longest_cmd=[%s]" "$longest_cmd"

	#
	# Determine the maximum width of terminal/console
	#
	local max_size="$( stty size 2> /dev/null )"
	: ${max_size:="24 80"}
	local max_width="${max_size#*[$IFS]}"
	f_dprintf "max_width=[%s]" "$max_width"

	#
	# Using the longest command-length as the width of a single column,
	# determine if we can use more than one column to display commands.
	#
	local x=$longest_cmd ncols=1
	x=$(( $x + 8 )) # Accomodate leading tab character
	x=$(( $x + 3 + $longest_cmd )) # Preload end of next column
	while [ $x -lt $max_width ]; do
		ncols=$(( $ncols + 1 ))
		x=$(( $x + 3 + $longest_cmd ))
	done
	f_dprintf "ncols=[%u] x=[%u]" $ncols $x

	#
	# Re-format the command-list into multiple columns
	#
	cmd_list=$( eval "$( echo "$cmd_list" |
		awk -v ncols=$ncols -v size=$longest_cmd '
		BEGIN {
			n = 0
			row_item[1] = ""
		}
		function print_row()
		{
			fmt = "printf \"\\t%-" size "s"
			for (i = 1; i < cur_col; i++)
				fmt = fmt "   %-" size "s"
			fmt = fmt "\\n\""
			printf "%s", fmt
			for (i = 1; i <= cur_col; i++)
				printf " \"%s\"", row_item[i]
			print ""
		}
		{
			n++
			cur_col = (( n - 1 ) % ncols ) + 1
			printf "f_dprintf \"row_item[%u]=[%%s]\" \"%s\"\n",
			       cur_col, $0
			row_item[cur_col] = $0
			if ( cur_col == ncols ) print_row()
		}
		END {
			if ( cur_col < ncols ) print_row()
		}' )"
	)

	f_usage $BSDCFG_LIBE/USAGE \
	        "PROGRAM_NAME" "$pgm" \
	        "COMMAND_LIST" "$cmd_list"

	# Never reached
}

# dialog_menu_main
#
# Display the dialog(1)-based application main menu.
#
dialog_menu_main()
{
	local title="$DIALOG_TITLE"
	local btitle="$DIALOG_BACKTITLE"
	local prompt="$msg_menu_text"
	local menu_list="
		'X' '$msg_exit'  '$msg_exit_bsdconfig'
		'1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system'
	" # END-QUOTE
	local defaultitem= # Calculated below
	local hline=

	#
	# Pick up the base modules (directories named `[0-9][0-9][0-9].*')
	#
	local menuitem menu_title menu_help menu_selection index=2
	for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do
		[ -f "$BSDCFG_LIBE/$menuitem/INDEX" ] || continue
		[ $index -lt ${#DIALOG_MENU_TAGS} ] || break

		menu_program= menu_title= menu_help=
		f_include_lang $BSDCFG_LIBE/$menuitem/INDEX
		[ "$menu_program" ] || continue

		case "$menu_program" in
		/*) : already fully qualified ;;
		 *) menu_program="$menuitem/$menu_program"
		esac

		tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
		setvar "menu_program$tag" "$menu_program"

		f_shell_escape "$menu_title" menu_title
		f_shell_escape "$menu_help" menu_help
		menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"

		index=$(( $index + 1 ))
	done

	#
	# Process the `local' libexec sources.
	#
	# Whereas modules in $BSDCFG_LIBE must be named [0-9][0-9][0-9].*
	# modules in $BSDCFG_LOCAL_LIBE should NOT be named this way (making it
	# more practical for port-maintainers).
	#
	# This also has the fortunate side-effect of making the de-duplication
	# effort rather simple (because so-called `base' modules must be named
	# differently than add-on modules).
	#
	local separator_added=
	for menuitem in $( cd "$BSDCFG_LOCAL_LIBE" 2> /dev/null && ls -d * )
	do
		# Skip the module if it looks like a `base' module
		case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac

		[ -f "$BSDCFG_LOCAL_LIBE/$menuitem/INDEX" ] || continue
		[ $index -lt ${#DIALOG_MENU_TAGS} ] || break

		menu_program= menu_title= menu_help=
		f_include_lang $BSDCFG_LOCAL_LIBE/$menuitem/INDEX || continue
		[ "$menu_program" ] || continue

		if [ ! "$separator_added" ]; then
			menu_list="$menu_list '-' '-' ''"
			separator_added=1
		fi

		case "$menu_program" in
		/*) : already fully qualified ;;
		 *) menu_program="$BSDCFG_LOCAL_LIBE/$menuitem/$menu_program"
		esac

		tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
		setvar "menu_program$tag" "$menu_program"

		f_shell_escape "$menu_title" menu_title
		f_shell_escape "$menu_help" menu_help
		menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"

		index=$(( $index + 1 ))
	done

	local height width rows
	eval f_dialog_menu_with_help_size height width rows \
	                                  \"\$title\"  \
	                                  \"\$btitle\" \
	                                  \"\$prompt\" \
	                                  \"\$hline\"  \
	                                  $menu_list

	# Obtain default-item from previously stored selection
	f_dialog_default_fetch defaultitem

	local menu_choice
	menu_choice=$( eval $DIALOG \
		--clear                                 \
		--title \"\$title\"                     \
		--backtitle \"\$btitle\"                \
		--hline \"\$hline\"                     \
		--item-help                             \
		--ok-label \"\$msg_ok\"                 \
		--cancel-label \"\$msg_exit_bsdconfig\" \
		--help-button                           \
		--help-label \"\$msg_help\"             \
		${USE_XDIALOG:+--help \"\"}             \
		--default-item \"\$defaultitem\"        \
		--menu \"\$prompt\"                     \
		$height $width $rows                    \
		$menu_list                              \
		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
	)
	local retval=$?
	f_dialog_data_sanitize menu_choice
	f_dialog_menutag_store "$menu_choice"

	# Only update default-item on success
	[ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"

	return $retval
}

############################################################ MAIN

#
# If $0 is not "bsdconfig", interpret it either as a keyword to a menuitem or
# as a valid resword (see script.subr for additional details about reswords).
#
if [ "$pgm" != "bsdconfig" ]; then
	if indexfile=$( f_index_file "$pgm" ) &&
	   cmd=$( f_index_menusel_command "$indexfile" "$pgm" )
	then
		f_dprintf "pgm=[%s] indexfile=[%s] cmd=[%s]" \
		          "$pgm" "$indexfile" "$cmd"
		exec "$cmd" "$@@" || exit 1
	else
		f_include $BSDCFG_SHARE/script.subr
		for resword in $RESWORDS; do
			[ "$pgm" = "$resword" ] || continue
			# Found a match
			f_dprintf "pgm=[%s] A valid resWord!" "$pgm"
			f_dispatch $resword
			exit $?
		done
	fi
fi

#
# Process command-line arguments
#
scripts_loaded=0
while getopts f:h$GETOPTS_STDARGS flag; do
	case "$flag" in
	f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr
	   f_script_load "$OPTARG"
	   scripts_loaded=$(( $scripts_loaded + 1 )) ;;
	h|\?) usage ;;
	esac
done
shift $(( $OPTIND -1 ))

# If we've loaded any scripts, do not continue any further
[ $scripts_loaded -gt 0 ] && exit

#
# Initialize
#
f_dialog_title "$msg_main_menu"

[ "$SECURE" ] && f_mustberoot_init

# Incorporate rc-file if it exists
[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"

#
# If a non-option argument was passed, process it as a menuitem selection...
#
if [ "$1" ]; then
	#
	# ...unless it's a long-option for usage.
	#
	case "$1" in -help|--help|-\?)
		usage
		# Not reached
	esac

	#
	# Find the INDEX (possibly i18n) claiming this keyword and get the
	# command to execute from the menu_selection line.
	#
	if ! { indexfile=$( f_index_file "$1" ) &&
	       cmd=$( f_index_menusel_command "$indexfile" "$1" )
	}; then
		# no matches, display usage (which shows valid keywords)
		f_err "%s: %s: $msg_not_found\n" "$pgm" "$1"
		usage
		# Not reached
	fi

	shift
	exec $cmd ${USE_XDIALOG:+-X} "$@@" || exit 1
	# Not reached
fi

#
# Launch application main menu
#
while :; do
	dialog_menu_main
	retval=$?
	f_dialog_menutag_fetch mtag
	f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"

	if [ $retval -eq 2 ]; then
		# The Help button was pressed
		f_show_help "$BSDCONFIG_HELPFILE"
		continue
	elif [ $retval -ne 0 ]; then
		f_die
	fi

	case "$mtag" in
	X) break ;;
	1) # Usage
	   f_show_help "$USAGE_HELPFILE"
	   continue
	esac

	# Anything else is a dynamically loaded menuitem

	f_getvar menu_program$mtag menu_program
	case "$menu_program" in
	/*) cmd="$menu_program" ;;
	 *) cmd="$BSDCFG_LIBE/$menu_program"
	esac
	f_dprintf "cmd=[%s]" "$cmd"
	$cmd ${USE_XDIALOG:+-X}
done

exit $SUCCESS

################################################################################
# END
################################################################################
@


1.38.2.1
log
@file bsdconfig was added on branch RELENG_9 on 2013-07-07 20:03:17 +0000
@
text
@d1 429
@


1.38.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252995
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 429
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-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 (INCLUDING, 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: stable/9/usr.sbin/bsdconfig/bsdconfig 252995 2013-07-07 19:13:34Z dteske $
#
############################################################ INCLUDES

# When common.subr is included, it automatically scans "$@@" for `-d' and/or
# `-D file' arguments to conditionally enable debugging. Similarly, when
# dialog.subr is included, it automatically scans "$@@" for `-X' and/or `-S'.
# To prevent this scanning from becoming confused by extra options, define
# any/all extra arguments to use in the optstring to getopts when scanning
# for dedicated options such as those described.
#
# NOTE: This needs to be declared before including `common.subr'.
# NOTE: You really only need to list flags that require an argument as unknown
#       flags are silently accepted unless they take an argument (in which case
#       the following argument will terminate option processing unless it looks
#       like a flag).
#
GETOPTS_EXTRA="f:"

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/mustberoot.subr
f_include $BSDCFG_SHARE/strings.subr

BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr

BSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp
USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp

############################################################ CONFIGURATION

#
# Alternate `local' libexec directory for add-on modules (e.g., from ports)
#
BSDCFG_LOCAL_LIBE="/usr/local/libexec/bsdconfig"

############################################################ FUNCTIONS

# usage
#
# display usage and exit
#
usage()
{
	local index="INDEX"
	local cmd_list # Calculated below

	cd $BSDCFG_LIBE
		# No need to preserve CWD (headed toward exit)

	# Test for language-specific indices
	f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
		index="$index.${LANG:-$LC_ALL}"

	cmd_list=$(
		awk '/^menu_selection="/ {
			sub(/\|.*/, "")
			sub(/^menu_selection="/, "")
			print
		}' */$index | sort
	)

	local alt_cmd_list # Calculated below (if $BSDCFG_LOCAL_LIBE exists)
	if f_quietly cd $BSDCFG_LOCAL_LIBE; then
		# No need to preserve CWD (headed toward exit)

		# Test for language-specific indices
		f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
			index="$index.${LANG:-$LC_ALL}"

		alt_cmd_list=$(
			awk '/^menu_selection="/ {
				sub(/\|.*/, "")
				sub(/^menu_selection="/, "")
				print
			}' */$index 2> /dev/null | sort
		)

		# Conflate lists, removing duplicates
		cmd_list=$( printf "%s\n%s\n" \
		                   "$cmd_list" "$alt_cmd_list" | sort -u )
	fi

	#
	# Determine the longest command-length (in characters)
	#
	local longest_cmd
	longest_cmd=$( echo "$cmd_list" | f_longest_line_length )
	f_dprintf "longest_cmd=[%s]" "$longest_cmd"

	#
	# Determine the maximum width of terminal/console
	#
	local max_size="$( stty size 2> /dev/null )"
	: ${max_size:="24 80"}
	local max_width="${max_size#*[$IFS]}"
	f_dprintf "max_width=[%s]" "$max_width"

	#
	# Using the longest command-length as the width of a single column,
	# determine if we can use more than one column to display commands.
	#
	local x=$longest_cmd ncols=1
	x=$(( $x + 8 )) # Accomodate leading tab character
	x=$(( $x + 3 + $longest_cmd )) # Preload end of next column
	while [ $x -lt $max_width ]; do
		ncols=$(( $ncols + 1 ))
		x=$(( $x + 3 + $longest_cmd ))
	done
	f_dprintf "ncols=[%u] x=[%u]" $ncols $x

	#
	# Re-format the command-list into multiple columns
	#
	cmd_list=$( eval "$( echo "$cmd_list" |
		awk -v ncols=$ncols -v size=$longest_cmd '
		BEGIN {
			n = 0
			row_item[1] = ""
		}
		function print_row()
		{
			fmt = "printf \"\\t%-" size "s"
			for (i = 1; i < cur_col; i++)
				fmt = fmt "   %-" size "s"
			fmt = fmt "\\n\""
			printf "%s", fmt
			for (i = 1; i <= cur_col; i++)
				printf " \"%s\"", row_item[i]
			print ""
		}
		{
			n++
			cur_col = (( n - 1 ) % ncols ) + 1
			printf "f_dprintf \"row_item[%u]=[%%s]\" \"%s\"\n",
			       cur_col, $0
			row_item[cur_col] = $0
			if ( cur_col == ncols ) print_row()
		}
		END {
			if ( cur_col < ncols ) print_row()
		}' )"
	)

	f_usage $BSDCFG_LIBE/USAGE \
	        "PROGRAM_NAME" "$pgm" \
	        "COMMAND_LIST" "$cmd_list"

	# Never reached
}

# dialog_menu_main
#
# Display the dialog(1)-based application main menu.
#
dialog_menu_main()
{
	local title="$DIALOG_TITLE"
	local btitle="$DIALOG_BACKTITLE"
	local prompt="$msg_menu_text"
	local menu_list="
		'X' '$msg_exit'  '$msg_exit_bsdconfig'
		'1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system'
	" # END-QUOTE
	local defaultitem= # Calculated below
	local hline=

	#
	# Pick up the base modules (directories named `[0-9][0-9][0-9].*')
	#
	local menuitem menu_title menu_help menu_selection index=2
	for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do
		[ -f "$BSDCFG_LIBE/$menuitem/INDEX" ] || continue
		[ $index -lt ${#DIALOG_MENU_TAGS} ] || break

		menu_program= menu_title= menu_help=
		f_include_lang $BSDCFG_LIBE/$menuitem/INDEX
		[ "$menu_program" ] || continue

		case "$menu_program" in
		/*) : already fully qualified ;;
		 *) menu_program="$menuitem/$menu_program"
		esac

		tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
		setvar "menu_program$tag" "$menu_program"

		f_shell_escape "$menu_title" menu_title
		f_shell_escape "$menu_help" menu_help
		menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"

		index=$(( $index + 1 ))
	done

	#
	# Process the `local' libexec sources.
	#
	# Whereas modules in $BSDCFG_LIBE must be named [0-9][0-9][0-9].*
	# modules in $BSDCFG_LOCAL_LIBE should NOT be named this way (making it
	# more practical for port-maintainers).
	#
	# This also has the fortunate side-effect of making the de-duplication
	# effort rather simple (because so-called `base' modules must be named
	# differently than add-on modules).
	#
	local separator_added=
	for menuitem in $( cd "$BSDCFG_LOCAL_LIBE" 2> /dev/null && ls -d * )
	do
		# Skip the module if it looks like a `base' module
		case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac

		[ -f "$BSDCFG_LOCAL_LIBE/$menuitem/INDEX" ] || continue
		[ $index -lt ${#DIALOG_MENU_TAGS} ] || break

		menu_program= menu_title= menu_help=
		f_include_lang $BSDCFG_LOCAL_LIBE/$menuitem/INDEX || continue
		[ "$menu_program" ] || continue

		if [ ! "$separator_added" ]; then
			menu_list="$menu_list '-' '-' ''"
			separator_added=1
		fi

		case "$menu_program" in
		/*) : already fully qualified ;;
		 *) menu_program="$BSDCFG_LOCAL_LIBE/$menuitem/$menu_program"
		esac

		tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
		setvar "menu_program$tag" "$menu_program"

		f_shell_escape "$menu_title" menu_title
		f_shell_escape "$menu_help" menu_help
		menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"

		index=$(( $index + 1 ))
	done

	local height width rows
	eval f_dialog_menu_with_help_size height width rows \
	                                  \"\$title\"  \
	                                  \"\$btitle\" \
	                                  \"\$prompt\" \
	                                  \"\$hline\"  \
	                                  $menu_list

	# Obtain default-item from previously stored selection
	f_dialog_default_fetch defaultitem

	local menu_choice
	menu_choice=$( eval $DIALOG \
		--clear                                 \
		--title \"\$title\"                     \
		--backtitle \"\$btitle\"                \
		--hline \"\$hline\"                     \
		--item-help                             \
		--ok-label \"\$msg_ok\"                 \
		--cancel-label \"\$msg_exit_bsdconfig\" \
		--help-button                           \
		--help-label \"\$msg_help\"             \
		${USE_XDIALOG:+--help \"\"}             \
		--default-item \"\$defaultitem\"        \
		--menu \"\$prompt\"                     \
		$height $width $rows                    \
		$menu_list                              \
		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
	)
	local retval=$?
	f_dialog_data_sanitize menu_choice
	f_dialog_menutag_store "$menu_choice"

	# Only update default-item on success
	[ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"

	return $retval
}

############################################################ MAIN

#
# If $0 is not "bsdconfig", interpret it either as a keyword to a menuitem or
# as a valid resword (see script.subr for additional details about reswords).
#
if [ "$pgm" != "bsdconfig" ]; then
	if indexfile=$( f_index_file "$pgm" ) &&
	   cmd=$( f_index_menusel_command "$indexfile" "$pgm" )
	then
		f_dprintf "pgm=[%s] indexfile=[%s] cmd=[%s]" \
		          "$pgm" "$indexfile" "$cmd"
		exec "$cmd" "$@@" || exit 1
	else
		f_include $BSDCFG_SHARE/script.subr
		for resword in $RESWORDS; do
			[ "$pgm" = "$resword" ] || continue
			# Found a match
			f_dprintf "pgm=[%s] A valid resWord!" "$pgm"
			f_dispatch $resword
			exit $?
		done
	fi
fi

#
# Process command-line arguments
#
scripts_loaded=0
while getopts f:h$GETOPTS_STDARGS flag; do
	case "$flag" in
	f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr
	   f_script_load "$OPTARG"
	   scripts_loaded=$(( $scripts_loaded + 1 )) ;;
	h|\?) usage ;;
	esac
done
shift $(( $OPTIND -1 ))

# If we've loaded any scripts, do not continue any further
[ $scripts_loaded -gt 0 ] && exit

#
# Initialize
#
f_dialog_title "$msg_main_menu"

[ "$SECURE" ] && f_mustberoot_init

# Incorporate rc-file if it exists
[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"

#
# If a non-option argument was passed, process it as a menuitem selection...
#
if [ "$1" ]; then
	#
	# ...unless it's a long-option for usage.
	#
	case "$1" in -help|--help|-\?)
		usage
		# Not reached
	esac

	#
	# Find the INDEX (possibly i18n) claiming this keyword and get the
	# command to execute from the menu_selection line.
	#
	if ! { indexfile=$( f_index_file "$1" ) &&
	       cmd=$( f_index_menusel_command "$indexfile" "$1" )
	}; then
		# no matches, display usage (which shows valid keywords)
		f_err "%s: %s: $msg_not_found\n" "$pgm" "$1"
		usage
		# Not reached
	fi

	shift
	exec $cmd ${USE_XDIALOG:+-X} "$@@" || exit 1
	# Not reached
fi

#
# Launch application main menu
#
while :; do
	dialog_menu_main
	retval=$?
	f_dialog_menutag_fetch mtag
	f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"

	if [ $retval -eq 2 ]; then
		# The Help button was pressed
		f_show_help "$BSDCONFIG_HELPFILE"
		continue
	elif [ $retval -ne 0 ]; then
		f_die
	fi

	case "$mtag" in
	X) break ;;
	1) # Usage
	   f_show_help "$USAGE_HELPFILE"
	   continue
	esac

	# Anything else is a dynamically loaded menuitem

	f_getvar menu_program$mtag menu_program
	case "$menu_program" in
	/*) cmd="$menu_program" ;;
	 *) cmd="$BSDCFG_LIBE/$menu_program"
	esac
	f_dprintf "cmd=[%s]" "$cmd"
	$cmd ${USE_XDIALOG:+-X}
done

exit $SUCCESS

################################################################################
# END
################################################################################
@


1.38.2.3
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/263791
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d4 1
a4 1
# Copyright (c) 2012-2014 Devin Teske
d28 1
a28 1
# $FreeBSD: stable/9/usr.sbin/bsdconfig/bsdconfig 263791 2014-03-27 03:20:47Z dteske $
d303 1
a303 1
	[ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice"
d318 2
a319 1
		f_dprintf "pgm=[%s] cmd=[%s] *=[%s]" "$pgm" "$cmd" "$*"
d327 1
a327 1
			f_dispatch $resword $resword "$@@"
d345 1
a345 1
shift $(( $OPTIND - 1 ))
a384 1
	f_dprintf "cmd=[%s] *=[%s]" "$cmd" "$*"
d399 2
a400 1
	if [ $retval -eq $DIALOG_HELP ]; then
d403 1
a403 1
	elif [ $retval -ne $DIALOG_OK ]; then
@


1.37
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252848
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252848 2013-07-05 22:24:43Z dteske $
d203 1
d242 1
@


1.36
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252836
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252836 2013-07-05 20:13:00Z dteske $
a237 2
		[ $index -lt ${#DIALOG_MENU_TAGS} ] || break

d241 2
@


1.35
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252833
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252833 2013-07-05 19:57:40Z dteske $
d60 7
d93 21
d198 3
d224 43
@


1.34
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252178
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252178 2013-06-24 20:58:54Z dteske $
a172 1
		tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
d174 1
a174 3
		menu_program=
		menu_title=
		menu_help=
d183 3
a187 1
		setvar "menu_program$tag" "$menu_program"
@


1.33
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252177
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252177 2013-06-24 20:39:07Z dteske $
d343 1
a343 1
	/*) cmd="$menu_program";;
@


1.32
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252019
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252019 2013-06-20 05:48:08Z dteske $
d266 2
a267 2
	   scripts_loaded=$(( $scripts_loaded + 1 ));;
	h|\?) usage;;
@


1.31
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252000
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 252000 2013-06-19 18:13:58Z dteske $
d333 1
a333 4
	X) # Exit
	   break
	   ;;

d337 1
a337 1
	   ;;
d339 1
a339 8
	*) # Dynamically loaded menuitem
	   f_getvar menu_program$mtag menu_program
	   case "$menu_program" in
	   /*) cmd="$menu_program";;
	    *) cmd="$BSDCFG_LIBE/$menu_program"
	   esac
	   f_dprintf "cmd=[%s]" "$cmd"
	   $cmd ${USE_XDIALOG:+-X}
d341 4
d346 2
@


1.30
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251793
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251793 2013-06-15 13:38:21Z dteske $
d183 1
a183 2
		*)
			menu_program="$menuitem/$menu_program"
@


1.29
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251364
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251364 2013-06-04 03:47:21Z dteske $
d293 3
a295 2
	case "$1" in
	-help|--help|-\?) usage;;
d308 1
d313 1
@


1.28
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251270
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251270 2013-06-02 23:05:01Z dteske $
a169 1
	local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
d187 2
a188 2
		menu_title=$( echo "$menu_title" | awk "$sanitize_awk" )
		menu_help=$( echo "$menu_help" | awk "$sanitize_awk" )
@


1.27
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251266
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251266 2013-06-02 22:34:40Z dteske $
d96 1
a96 2
	local max_size max_width
	max_size=$( stty size 2> /dev/null )
d98 1
a98 1
	max_width="${max_size#*[$IFS]}"
@


1.26
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251265
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251265 2013-06-02 22:04:39Z dteske $
a171 1

@


1.25
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251264
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251264 2013-06-02 20:02:50Z dteske $
d32 15
@


1.24
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251244
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251244 2013-06-02 09:02:12Z dteske $
d53 2
a54 1
	local index="INDEX" cmd_list=""
d149 1
a149 4
	local menu_list
	local defaultitem= # Calculated below

	menu_list="
d153 2
d188 1
a188 1
	                                  \"\"         \
d199 1
@


1.23
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251236
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251236 2013-06-01 23:58:44Z dteske $
d149 1
d191 3
d205 1
a205 1
		--default-item \"\$DEFAULTITEM_$$\"     \
d216 1
a216 1
	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice"
@


1.22
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251190
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 251190 2013-05-31 19:07:17Z dteske $
d190 2
a191 2
	local dialog_menu
	dialog_menu=$( eval $DIALOG \
d208 2
a209 1
	setvar DIALOG_MENU_$$ "$dialog_menu"
d212 1
a212 1
	[ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$dialog_menu"
d302 1
a302 1
	mtag=$( f_dialog_menutag )
@


1.21
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250633
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 250633 2013-05-14 03:21:13Z dteske $
d148 1
a148 1
	local menu_list size
d182 7
a188 6
	size=$( eval f_dialog_menu_with_help_size \
	        	\"\$title\"  \
	        	\"\$btitle\" \
	        	\"\$prompt\" \
	        	\"\"         \
	        	$menu_list   )
d202 3
a204 1
		--menu \"\$prompt\" $size $menu_list    \
@


1.20
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249751
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 249751 2013-04-22 05:52:06Z dteske $
d242 1
a242 1
while getopts dD:f:hSX flag; do
@


1.19
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249749
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 249749 2013-04-22 05:32:27Z dteske $
d200 1
d206 4
@


1.18
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249746
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 249746 2013-04-22 05:02:34Z dteske $
d315 5
a319 1
	   cmd=$( eval echo \"\$menu_program$mtag\" )
a321 1
	   ;;
@


1.17
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245401
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 245401 2013-01-14 01:09:23Z dteske $
d56 1
d135 2
d158 1
a158 1
	for menuitem in $( ls -d [0-9][0-9][0-9].* ); do
d165 1
a165 1
		f_include_lang $menuitem/INDEX
d237 1
a237 1
while getopts f:hSX flag; do
a259 2
cd $BSDCFG_LIBE || f_die 1 "$msg_directory_not_found" "$BSDCFG_LIBE"

@


1.16
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245106
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 245106 2013-01-06 18:18:09Z dteske $
d195 1
@


1.15
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245052
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d4 1
a4 1
# Copyright (c) 2012 Devin Teske
d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 245052 2013-01-05 02:08:47Z dteske $
@


1.14
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244675
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 244675 2012-12-25 10:47:45Z dteske $
d207 2
a208 1
# If $0 is not "bsdconfig", interpret it as a keyword to a menuitem
d210 17
a226 5
if [ "$pgm" != "bsdconfig" ] &&
   indexfile=$( f_index_file "$pgm" ) &&
   cmd=$( f_index_menusel_command "$indexfile" "$pgm" )
then
	exec "$cmd" "$@@" || exit 1
d232 2
a233 1
while getopts hSX flag; do
d235 3
d243 3
@


1.13
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244674
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 244674 2012-12-25 09:30:25Z dteske $
d34 1
a235 9
#
# Log our operating environment for debugging purposes
#
export UNAME_S="$(uname -s)" # Operating System (i.e. FreeBSD)
export UNAME_P="$(uname -p)" # Processor Architecture (i.e. i386)
export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE)
f_dprintf "UNAME_S=[%s] UNAME_P=[%s] UNAME_R=[%s]" \
          "$UNAME_S" "$UNAME_P" "$UNAME_R"

@


1.12
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244550
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 244550 2012-12-21 19:26:17Z dteske $
a227 1
f_dialog_init
@


1.11
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/243112
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243112 | dteske | 2012-11-16 00:59:11 +0000 (Fri, 16 Nov 2012) | 11 lines
## SVN ##
## SVN ## Replicate a feature from sysinstall documented in
## SVN ## stable/9/usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## To get a list of modules you can link to, see `bsdconfig -h' output.
## SVN ##
## SVN ## Approved by:	adrian (co-mentor) (implicit)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 243112 2012-11-16 00:59:11Z dteske $
d73 1
a73 1
	f_dprintf "longest_cmd=[$longest_cmd]"
d82 1
a82 1
	f_dprintf "max_width=[$max_width]"
d95 1
a95 1
	f_dprintf "ncols=[$ncols] x=[$x]"
d120 2
a121 1
			printf "f_dprintf \"row_item[%u]=[%s]\"\n", cur_col, $0
d242 2
a243 1
f_dprintf "UNAME_S=[$UNAME_S] UNAME_P=[$UNAME_P] UNAME_R=[$UNAME_R]"
d281 1
a281 1
	f_dprintf "retval=$retval mtag=[$mtag]"
d303 1
a303 1
	   f_dprintf "cmd=[$cmd]"
@


1.10
log
@Switching exporter and resync
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/bsdconfig 242107 2012-10-26 00:31:25Z dteske $
d205 10
d257 2
a258 1
	# Find the INDEX (possibly i18n) claiming this keyword
d260 4
a263 16
	lang="${LANG:-$LC_ALL}"
	if [ "$lang" ]; then
		sel=$( grep "^menu_selection=\"$1|" */INDEX.$lang \
		       		2> /dev/null | tail -1 )

		# Fall-back to non-i18n sources if nothing was found
		[ "$sel" ] ||
			sel=$( grep "^menu_selection=\"$1|" */INDEX | tail -1 )
	else
		sel=$( grep "^menu_selection=\"$1|" */INDEX | tail -1 )
	fi

	#
	# If no matches, display usage (which shows valid keywords)
	#
	if [ ! "$sel" ]; then
a267 10
	#
	# The command to execute is after the pipe-character (|) in the
	# menu_selection property of the INDEX file for the menuitem.
	#
	cmd="${sel#*|}"
	cmd="${cmd%\"}"
	if [ ! "$cmd" ]; then
		echo "$pgm: $1: $msg_not_found"
		usage
	fi
a268 12

	#
	# If the command pathname is not fully qualified fix-up/force to be
	# relative to the menuitem directory.
	#
	case "$cmd" in
	/*) : already fully qualified ;;
	*)
		dir="${sel%%/*}"
		cmd="$dir/$cmd"
	esac

@


1.9
log
@SVN rev 242107 on 2012-10-26 00:31:25Z by dteske

Switch from using a msgbox to display help files to a textbox instead. The
problem with using a msgbox was one of truncation in the case of Xdialog(1)
and lack of screen real-estate (since the msgbox is not scrollable in X11
while a textbox is).

The textbox renders the text much better and is more appropriate for this
type of data display.

Approved by:	adrian (co-mentor) (implicit)
@
text
@d28 1
a28 1
# $FreeBSD$
@


1.8
log
@SVN rev 242096 on 2012-10-25 21:04:11Z by dteske

When Xdialog(1) is passed a NULL argument to its `--help' option, Xdialog(1)
acts like dialog(1) in that it returns exit status 2 when the help button is
chosen.

Approved by:	adri (co-mentor) (implicit)
@
text
@d40 3
a42 2
f_include_help BSDCONFIG $BSDCFG_LIBE/include/bsdconfig.hlp
f_include_help USAGE     $BSDCFG_LIBE/include/usage.hlp
d306 1
a306 1
		f_show_msg "%s" "$( f_include_help BSDCONFIG )"
d318 1
a318 1
	   f_show_msg "%s" "$( f_include_help USAGE )"
@


1.7
log
@SVN rev 241899 on 2012-10-22 18:01:38Z by dteske

Resurrect usage.hlp and securelevel.hlp from sysinstall(8) and integrate them
into bsdconfig(8).

Approved by:	adrian (co-mentor) (implicit)
@
text
@d192 1
a192 1
		${USE_XDIALOG:+--help \"\$( f_include_help BSDCONFIG )\"} \
@


1.6
log
@SVN rev 241701 on 2012-10-18 18:43:54Z by dteske

More-accurately replicate the help system from sysinstall(8). However, also
improve upon the system by giving the user a "Help" button instead of requiring
the user to press F1.

NOTE: In FreeBSD-9 and higher, dialog(1) does not support the F1 hook, so the
      mechanism for providing help to the user had to be changed to a button.

This now means we can resurrect *.hlp files from usr.sbin/sysinstall/help/ as-
is and reusing them as-needed in bsdconfig (holding to the goal of losing as
little functionality from sysinstall as possible).

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d40 2
a41 1
f_include_help $BSDCFG_LIBE/include/bsdconfig.hlp
d145 2
a146 1
		'X' '$msg_exit' '$msg_exit_bsdconfig'
d151 1
a151 1
	local menuitem menu_title menu_help menu_selection index=1
d192 1
a192 1
	${USE_XDIALOG:+--help \"\$( f_include_help )\"} \
d305 1
a305 1
		f_show_msg "%s" "$( f_include_help )"
d316 5
@


1.5
log
@SVN rev 240783 on 2012-09-21 19:03:25Z by dteske

Reverse SVN r240770 -- jilles@@ made a suggestion that allowed us to redesign
our embedded rescue environment to support /dev/null making r240770 obsolete.

Reviewed by:	jilles, adrian (co-mentor)
Approved by:	jilles, adrian (co-mentor)
@
text
@d40 1
d189 2
a291 2
[ -f "$HOME/.bsdconfigrc" ] || f_dialog_msgbox "$msg_help_text"

d301 7
a307 1
	[ $retval -eq 0 ] || f_die
@


1.4
log
@SVN rev 240770 on 2012-09-21 01:36:20Z by dteske

Replace redirections to /dev/null with "close file-descriptor" syntax (>&-).

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d76 1
a76 1
	max_size=$( stty size 2>&- )
d245 2
a246 2
		sel=$( grep "^menu_selection=\"$1|" */INDEX.$lang 2>&- |
		       	tail -1 )
@


1.3
log
@SVN rev 240768 on 2012-09-20 23:44:13Z by dteske

Change all invocations of dialog(1) to no-longer require temporary files.
This allows bsdconfig to -- like bsdinstall -- operate from read-only media.

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d76 1
a76 1
	max_size=$( stty size 2> /dev/null )
d245 2
a246 2
		sel=$( grep "^menu_selection=\"$1|" */INDEX.$lang \
		       		2> /dev/null | tail -1 )
@


1.2
log
@SVN rev 240684 on 2012-09-18 22:28:42Z by dteske

Move major includes into /usr/share/bsdconfig for easy external access.

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d180 2
a181 1
	eval $DIALOG \
d189 5
a193 1
		2> "$DIALOG_TMPDIR/dialog.menu.$$"
@


1.1
log
@SVN rev 238438 on 2012-07-14 03:16:57Z by dteske

Import bsdconfig(8) as a replacement for the post-install abilities of
deprecated sysinstall(8). NOTE: WITH_BSDCONFIG is currently required.

Submitted by:	Devin Teske (dteske), Ron McDowell <rcm@@fuzzwad.org>
Reviewed by:	Ron McDowell <rcm@@fuzzwad.org>
Approved by:	Ed Maste (emaste)
@
text
@d32 6
a38 4
. $BSDCFG_LIBE/include/common.subr || exit 1
f_include $BSDCFG_LIBE/include/dialog.subr
f_include $BSDCFG_LIBE/include/mustberoot.subr
f_include $BSDCFG_LIBE/include/strings.subr
@

