From 2b4f8b4cff0f059bf1e3f05fca00c8ae991d2ac7 Mon Sep 17 00:00:00 2001 From: dteske Date: Thu, 18 Oct 2012 18:43:54 +0000 Subject: 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) --- usr.sbin/bsdconfig/bsdconfig | 13 ++++++++--- usr.sbin/bsdconfig/include/Makefile | 2 +- usr.sbin/bsdconfig/include/bsdconfig.hlp | 12 ++++++++++ usr.sbin/bsdconfig/include/messages.subr | 1 - usr.sbin/bsdconfig/share/common.subr | 38 ++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 usr.sbin/bsdconfig/include/bsdconfig.hlp diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index ea72d3c..a9dc1fa 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -37,6 +37,7 @@ f_include $BSDCFG_SHARE/strings.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" f_include_lang $BSDCFG_LIBE/include/messages.subr +f_include_help $BSDCFG_LIBE/include/bsdconfig.hlp ############################################################ FUNCTIONS @@ -185,6 +186,8 @@ dialog_menu_main() --item-help \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_exit_bsdconfig\" \ + --help-button \ + ${USE_XDIALOG:+--help \"\$( f_include_help )\"} \ --menu \"\$prompt\" $size $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -286,8 +289,6 @@ if [ "$1" ]; then exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1 fi -[ -f "$HOME/.bsdconfigrc" ] || f_dialog_msgbox "$msg_help_text" - # # Launch application main menu # @@ -297,7 +298,13 @@ while :; do mtag=$( f_dialog_menutag ) f_dprintf "retval=$retval mtag=[$mtag]" - [ $retval -eq 0 ] || f_die + if [ $retval -eq 2 ]; then + # The Help button was pressed + f_show_msg "%s" "$( f_include_help )" + continue + elif [ $retval -ne 0 ]; then + f_die + fi case "$mtag" in X) # Exit diff --git a/usr.sbin/bsdconfig/include/Makefile b/usr.sbin/bsdconfig/include/Makefile index 15d1725..27ce643 100644 --- a/usr.sbin/bsdconfig/include/Makefile +++ b/usr.sbin/bsdconfig/include/Makefile @@ -3,7 +3,7 @@ NO_OBJ= FILESDIR= ${LIBEXECDIR}/bsdconfig/include -FILES= messages.subr +FILES= bsdconfig.hlp messages.subr beforeinstall: mkdir -p ${DESTDIR}${FILESDIR} diff --git a/usr.sbin/bsdconfig/include/bsdconfig.hlp b/usr.sbin/bsdconfig/include/bsdconfig.hlp new file mode 100644 index 0000000..b6eeaf3 --- /dev/null +++ b/usr.sbin/bsdconfig/include/bsdconfig.hlp @@ -0,0 +1,12 @@ +This menu allows you to configure your system after the installation +process is complete. At the minimum, you should probably set the root +password and the system time zone. + +For extra goodies like bash, emacs, firefox, etc., you should look at +the Packages item in this menu. + +For setting the timezone after the system is installed, use the 'Time +Zone' item in this menu. + +For more information on the overall general system configuration, see +the /etc/rc.conf and /etc/defaults/rc.conf files. diff --git a/usr.sbin/bsdconfig/include/messages.subr b/usr.sbin/bsdconfig/include/messages.subr index 26d4188..a3b8ace 100644 --- a/usr.sbin/bsdconfig/include/messages.subr +++ b/usr.sbin/bsdconfig/include/messages.subr @@ -38,7 +38,6 @@ msg_created_path="Created %s" msg_directory_not_found="%s: Directory not found." msg_exit="Exit" msg_exit_bsdconfig="Exit bsdconfig" -msg_help_text="This menu allows you to configure your system after the installation\nprocess is complete. At the minimum, you should probably set the root\npassword and the system time zone.\n\nFor extra goodies like bash, emacs, firefox, etc., you should look at the\n'Packages' item in this menu.\n\nFor setting the timezone after the system is installed, use the 'Time\nZone' item in this menu.\n\nFor more information on the overall general system configuration, see the\n/etc/rc.conf and /etc/defaults/rc.conf files. (Note: to inhibit displaying\nof this message, create an empty file: \$HOME/.bsdconfigrc or copy it from\n/usr/share/examples/bsdconfig/bsdconfigrc)" msg_main_menu="Main Menu" msg_menu_text="If you've already installed FreeBSD, you may use\nthis menu to customize it somewhat to suit your\nparticular configuration. Most importantly, you\ncan use the Packages utility to load extra '3rd\nparty' software not provided in the base\ndistributions." msg_must_be_root_to_execute="%s: must be root to execute" diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 667a8f6..9d034ea 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -179,6 +179,44 @@ f_include_lang() fi } +# f_include_help [$file] +# +# When given an argument, cache the contents of a language help-file (to later +# be retrieved by executing again without arguments). +# +# Automatically takes $LANG and $LC_ALL into consideration when reading $file +# (suffix ".$LC_ALL" or ".$LANG" will automatically be added prior to loading +# the language help-file). +# +# No error is produced if (a) a language has been requested (by setting either +# $LANG or $LC_ALL in the environment) and (b) the language help-file does not +# exist -- in which case we will fall back to loading $file without-suffix. +# +# If the language help-file does not exist, an error is cached in place of the +# help-file contents. +# +# When called without arguments, the cached value (if any) is produced. Each +# time this function is called, the cache is overwritten with the newly loaded +# contents. +# +f_include_help() +{ + local file="$1" + + if [ "$file" ]; then + local lang="${LANG:-$LC_ALL}" + + f_dprintf "lang=[$lang]" + if [ -f "$file.$lang" ]; then + setvar HELP_$$ "$( cat "$file.$lang" 2>&1 )" + else + setvar HELP_$$ "$( cat "$file" 2>&1 )" + fi + else + eval echo \"\$HELP_$$\" + fi +} + # f_usage $file [ $key1 $value1 ... ] # # Display USAGE file with optional pre-processor macro definitions. The first -- cgit v1.1