Index: head/usr.sbin/bsdconfig/bsdconfig =================================================================== --- head/usr.sbin/bsdconfig/bsdconfig (revision 251243) +++ head/usr.sbin/bsdconfig/bsdconfig (revision 251244) @@ -1,339 +1,343 @@ #!/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$ # ############################################################ 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/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 ############################################################ FUNCTIONS # usage # # display usage and exit # usage() { local index="INDEX" cmd_list="" 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 ) # # 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 max_width max_size=$( stty size 2> /dev/null ) : ${max_size:="24 80"} 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 + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' '$msg_exit_bsdconfig' '1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system' " # END-QUOTE local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }" 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 [ $index -lt ${#DIALOG_MENU_TAGS} ] || break tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 ) 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 menu_title=$( echo "$menu_title" | awk "$sanitize_awk" ) menu_help=$( echo "$menu_help" | awk "$sanitize_awk" ) setvar "menu_program$tag" "$menu_program" 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\" \ \"\" \ $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\" \ --item-help \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_exit_bsdconfig\" \ --help-button \ --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ - --default-item \"\$DEFAULTITEM_$$\" \ + --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 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $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;; 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 fi shift exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1 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) # Exit break ;; 1) # Usage f_show_help "$USAGE_HELPFILE" continue ;; *) # 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} esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/console/console =================================================================== --- head/usr.sbin/bsdconfig/console/console (revision 251243) +++ head/usr.sbin/bsdconfig/console/console (revision 251244) @@ -1,144 +1,148 @@ #!/bin/sh #- # 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 (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/mustberoot.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list local hline="$hline_configure_system_console_settings" local prompt="$msg_console_menu_text" + local defaultitem= # Calculated below menu_list=" 'X $msg_exit' '$msg_exit_this_menu' '2 $msg_font' '$msg_choose_alternate_screen_font' '3 $msg_keymap' '$msg_choose_alternate_keyboard_map' '4 $msg_repeat' '$msg_set_repeat_rate' '5 $msg_saver' '$msg_configure_screen_saver' '6 $msg_screenmap' '$msg_choose_alternate_screenmap' '7 $msg_ttys' '$msg_choose_console_terminal_type' " # END-QUOTE local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --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" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_system_console_configuration" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in "X $msg_exit") break ;; "2 $msg_font") # Choose an alternate screen font $BSDCFG_LIBE/$APP_DIR/font ${USE_XDIALOG:+-X} ;; "3 $msg_keymap") # Choose an alternate keyboard map $BSDCFG_LIBE/$APP_DIR/keymap ${USE_XDIALOG:+-X} ;; "4 $msg_repeat") # Set the rate at which keys repeat $BSDCFG_LIBE/$APP_DIR/repeat ${USE_XDIALOG:+-X} ;; "5 $msg_saver") # Configure the screen saver $BSDCFG_LIBE/$APP_DIR/saver ${USE_XDIALOG:+-X} ;; "6 $msg_screenmap") # Choose an alternate screenmap $BSDCFG_LIBE/$APP_DIR/screenmap ${USE_XDIALOG:+-X} ;; "7 $msg_ttys") # Choose console terminal type $BSDCFG_LIBE/$APP_DIR/ttys ${USE_XDIALOG:+-X} ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/mouse/mouse =================================================================== --- head/usr.sbin/bsdconfig/mouse/mouse (revision 251243) +++ head/usr.sbin/bsdconfig/mouse/mouse (revision 251244) @@ -1,141 +1,145 @@ #!/bin/sh #- # 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 (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/mustberoot.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list local hline="" local prompt="$msg_menu_text" + local defaultitem= # Calculated below menu_list=" 'X $msg_exit' '$msg_exit_this_menu' '2 $msg_enable' '$msg_test_and_run_the_mouse_daemon' '3 $msg_type' '$msg_select_mouse_protocol_type' '4 $msg_port' '$msg_select_mouse_port' '5 $msg_flags' '$msg_set_additional_flags' '6 $msg_disable' '$msg_disable_the_mouse_daemon' " # END-QUOTE local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --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" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_please_configure_your_mouse" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in "X $msg_exit") break ;; "2 $msg_enable") # Test and run the mouse daemon $BSDCFG_LIBE/$APP_DIR/enable ${USE_XDIALOG:+-X} ;; "3 $msg_type") # Select mouse protocol type $BSDCFG_LIBE/$APP_DIR/type ${USE_XDIALOG:+-X} ;; "4 $msg_port") # Select mouse port $BSDCFG_LIBE/$APP_DIR/port ${USE_XDIALOG:+-X} ;; "5 $msg_flags") # Set additional flags $BSDCFG_LIBE/$APP_DIR/flags ${USE_XDIALOG:+-X} ;; "6 $msg_disable") # Disable the mouse daemon $BSDCFG_LIBE/$APP_DIR/disable ${USE_XDIALOG:+-X} ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/networking/networking =================================================================== --- head/usr.sbin/bsdconfig/networking/networking (revision 251243) +++ head/usr.sbin/bsdconfig/networking/networking (revision 251244) @@ -1,154 +1,158 @@ #!/bin/sh #- # Copyright (c) 2006-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/mustberoot.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list local hline="$hline_arrows_tab_enter" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' '1' '$msg_hostname_domain' '2' '$msg_network_interfaces' '3' '$msg_default_router' '4' '$msg_dns_nameservers' " # END-QUOTE local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\" \ \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\" \ + $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" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_network_management" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in X) # Exit break ;; 1) # Hostname/Domain $BSDCFG_LIBE/$APP_DIR/hostname ${USE_XDIALOG:+-X} ;; 2) # Network Interfaces $BSDCFG_LIBE/$APP_DIR/devices ${USE_XDIALOG:+-X} # Make subsequent uses of this menu faster by not performing # "ifconfig up" (limiting the pain one must endure). See also # `$BSDCFG_SHARE/networking/device.subr'. # export DIALOG_MENU_NETDEV_KICK_INTERFACES= ;; 3) # Default Router/Gateway $BSDCFG_LIBE/$APP_DIR/defaultrouter ${USE_XDIALOG:+-X} ;; 4) # DNS nameservers $BSDCFG_LIBE/$APP_DIR/nameservers ${USE_XDIALOG:+-X} ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/security/security =================================================================== --- head/usr.sbin/bsdconfig/security/security (revision 251243) +++ head/usr.sbin/bsdconfig/security/security (revision 251244) @@ -1,176 +1,176 @@ #!/bin/sh #- # 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 (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/mustberoot.subr f_include $BSDCFG_SHARE/sysrc.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="130.security" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list mark=" " defaultitem= local hline="$hline_arrows_tab_enter" local prompt="$msg_menu_text" # Obtain default-item (adjusted below for dynamic tags) - f_getvar DEFAULTITEM_$$ defaultitem + f_dialog_default_fetch defaultitem local ditem="${defaultitem%%[$IFS]*}" menu_list=" 'X <<< $msg_exit' '$msg_exit_this_menu' " # END-QUOTE # # Add dynamically tagged entry for kern_securelevels # case "$( f_sysrc_get kern_securelevel_enable )" in [Yy][Ee][Ss]) local kern_securelevel="$( f_sysrc_get kern_securelevel )" if [ ${#kern_securelevel} -eq 1 ] && f_isinteger "$kern_securelevel" && [ $kern_securelevel -lt 9 ] then mark="$kern_securelevel" else mark="X" fi ;; *) mark=" " esac menu_list="$menu_list '2 [$mark] $msg_securelevel' '$msg_securelevel_desc'" # Update default-item if appropriate [ "$ditem" = 2 ] && defaultitem="2 [$mark] $msg_securelevel" # # Add dynamically tagged entry for nfs_reserved_port_only # case "$( f_sysrc_get nfs_reserved_port_only )" in [Yy][Ee][Ss]) mark="X" ;; *) mark=" " ;; esac menu_list="$menu_list '3 [$mark] $msg_nfs_port' '$msg_nfs_port_desc'" # Update default-item if appropriate [ "$ditem" = 3 ] && defaultitem="3 [$mark] $msg_nfs_port" local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list local menu_choice menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --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 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_system_security_options_menu" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in "X <<< $msg_exit") break ;; "2 ["?"] $msg_securelevel") # Configure securelevels for the system $BSDCFG_LIBE/$APP_DIR/kern_securelevel ${USE_XDIALOG:+-X} ;; "3 [X] $msg_nfs_port") # Require that NFS clients use reserved ports f_sysrc_set nfs_reserved_port_only "NO";; "3 [ ] $msg_nfs_port") # Same; Toggle value f_sysrc_set nfs_reserved_port_only "YES";; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/share/dialog.subr =================================================================== --- head/usr.sbin/bsdconfig/share/dialog.subr (revision 251243) +++ head/usr.sbin/bsdconfig/share/dialog.subr (revision 251244) @@ -1,2053 +1,2092 @@ if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1 # # Copyright (c) 2006-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..." dialog.subr f_include $BSDCFG_SHARE/strings.subr f_include $BSDCFG_SHARE/variable.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" f_include_lang $BSDCFG_LIBE/include/messages.subr ############################################################ CONFIGURATION # # Default file descriptor to link to stdout for dialog(1) passthru allowing # execution of dialog from within a sub-shell (so-long as its standard output # is explicitly redirected to this file descriptor). # : ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} ############################################################ GLOBALS # # Default name of dialog(1) utility # NOTE: This is changed to "Xdialog" by the optional `-X' argument # DIALOG="dialog" # # Default dialog(1) title and backtitle text # DIALOG_TITLE="$pgm" DIALOG_BACKTITLE="bsdconfig" # # Settings used while interacting with dialog(1) # DIALOG_MENU_TAGS="123456789ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz" # # Declare that we are fully-compliant with Xdialog(1) by unset'ing all # compatibility settings. # unset XDIALOG_HIGH_DIALOG_COMPAT unset XDIALOG_FORCE_AUTOSIZE unset XDIALOG_INFOBOX_TIMEOUT # # Default behavior is to call f_dialog_init() automatically when loaded. # : ${DIALOG_SELF_INITIALIZE=1} # # Default terminal size (used if/when running without a controlling terminal) # : ${DEFAULT_TERMINAL_SIZE:=24 80} # # Minimum width(s) for various dialog(1) implementations (sensible global # default(s) for all widgets of a given variant) # : ${DIALOG_MIN_WIDTH:=24} : ${XDIALOG_MIN_WIDTH:=35} # # When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll # need to know the size of the embedded GUI objects because the height passed # to Xdialog(1) for these widgets has to be tall enough to accomodate them. # # These values are helpful when manually sizing with dialog(1) too, but in a # different way. dialog(1) does not make you accomodate the custom items in the # height (but does for width) -- a height of 3 will display three lines and a # full calendar, for example (whereas Xdialog will truncate the calendar if # given a height of 3). For dialog(1), use these values for making sure that # the height does not exceed max_height (obtained by f_dialog_max_size()). # DIALOG_CALENDAR_HEIGHT=15 DIALOG_TIMEBOX_HEIGHT=6 ############################################################ GENERIC FUNCTIONS # f_dialog_data_sanitize $var_to_edit ... # # When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors # are generated from underlying libraries. For example, if $LANG is set to an # invalid or unknown locale, the warnings from the Xdialog(1) libraries will # clutter the output. This function helps by providing a centralied function # that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. # # Simply pass the name of one or more variables that need to be sanitized. # After execution, the variables will hold their newly-sanitized data. # f_dialog_data_sanitize() { if [ "$#" -eq 0 ]; then f_dprintf "%s: called with zero arguments" \ f_dialog_response_sanitize return $FAILURE fi local __var_to_edit for __var_to_edit in $*; do # Skip warnings and trim leading/trailing whitespace setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' BEGIN { data = 0 } { if ( ! data ) { if ( $0 ~ /^$/ ) next if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next data = 1 } print } ' )" done } # f_dialog_line_sanitize $var_to_edit ... # # When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors # are generated from underlying libraries. For example, if $LANG is set to an # invalid or unknown locale, the warnings from the Xdialog(1) libraries will # clutter the output. This function helps by providing a centralied function # that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. # # Simply pass the name of one or more variables that need to be sanitized. # After execution, the variables will hold their newly-sanitized data. # # This function, unlike f_dialog_data_sanitize(), also removes leading/trailing # whitespace from each line. # f_dialog_line_sanitize() { if [ "$#" -eq 0 ]; then f_dprintf "%s: called with zero arguments" \ f_dialog_response_sanitize return $FAILURE fi local __var_to_edit for __var_to_edit in $*; do # Skip warnings and trim leading/trailing whitespace setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' BEGIN { data = 0 } { if ( ! data ) { if ( $0 ~ /^$/ ) next if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next data = 1 } sub(/^[[:space:]]*/, "") sub(/[[:space:]]*$/, "") print } ' )" done } ############################################################ TITLE FUNCTIONS # f_dialog_title [$new_title] # # Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1) # ($DIALOG_BACKTITLE) invocations. If no arguments are given or the first # argument is NULL, the current title is returned. # # Each time this function is called, a backup of the current values is made # allowing a one-time (single-level) restoration of the previous title using the # f_dialog_title_restore() function (below). # f_dialog_title() { local new_title="$1" if [ "${1+set}" ]; then if [ "$USE_XDIALOG" ]; then _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" DIALOG_BACKTITLE="$new_title" else _DIALOG_TITLE="$DIALOG_TITLE" DIALOG_TITLE="$new_title" fi else if [ "$USE_XDIALOG" ]; then echo "$DIALOG_BACKTITLE" else echo "$DIALOG_TITLE" fi fi } # f_dialog_title_restore # # Restore the previous title set by the last call to f_dialog_title(). # Restoration is non-recursive and only works to restore the most-recent title. # f_dialog_title_restore() { if [ "$USE_XDIALOG" ]; then DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" else DIALOG_TITLE="$_DIALOG_TITLE" fi } # f_dialog_backtitle [$new_backtitle] # # Set the backtitle of future dialog(1) ($DIALOG_BACKTITLE) or title of # Xdialog(1) ($DIALOG_TITLE) invocations. If no arguments are given or the # first argument is NULL, the current backtitle is returned. # f_dialog_backtitle() { local new_backtitle="$1" if [ "${1+set}" ]; then if [ "$USE_XDIALOG" ]; then _DIALOG_TITLE="$DIALOG_TITLE" DIALOG_TITLE="$new_backtitle" else _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" DIALOG_BACKTITLE="$new_backtitle" fi else if [ "$USE_XDIALOG" ]; then echo "$DIALOG_TITLE" else echo "$DIALOG_BACKTITLE" fi fi } # f_dialog_backtitle_restore # # Restore the previous backtitle set by the last call to f_dialog_backtitle(). # Restoration is non-recursive and only works to restore the most-recent # backtitle. # f_dialog_backtitle_restore() { if [ "$USE_XDIALOG" ]; then DIALOG_TITLE="$_DIALOG_TITLE" else DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" fi } ############################################################ SIZE FUNCTIONS # f_dialog_max_size $var_height $var_width # # Get the maximum height and width for a dialog widget and store the values in # $var_height and $var_width (respectively). # f_dialog_max_size() { local __var_height="$1" __var_width="$2" __max_size [ "$__var_height" -o "$__var_width" ] || return $FAILURE if [ "$USE_XDIALOG" ]; then __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION else __max_size=$( stty size 2> /dev/null ) # usually "24 80" : ${__max_size:=$DEFAULT_TERMINAL_SIZE} fi [ "$__var_height" ] && setvar "$__var_height" "${__max_size%%[$IFS]*}" [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}" } # f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]] # # Modify $var_height to be no-less-than $min_height (if given; zero otherwise) # and no-greater-than terminal height (or screen height if $USE_XDIALOG is # set). # # Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or # $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal # or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by # passing $min_width. # # Return status is success unless one of the passed arguments is invalid # or all of the $var_* arguments are either NULL or missing. # f_dialog_size_constrain() { local __var_height="$1" __var_width="$2" local __min_height="$3" __min_width="$4" local __retval=$SUCCESS # Return failure unless at least one var_* argument is passed [ "$__var_height" -o "$__var_width" ] || return $FAILURE # # Print debug warnings if any given (non-NULL) argument are invalid # NOTE: Don't change the name of $__{var,min,}{height,width} # local __height __width local __arg __cp __fname=f_dialog_size_constrain for __arg in height width; do debug= f_getvar __var_$__arg __cp [ "$__cp" ] || continue if ! f_getvar "$__cp" __$__arg; then f_dprintf "%s: var_%s variable \`%s' not set" \ $__fname $__arg "$__cp" __retval=$FAILURE elif ! eval f_isinteger \$__$__arg; then f_dprintf "%s: var_%s variable value not a number" \ $__fname $__arg __retval=$FAILURE fi done for __arg in height width; do debug= f_getvar __min_$__arg __cp [ "$__cp" ] || continue f_isinteger "$__cp" && continue f_dprintf "%s: min_%s value not a number" $__fname $__arg __retval=$FAILURE setvar __min_$__arg "" done # Obtain maximum height and width values # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __max_height_size_constain __max_width_size_constrain f_dialog_max_size \ __max_height_size_constrain __max_width_size_constrain # Adjust height if desired if [ "$__var_height" ]; then if [ $__height -lt ${__min_height:-0} ]; then setvar "$__var_height" $__min_height elif [ $__height -gt $__max_height_size_constrain ]; then setvar "$__var_height" $__max_height_size_constrain fi fi # Adjust width if desired if [ "$__var_width" ]; then if [ "$USE_XDIALOG" ]; then : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} else : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} fi if [ $__width -lt $__min_width ]; then setvar "$__var_width" $__min_width elif [ $__width -gt $__max_width_size_constrain ]; then setvar "$__var_width" $__max_width_size_constrain fi fi return $__retval # success if no debug warnings were printed } # f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \ # [$min_height [$min_width [$min_rows]]] # # Modify $var_height to be no-less-than $min_height (if given; zero otherwise) # and no-greater-than terminal height (or screen height if $USE_XDIALOG is # set). # # Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or # $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal # or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by # passing $min_width. # # Last, modify $var_rows to be no-less-than $min_rows (if specified; zero # otherwise) and no-greater-than (max_height - 8) where max_height is the # terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL # or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the # number of visible rows. # # Return status is success unless one of the passed arguments is invalid # or all of the $var_* arguments are either NULL or missing. # f_dialog_menu_constrain() { local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4" local __min_height="$5" __min_width="$6" __min_rows="$7" # Return failure unless at least one var_* argument is passed [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || return $FAILURE # # Print debug warnings if any given (non-NULL) argument are invalid # NOTE: Don't change the name of $__{var,min,}{height,width,rows} # local __height __width __rows local __arg __cp __fname=f_dialog_menu_constrain for __arg in height width rows; do debug= f_getvar __var_$__arg __cp [ "$__cp" ] || continue if ! f_getvar "$__cp" __$__arg; then f_dprintf "%s: var_%s variable \`%s' not set" \ $__fname $__arg "$__cp" __retval=$FAILURE elif ! eval f_isinteger \$__$__arg; then f_dprintf "%s: var_%s variable value not a number" \ $__fname $__arg __retval=$FAILURE fi done for __arg in height width rows; do debug= f_getvar __min_$__arg __cp [ "$__cp" ] || continue f_isinteger "$__cp" && continue f_dprintf "%s: min_%s value not a number" $__fname $__arg __retval=$FAILURE setvar __min_$__arg "" done # Obtain maximum height and width values # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __max_height_menu_constrain __max_width_menu_constrain f_dialog_max_size \ __max_height_menu_constrain __max_width_menu_constrain # Adjust height if desired if [ "$__var_height" ]; then if [ $__height -lt ${__min_height:-0} ]; then setvar "$__var_height" $__min_height elif [ $__height -gt $__max_height_menu_constrain ]; then setvar "$__var_height" $__max_height_menu_constrain fi fi # Adjust width if desired if [ "$__var_width" ]; then if [ "$USE_XDIALOG" ]; then : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} else : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} fi if [ $__width -lt $__min_width ]; then setvar "$__var_width" $__min_width elif [ $__width -gt $__max_width_menu_constrain ]; then setvar "$__var_width" $__max_width_menu_constrain fi fi # Adjust rows if desired if [ "$__var_rows" ]; then if [ "$USE_XDIALOG" ]; then : ${__min_rows:=1} else : ${__min_rows:=0} fi local __max_rows=$(( $__max_height_menu_constrain - 8 )) # If prompt_len is zero (no prompt), bump the max-rows by 1 # Default assumption is (if no argument) that there's no prompt [ ${__prompt_len:-0} -gt 0 ] || __max_rows=$(( $__max_rows + 1 )) if [ $__rows -lt $__min_rows ]; then setvar "$__var_rows" $__min_rows elif [ $__rows -gt $__max_rows ]; then setvar "$__var_rows" $__max_rows fi fi return $__retval # success if no debug warnings were printed } # f_dialog_infobox_size [-n] $var_height $var_width \ # $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--infobox' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, and [optionally] hline. The optimal height and # width for the described widget (not exceeding the actual terminal height or # width) is stored in $var_height and $var_width (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # f_dialog_infobox_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # Default height/width of zero for auto-sizing local __height=0 __width=0 __n # Adjust height if desired if [ "$__var_height" ]; then # # Set height based on number of rows in prompt # __n=$( echo -n "$__prompt" | f_number_of_lines ) __n=$(( $__n + 2 )) [ $__n -gt $__height ] && __height=$__n # # For Xdialog(1) bump height if backtitle is enabled (displayed # in the X11 window with a separator line between the backtitle # and msg text). # if [ "$USE_XDIALOG" -a "$__btitle" ]; then __n=$( echo "$__btitle" | f_number_of_lines ) __height=$(( $__height + $__n + 2 )) fi setvar "$__var_height" $__height fi # Adjust width if desired if [ "$__var_width" ]; then # # Bump width for long titles # __n=$(( ${#__title} + 4 )) [ $__n -gt $__width ] && __width=$__n # # If using Xdialog(1), bump width for long backtitles (which # appear within the window). # if [ "$USE_XDIALOG" ]; then __n=$(( ${#__btitle} + 4 )) [ $__n -gt $__width ] && __width=$__n fi # # Bump width for long prompts # __n=$( echo "$__prompt" | f_longest_line_length ) __n=$(( $__n + 4 )) # add width for border [ $__n -gt $__width ] && __width=$__n # # Bump width for long hlines. Xdialog(1) supports `--hline' but # it's currently not used (so don't do anything here if using # Xdialog(1)). # if [ ! "$USE_XDIALOG" ]; then __n=$(( ${#__hline} + 10 )) [ $__n -gt $__width ] && __width=$__n fi # Bump width by 16.6% if using Xdialog(1) [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 )) setvar "$__var_width" $__width fi # Constrain values to sensible minimums/maximums unless `-n' was passed # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_size_constrain "$__var_height" "$__var_width" } # f_dialog_buttonbox_size [-n] $var_height $var_width \ # $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--msgbox' and `--yesno' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, and [optionally] hline. The optimal height and # width for the described widget (not exceeding the actual terminal height or # width) is stored in $var_height and $var_width (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # f_dialog_buttonbox_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # Calculate height/width of infobox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_bbox_size __width_bbox_size f_dialog_infobox_size -n \ "${__var_height:+__height_bbox_size}" \ "${__var_width:+__width_bbox_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # Adjust height if desired if [ "$__var_height" ]; then # Add height to accomodate the buttons __height_bbox_size=$(( $__height_bbox_size + 2 )) # Adjust for clipping with Xdialog(1) on Linux/GTK2 [ "$USE_XDIALOG" ] && __height_bbox_size=$(( $__height_bbox_size + 3 )) setvar "$__var_height" $__height_bbox_size fi # No adjustemnts to width, just pass-thru the infobox width if [ "$__var_width" ]; then setvar "$__var_width" $__width_bbox_size fi # Constrain values to sensible minimums/maximums unless `-n' was passed # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_size_constrain "$__var_height" "$__var_width" } # f_dialog_inputbox_size [-n] $var_height $var_width \ # $title $backtitle $prompt $init [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--inputbox' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, and [optionally] hline. The optimal height and # width for the described widget (not exceeding the actual terminal height or # width) is stored in $var_height and $var_width (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # f_dialog_inputbox_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # Calculate height/width of buttonbox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_ibox_size __width_ibox_size f_dialog_buttonbox_size -n \ "${__var_height:+__height_ibox_size}" \ "${__var_width:+__width_ibox_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # Adjust height if desired if [ "$__var_height" ]; then # Add height for input box (not needed for Xdialog(1)) [ ! "$USE_XDIALOG" ] && __height_ibox_size=$(( $__height_ibox_size + 3 )) setvar "$__var_height" $__height_ibox_size fi # Adjust width if desired if [ "$__var_width" ]; then # Bump width for initial text (something neither dialog(1) nor # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1)) local __n=$(( ${#__init} + 7 )) [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n setvar "$__var_width" $__width_ibox_size fi # Constrain values to sensible minimums/maximums unless `-n' was passed # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_size_constrain "$__var_height" "$__var_width" } # f_xdialog_2inputsbox_size [-n] $var_height $var_width \ # $title $backtitle $prompt \ # $label1 $init1 $label2 $init2 # # Xdialog(1) does not perform auto-sizing of the width and height of # `--2inputsbox' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, label for the first field, initial text for said # field, label for the second field, and initial text for said field. The # optimal height and width for the described widget (not exceeding the actual # terminal height or width) is stored in $var_height and $var_width # (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # Xdialog(1). # f_xdialog_2inputsbox_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" local __label1="$6" __init1="$7" __label2="$8" __init2="$9" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # Calculate height/width of inputbox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_2ibox_size __width_2ibox_size f_dialog_inputbox_size -n \ "${__var_height:+__height_2ibox_size}" \ "${__var_width:+__width_2ibox_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1" # Adjust height if desired if [ "$__var_height" ]; then # Add height for 1st label, 2nd label, and 2nd input box __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 )) setvar "$__var_height" $__height_2ibox_size fi # Adjust width if desired if [ "$__var_width" ]; then local __n # Bump width for first label text (+16.6% since Xdialog(1)) __n=$(( ${#__label1} + 7 )) __n=$(( $__n + $__n / 6 )) [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n # Bump width for second label text (+16.6% since Xdialog(1)) __n=$(( ${#__label2} + 7 )) __n=$(( $__n + $__n / 6 )) [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n # Bump width for 2nd initial text (something neither dialog(1) # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1)) __n=$(( ${#__init2} + 7 )) __n=$(( $__n + $__n / 6 )) [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n setvar "$__var_width" $__width_2ibox_size fi # Constrain values to sensible minimums/maximums unless `-n' was passed # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_size_constrain "$__var_height" "$__var_width" } # f_dialog_menu_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $tag2 $item2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--menu' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the menu list itself (comprised of tag/item couplets). The # optimal height, width, and rows for the described widget (not exceeding the # actual terminal height or width) is stored in $var_height, $var_width, and # $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_menu_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" __var_rows="$3" local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || return $FAILURE # Calculate height/width of infobox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_menu_size __width_menu_size f_dialog_infobox_size -n \ "${__var_height:+__height_menu_size}" \ "${__var_width:+__width_menu_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # # Always process the menu-item arguments to get the longest tag-length, # longest item-length (both used to bump the width), and the number of # rows (used to bump the height). # local __longest_tag=0 __longest_item=0 __rows=0 while [ $# -ge 2 ]; do local __tag="$1" __item="$2" shift 2 # tag/item [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} __rows=$(( $__rows + 1 )) done # Adjust rows early (for up-comning height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) fi # Adjust height if desired if [ "$__var_height" ]; then # Add rows to height if [ "$USE_XDIALOG" ]; then __height_menu_size=$(( $__height_menu_size + $__rows + 7 )) else __height_menu_size=$(( $__height_menu_size + $__rows + 4 )) fi setvar "$__var_height" $__height_menu_size fi # Adjust width if desired if [ "$__var_width" ]; then # The sum total between the longest tag-length and the # longest item-length should be used to bump menu width local __n=$(( $__longest_tag + $__longest_item + 10 )) [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n setvar "$__var_width" $__width_menu_size fi # Store adjusted rows if desired [ "$__var_rows" ] && setvar "$__var_rows" $__rows # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_menu_constrain \ "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } # f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $help1 $tag2 $item2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--menu' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the menu list itself (comprised of tag/item/help triplets). The # optimal height, width, and rows for the described widget (not exceeding the # actual terminal height or width) is stored in $var_height, $var_width, and # $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_menu_with_help_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" __var_rows="$3" local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || return $FAILURE # Calculate height/width of infobox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_menu_with_help_size __width_menu_with_help_size f_dialog_infobox_size -n \ "${__var_height:+__height_menu_with_help_size}" \ "${__var_width:+__width_menu_with_help_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # # Always process the menu-item arguments to get the longest tag-length, # longest item-length, longest help-length (help-length only considered # if using Xdialog(1), as it places the help string in the widget) -- # all used to bump the width -- and the number of rows (used to bump # the height). # local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 while [ $# -ge 3 ]; do local __tag="$1" __item="$2" __help="$3" shift 3 # tag/item/help [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} __rows=$(( $__rows + 1 )) done # Adjust rows early (for up-coming height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) fi # Adjust height if desired if [ "$__var_height" ]; then # Add rows to height if [ "$USE_XDIALOG" ]; then __height_menu_with_help_size=$(( $__height_menu_with_help_size + $__rows + 8 )) else __height_menu_with_help_size=$(( $__height_menu_with_help_size + $__rows + 4 )) fi setvar "$__var_height" $__height_menu_with_help_size fi # Adjust width if desired if [ "$__var_width" ]; then # The sum total between the longest tag-length and the # longest item-length should be used to bump menu width local __n=$(( $__longest_tag + $__longest_item + 10 )) [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_menu_with_help_size ] && __width_menu_with_help_size=$__n # Update width for help text if using Xdialog(1) if [ "$USE_XDIALOG" ]; then __n=$(( $__longest_help + 10 )) __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_menu_with_help_size ] && __width_menu_with_help_size=$__n fi setvar "$__var_width" $__width_menu_with_help_size fi # Store adjusted rows if desired [ "$__var_rows" ] && setvar "$__var_rows" $__rows # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_menu_constrain \ "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } # f_dialog_radiolist_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $tag2 $item2 $status2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--radiolist' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the radio list itself (comprised of tag/item/status triplets). # The optimal height, width, and rows for the described widget (not exceeding # the actual terminal height or width) is stored in $var_height, $var_width, # and $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_radiolist_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" __var_rows="$3" local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || return $FAILURE # Calculate height/width of infobox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_rlist_size __width_rlist_size f_dialog_infobox_size -n \ "${__var_height:+__height_rlist_size}" \ "${__var_width:+__width_rlist_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # # Always process the menu-item arguments to get the longest tag-length, # longest item-length (both used to bump the width), and the number of # rows (used to bump the height). # local __longest_tag=0 __longest_item=0 __rows=0 while [ $# -ge 3 ]; do local __tag="$1" __item="$2" shift 3 # tag/item/status [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} __rows=$(( $__rows + 1 )) done # Adjust rows early (for up-coming height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) fi # Adjust height if desired if [ "$__var_height" ]; then # Add rows to height if [ "$USE_XDIALOG" ]; then __height_rlist_size=$(( $__height_rlist_size + $__rows + 7 )) else __height_rlist_size=$(( $__height_rlist_size + $__rows + 4 )) fi setvar "$__var_height" $__height_rlist_size fi # Adjust width if desired if [ "$__var_width" ]; then # Sum total between longest tag-length, longest item-length, # and radio-button width should be used to bump menu width local __n=$(( $__longest_tag + $__longest_item + 13 )) [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n setvar "$__var_width" $__width_rlist_size fi # Store adjusted rows if desired [ "$__var_rows" ] && setvar "$__var_rows" $__rows # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_menu_constrain \ "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } # f_dialog_checklist_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $tag2 $item2 $status2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--checklist' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the check list itself (comprised of tag/item/status triplets). # The optimal height, width, and rows for the described widget (not exceeding # the actual terminal height or width) is stored in $var_height, $var_width, # and $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_checklist_size() { f_dialog_radiolist_size "$@" } # f_dialog_radiolist_with_help_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $help1 \ # $tag2 $item2 $status2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--radiolist' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the radio list itself (comprised of tag/item/status/help # quadruplets). The optimal height, width, and rows for the described widget # (not exceeding the actual terminal height or width) is stored in $var_height, # $var_width, and $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_radiolist_with_help_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" __var_rows="$3" local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || return $FAILURE # Calculate height/width of infobox (adjusted/constrained below) # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_rlist_with_help_size __width_rlist_with_help_size f_dialog_infobox_size -n \ "${__var_height:+__height_rlist_with_help_size}" \ "${__var_width:+__width_rlist_with_help_size}" \ "$__title" "$__btitle" "$__prompt" "$__hline" # # Always process the menu-item arguments to get the longest tag-length, # longest item-length, longest help-length (help-length only considered # if using Xdialog(1), as it places the help string in the widget) -- # all used to bump the width -- and the number of rows (used to bump # the height). # local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 while [ $# -ge 4 ]; do local __tag="$1" __item="$2" __status="$3" __help="$4" shift 4 # tag/item/status/help [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} __rows=$(( $__rows + 1 )) done # Adjust rows early (for up-coming height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) fi # Adjust height if desired if [ "$__var_height" ]; then # Add rows to height if [ "$USE_XDIALOG" ]; then __height_rlist_with_help_size=$(( $__height_rlist_with_help_size + $__rows + 7 )) else __height_rlist_with_help_size=$(( $__height_rlist_with_help_size + $__rows + 4 )) fi setvar "$__var_height" $__height fi # Adjust width if desired if [ "$__var_width" ]; then # Sum total between longest tag-length, longest item-length, # and radio-button width should be used to bump menu width local __n=$(( $__longest_tag + $__longest_item + 13 )) [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_rlist_with_help_size ] && __width_rlist_with_help_size=$__n # Update width for help text if using Xdialog(1) if [ "$USE_XDIALOG" ]; then __n=$(( $__longest_help + 10 )) __n=$(( $__n + $__n / 6 )) # plus 16.6% [ $__n -gt $__width_rlist_with_help_size ] && __width_rlist_with_help_size=$__n fi setvar "$__var_width" $__width_rlist_with_help_size fi # Store adjusted rows if desired [ "$__var_rows" ] && setvar "$__var_rows" $__rows # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain [ ! "$__constrain" ] || f_dialog_menu_constrain \ "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } # f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \ # $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $help1 \ # $tag2 $item2 $status2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--checklist' boxes sensibly. # # This function helps solve this issue by taking three sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height, width, and rows. The second set of arguments # are the title, backtitle, prompt, and hline. The [optional] third set of # arguments are the check list itself (comprised of tag/item/status/help # quadruplets). The optimal height, width, and rows for the described widget # (not exceeding the actual terminal height or width) is stored in $var_height, # $var_width, and $var_rows (respectively). # # If the first argument is `-n', the calculated sizes ($var_height, $var_width, # and $var_rows) are not constrained to minimum/maximum values. # f_dialog_checklist_with_help_size() { f_dialog_radiolist_with_help_size "$@" } # f_dialog_calendar_size [-n] $var_height $var_width \ # $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--calendar' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, and [optionally] hline. The optimal height and # width for the described widget (not exceeding the actual terminal height or # width) is stored in $var_height and $var_width (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # f_dialog_calendar_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # # Obtain/Adjust minimum and maximum thresholds # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). # local __max_height_cal_size __max_width_cal_size f_dialog_max_size __max_height_cal_size __max_width_cal_size __max_width_cal_size=$(( $__max_width_cal_size - 2 )) # the calendar box will refuse to display if too wide local __min_width if [ "$USE_XDIALOG" ]; then __min_width=55 else __min_width=40 __max_height_cal_size=$(( $__max_height_cal_size - $DIALOG_CALENDAR_HEIGHT )) # When using dialog(1), we can't predict whether the user has # disabled shadow's in their `$HOME/.dialogrc' file, so we'll # subtract one for the potential shadow around the widget __max_height_cal_size=$(( $__max_height_cal_size - 1 )) fi # Calculate height if desired if [ "$__var_height" ]; then local __height __height=$( echo "$__prompt" | f_number_of_lines ) if [ "$USE_XDIALOG" ]; then # Add height to accomodate for embedded calendar widget __height=$(( $__height + $DIALOG_CALENDAR_HEIGHT - 1 )) # Also, bump height if backtitle is enabled if [ "$__btitle" ]; then local __n __n=$( echo "$__btitle" | f_number_of_lines ) __height=$(( $__height + $__n + 2 )) fi else [ "$__prompt" ] && __height=$(( $__height + 1 )) fi # Enforce maximum height, unless `-n' was passed [ "$__constrain" -a $__height -gt $__max_height_cal_size ] && __height=$__max_height_cal_size setvar "$__var_height" $__height fi # Calculate width if desired if [ "$__var_width" ]; then # NOTE: Function name appended to prevent __var_{height,width} # values from becoming local (and thus preventing setvar # from working). local __width_cal_size f_dialog_infobox_size -n "" __width_cal_size \ "$__title" "$__btitle" "$__prompt" "$__hline" # Enforce minimum/maximum width, unless `-n' was passed if [ "$__constrain" ]; then if [ $__width_cal_size -lt $__min_width ]; then __width_cal_size=$__min_width elif [ $__width_cal_size -gt $__max_width_cal_size ] then __width_cal_size=$__max_width_size fi fi setvar "$__var_width" $__width_cal_size fi return $SUCCESS } # f_dialog_timebox_size [-n] $var_height $var_width \ # $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--timebox' boxes sensibly. # # This function helps solve this issue by taking two sets of sequential # arguments. The first set of arguments are the variable names to use when # storing the calculated height and width. The second set of arguments are the # title, backtitle, prompt, and [optionally] hline. The optional height and # width for the described widget (not exceeding the actual terminal height or # width) is stored in $var_height and $var_width (respectively). # # If the first argument is `-n', the calculated sizes ($var_height and # $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # f_dialog_timebox_size() { local __constrain=1 [ "$1" = "-n" ] && __constrain= && shift 1 # -n local __var_height="$1" __var_width="$2" local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" # Return unless at least one size aspect has been requested [ "$__var_height" -o "$__var_width" ] || return $FAILURE # # Obtain/Adjust minimum and maximum thresholds # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). # local __max_height_tbox_size __max_width_tbox_size f_dialog_max_size __max_height_tbox_size __max_width_tbox_size __max_width_tbox_size=$(( $__max_width_tbox_size - 2 )) # the timebox widget refuses to display if too wide local __min_width if [ "$USE_XDIALOG" ]; then __min_width=40 else __min_width=20 __max_height_tbox_size=$(( \ $__max_height_tbox_size - $DIALOG_TIMEBOX_HEIGHT )) # When using dialog(1), we can't predict whether the user has # disabled shadow's in their `$HOME/.dialogrc' file, so we'll # subtract one for the potential shadow around the widget __max_height_tbox_size=$(( $__max_height_tbox_size - 1 )) fi # Calculate height if desired if [ "$__var_height" -a "$USE_XDIALOG" ]; then # When using Xdialog(1), the height seems to have # no effect. All values provide the same results. setvar "$__var_height" 0 # autosize elif [ "$__var_height" ]; then local __height __height=$( echo "$__prompt" | f_number_of_lines ) __height=$(( $__height ${__prompt:++1} + 1 )) # Enforce maximum height, unless `-n' was passed [ "$__constrain" -a $__height -gt $__max_height_tbox_size ] && __height=$__max_height_tbox_size setvar "$__var_height" $__height fi # Calculate width if desired if [ "$__var_width" ]; then # NOTE: Function name appended to prevent __var_{height,width} # values from becoming local (and thus preventing setvar # from working). local __width_tbox_size f_dialog_infobox_size -n "" __width_tbox_size \ "$__title" "$__btitle" "$__prompt" "$__hline" # Enforce the minimum width for displaying the timebox if [ "$__constrain" ]; then if [ $__width_tbox_size -lt $__min_width ]; then __width_tbox_size=$__min_width elif [ $__width_tbox_size -ge $__max_width_tbox_size ] then __width_tbox_size=$__max_width_tbox_size fi fi setvar "$__var_width" $__width_tbox_size fi return $SUCCESS } ############################################################ CLEAR FUNCTIONS # f_dialog_clear # # Clears any/all previous dialog(1) displays. # f_dialog_clear() { $DIALOG --clear } ############################################################ INFO FUNCTIONS # f_dialog_info $info_text ... # # Throw up a dialog(1) infobox. The infobox remains until another dialog is # displayed or `dialog --clear' (or f_dialog_clear) is called. # f_dialog_info() { local info_text="$*" height width f_dialog_infobox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ ${USE_XDIALOG:+--ignore-eof} \ ${USE_XDIALOG:+--no-buttons} \ --infobox "$info_text" $height $width } # f_xdialog_info $info_text ... # # Throw up an Xdialog(1) infobox and do not dismiss it until stdin produces # EOF. This implies that you must execute this either as an rvalue to a pipe, # lvalue to indirection or in a sub-shell that provides data on stdin. # f_xdialog_info() { local info_text="$*" height width f_dialog_infobox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --no-close --no-buttons \ --infobox "$info_text" $height $width \ -1 # timeout of -1 means abort when EOF on stdin } ############################################################ MSGBOX FUNCTIONS # f_dialog_msgbox $msg_text ... # # Throw up a dialog(1) msgbox. The msgbox remains until the user presses ENTER # or ESC, acknowledging the modal dialog. # # If the user presses ENTER, the exit status is zero (success), otherwise if # the user presses ESC the exit status is 255. # f_dialog_msgbox() { local msg_text="$*" height width f_dialog_buttonbox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --ok-label "$msg_ok" \ --msgbox "$msg_text" $height $width } ############################################################ TEXTBOX FUNCTIONS # f_dialog_textbox $file # # Display the contents of $file (or an error if $file does not exist, etc.) in # a dialog(1) textbox (which has a scrollable region for the text). The textbox # remains until the user presses ENTER or ESC, acknowledging the modal dialog. # # If the user presses ENTER, the exit status is zero (success), otherwise if # the user presses ESC the exit status is 255. # f_dialog_textbox() { local file="$1" local contents height width retval contents=$( cat "$file" 2>&1 ) retval=$? f_dialog_buttonbox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$contents" if [ $retval -eq $SUCCESS ]; then $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --exit-label "$msg_ok" \ --no-cancel \ --textbox "$file" $height $width else $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --ok-label "$msg_ok" \ --msgbox "$contents" $height $width fi } ############################################################ YESNO FUNCTIONS # f_dialog_yesno $msg_text ... # # Display a dialog(1) Yes/No prompt to allow the user to make some decision. # The yesno prompt remains until the user presses ENTER or ESC, acknowledging # the modal dialog. # # If the user chooses YES the exit status is zero, or chooses NO the exit # status is one, or presses ESC the exit status is 255. # f_dialog_yesno() { local msg_text="$*" height width local hline="$hline_arrows_tab_enter" f_interactive || return 0 # If non-interactive, return YES all the time f_dialog_buttonbox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" if [ "$USE_XDIALOG" ]; then $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$hline" \ --ok-label "$msg_yes" \ --cancel-label "$msg_no" \ --yesno "$msg_text" $height $width else $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$hline" \ --yes-label "$msg_yes" \ --no-label "$msg_no" \ --yesno "$msg_text" $height $width fi } # f_dialog_noyes $msg_text ... # # Display a dialog(1) No/Yes prompt to allow the user to make some decision. # The noyes prompt remains until the user presses ENTER or ESC, acknowledging # the modal dialog. # # If the user chooses YES the exit status is zero, or chooses NO the exit # status is one, or presses ESC the exit status is 255. # # NOTE: This is just like the f_dialog_yesno function except "No" is default. # f_dialog_noyes() { local msg_text="$*" height width local hline="$hline_arrows_tab_enter" f_interactive || return 1 # If non-interactive, return NO all the time f_dialog_buttonbox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" if [ "$USE_XDIALOG" ]; then $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$hline" \ --default-no \ --ok-label "$msg_yes" \ --cancel-label "$msg_no" \ --yesno "$msg_text" $height $width else $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$hline" \ --defaultno \ --yes-label "$msg_yes" \ --no-label "$msg_no" \ --yesno "$msg_text" $height $width fi } ############################################################ INPUT FUNCTIONS # f_dialog_inputstr_store [-s] $text # # Store some text from a dialog(1) inputbox to be retrieved later by # f_dialog_inputstr_fetch(). If the first argument is `-s', the text is # sanitized before being stored. # f_dialog_inputstr_store() { local sanitize= [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s local text="$1" # Sanitize the line before storing it if desired [ "$sanitize" ] && f_dialog_line_sanitize text setvar DIALOG_INPUTBOX_$$ "$text" } # f_dialog_inputstr_fetch [$var_to_set] # # Obtain the inputstr entered by the user from the most recently displayed # dialog(1) inputbox (previously stored with f_dialog_inputstr_store() above). # If $var_to_set is NULL or missing, output is printed to stdout (which is less # recommended due to performance degradation; in a loop for example). # f_dialog_inputstr_fetch() { local __var_to_set="$1" __cp debug= f_getvar DIALOG_INPUTBOX_$$ "${__var_to_set:-__cp}" # get data setvar DIALOG_INPUTBOX_$$ "" # scrub memory in case data was sensitive # Return the line on standard-out if desired [ "$__var_to_set" ] || echo "$__cp" return $SUCCESS } # f_dialog_input $var_to_set $prompt [$init [$hline]] # # Prompt the user with a dialog(1) inputbox to enter some value. The inputbox # remains until the the user presses ENTER or ESC, or otherwise ends the # editing session, by selecting `Cancel' for example. # # If the user presses ENTER, the exit status is zero (success), otherwise if # the user presses ESC the exit status is 255, or if the user chose Cancel, the # exit status is instead 1. # # NOTE: The hline should correspond to the type of data you want from the user. # NOTE: Should not be used to edit multiline values. # f_dialog_input() { local __var_to_set="$1" __prompt="$2" __init="$3" __hline="$4" # NOTE: Function name appended to prevent __var_{height,width} values # from becoming local (and thus preventing setvar from working). local __height_input __width_input f_dialog_inputbox_size __height_input __width_input \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \ "$__prompt" "$__init" "$__hline" local __opterm="--" [ "$USE_XDIALOG" ] && __opterm= local __dialog_input __dialog_input=$( $DIALOG \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --hline "$__hline" \ --ok-label "$msg_ok" \ --cancel-label "$msg_cancel" \ --inputbox "$__prompt" \ $__height_input $__width_input \ $__opterm "$__init" \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local __retval=$? # Remove warnings and leading/trailing whitespace from user input f_dialog_line_sanitize __dialog_input setvar "$__var_to_set" "$__dialog_input" return $__retval } ############################################################ MENU FUNCTIONS # f_dialog_menutag_store [-s] $text # # Store some text from a dialog(1) menu to be retrieved later by # f_dialog_menutag_fetch(). If the first argument is `-s', the text is # sanitized before being stored. # f_dialog_menutag_store() { local sanitize= [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s local text="$1" # Sanitize the menutag before storing it if desired [ "$sanitize" ] && f_dialog_data_sanitize text setvar DIALOG_MENU_$$ "$text" } # f_dialog_menutag_fetch [$var_to_set] # # Obtain the menutag chosen by the user from the most recently displayed # dialog(1) menu (previously stored with f_dialog_menutag_store() above). If # $var_to_set is NULL or missing, output is printed to stdout (which is less # recommended due to performance degradation; in a loop for example). # f_dialog_menutag_fetch() { local __var_to_set="$1" __cp debug= f_getvar DIALOG_MENU_$$ "${__var_to_set:-__cp}" # get the data setvar DIALOG_MENU_$$ "" # scrub memory in case data was sensitive # Return the data on standard-out if desired [ "$__var_to_set" ] || echo "$__cp" return $SUCCESS } +# f_dialog_default_store [-s] $text +# +# Store some text to be used later as the --default-item argument to dialog(1) +# (or Xdialog(1)) for --menu, --checklist, and --radiolist widgets. Retrieve +# the text later with f_dialog_menutag_fetch(). If the first argument is `-s', +# the text is sanitized before being stored. +# +f_dialog_default_store() +{ + local sanitize= + [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s + local text="$1" + + # Sanitize the defaulitem before storing it if desired + [ "$sanitize" ] && f_dialog_data_sanitize text + + setvar DEFAULTITEM_$$ "$text" +} + +# f_dialog_default_fetch [$var_to_set] +# +# Obtain text to be used with the --default-item argument of dialog(1) (or +# Xdialog(1)) (previously stored with f_dialog_default_store() above). If +# $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +f_dialog_default_fetch() +{ + local __var_to_set="$1" __cp + + debug= f_getvar DEFAULTITEM_$$ "${__var_to_set:-__cp}" # get the data + setvar DEFAULTITEM_$$ "" # scrub memory in case data was sensitive + + # Return the data on standard-out if desired + [ "$__var_to_set" ] || echo "$__cp" + + return $SUCCESS +} + # f_dialog_menutag2item $tag_chosen $tag1 $item1 $tag2 $item2 ... # # To use the `--menu' option of dialog(1) you must pass an ordered list of # tag/item pairs on the command-line. When the user selects a menu option the # tag for that item is printed to stderr. # # This function allows you to dereference the tag chosen by the user back into # the item associated with said tag. # # Pass the tag chosen by the user as the first argument, followed by the # ordered list of tag/item pairs (HINT: use the same tag/item list as was # passed to dialog(1) for consistency). # # If the tag cannot be found, NULL is returned. # f_dialog_menutag2item() { local tag="$1" tagn item shift 1 # tag while [ $# -gt 0 ]; do tagn="$1" item="$2" shift 2 # tagn/item if [ "$tag" = "$tagn" ]; then echo "$item" return $SUCCESS fi done return $FAILURE } # f_dialog_menutag2item_with_help $tag_chosen $tag1 $item1 $help1 \ # $tag2 $item2 $help2 ... # # To use the `--menu' option of dialog(1) with the `--item-help' option, you # must pass an ordered list of tag/item/help triplets on the command-line. When # the user selects a menu option the tag for that item is printed to stderr. # # This function allows you to dereference the tag chosen by the user back into # the item associated with said tag (help is discarded/ignored). # # Pass the tag chosen by the user as the first argument, followed by the # ordered list of tag/item/help triplets (HINT: use the same tag/item/help list # as was passed to dialog(1) for consistency). # # If the tag cannot be found, NULL is returned. # f_dialog_menutag2item_with_help() { local tag="$1" tagn item shift 1 # tag while [ $# -gt 0 ]; do tagn="$1" item="$2" shift 3 # tagn/item/help if [ "$tag" = "$tagn" ]; then echo "$item" return $SUCCESS fi done return $FAILURE } # f_dialog_menutag2index $tag_chosen $tag1 $item1 $tag2 $item2 ... # # To use the `--menu' option of dialog(1) you must pass an ordered list of # tag/item pairs on the command-line. When the user selects a menu option the # tag for that item is printed to stderr. # # This function allows you to dereference the tag chosen by the user back into # the index associated with said tag. The index is the one-based tag/item pair # array position within the ordered list of tag/item pairs passed to dialog(1). # # Pass the tag chosen by the user as the first argument, followed by the # ordered list of tag/item pairs (HINT: use the same tag/item list as was # passed to dialog(1) for consistency). # # If the tag cannot be found, NULL is returned. # f_dialog_menutag2index() { local tag="$1" tagn n=1 shift 1 # tag while [ $# -gt 0 ]; do tagn="$1" shift 2 # tagn/item if [ "$tag" = "$tagn" ]; then echo $n return $SUCCESS fi n=$(( $n + 1 )) done return $FAILURE } # f_dialog_menutag2index_with_help $tag_chosen $tag1 $item1 $help1 \ # $tag2 $item2 $help2 ... # # To use the `--menu' option of dialog(1) with the `--item-help' option, you # must pass an ordered list of tag/item/help triplets on the command-line. When # the user selects a menu option the tag for that item is printed to stderr. # # This function allows you to dereference the tag chosen by the user back into # the index associated with said tag. The index is the one-based tag/item/help # triplet array position within the ordered list of tag/item/help triplets # passed to dialog(1). # # Pass the tag chosen by the user as the first argument, followed by the # ordered list of tag/item/help triplets (HINT: use the same tag/item/help list # as was passed to dialog(1) for consistency). # # If the tag cannot be found, NULL is returned. # f_dialog_menutag2index_with_help() { local tag="$1" tagn n=1 shift 1 # tag while [ $# -gt 0 ]; do tagn="$1" shift 3 # tagn/item/help if [ "$tag" = "$tagn" ]; then echo $n return $SUCCESS fi n=$(( $n + 1 )) done return $FAILURE } ############################################################ INIT FUNCTIONS # f_dialog_init # # Initialize (or re-initialize) the dialog module after setting/changing any # of the following environment variables: # # USE_XDIALOG Either NULL or Non-NULL. If given a value will indicate # that Xdialog(1) should be used instead of dialog(1). # # SECURE Either NULL or Non-NULL. If given a value will indicate # that (while running as root) sudo(8) authentication is # required to proceed. # f_dialog_init() { DIALOG_SELF_INITIALIZE= # # Clone terminal stdout so we can redirect to it from within sub-shells # eval exec $DIALOG_TERMINAL_PASSTHRU_FD\>\&1 # # Add `-S' and `-X' to the list of standard arguments supported by all # case "$GETOPTS_STDARGS" in *SX*) : good ;; # already present *) GETOPTS_STDARGS="${GETOPTS_STDARGS}SX" esac # # Process stored command-line arguments # f_dprintf "f_dialog_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \ "$ARGV" "$GETOPTS_STDARGS" SECURE=$( set -- $ARGV while getopts "$GETOPTS_STDARGS" flag > /dev/null; do case "$flag" in S) echo 1;; \?) continue;; esac done ) USE_XDIALOG=$( set -- $ARGV while getopts $GETOPTS_STDARGS flag > /dev/null; do case "$flag" in S|X) echo 1;; \?) continue;; esac done ) f_dprintf "f_dialog_init: SECURE=[%s] USE_XDIALOG=[%s]" \ "$SECURE" "$USE_XDIALOG" # # Process `-X' command-line option # [ "$USE_XDIALOG" ] && DIALOG=Xdialog # # Sanity check, or die gracefully # if ! f_have $DIALOG; then unset USE_XDIALOG failed_dialog="$DIALOG" DIALOG=dialog f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$failed_dialog" fi # # If we're already running as root but we got there by way of sudo(8) # and we have X11, we should merge the xauth(1) credentials from our # original user. # if [ "$USE_XDIALOG" ] && [ "$( id -u )" = "0" ] && [ "$SUDO_USER" -a "$DISPLAY" ] then if ! f_have xauth; then # Die gracefully, as we [likely] can't use Xdialog(1) unset USE_XDIALOG DIALOG=dialog f_die 1 "$msg_no_such_file_or_directory" "$pgm" "xauth" fi HOSTNAME=$(hostname) displaynum="${DISPLAY#*:}" eval xauth -if \~$SUDO_USER/.Xauthority extract - \ \"\$HOSTNAME/unix:\$displaynum\" \ \"\$HOSTNAME:\$displaynum\" | sudo sh -c 'xauth -ivf \ ~root/.Xauthority merge - > /dev/null 2>&1' fi # # Probe Xdialog(1) for maximum height/width constraints, or die # gracefully # if [ "$USE_XDIALOG" ]; then if ! maxsize=$( LANG= LC_ALL= $DIALOG --print-maxsize 2>&1 ) then # Xdialog(1) failed, fall back to dialog(1) unset USE_XDIALOG # Display the error message produced by Xdialog(1) local height width f_dialog_buttonbox_size height width \ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$maxsize" dialog \ --title "$DIALOG_TITLE" \ --backtitle "$DIALOG_BACKTITLE" \ --ok-label "$msg_ok" \ --msgbox "$maxsize" $height $width exit $FAILURE fi XDIALOG_MAXSIZE=$( set -- ${maxsize##*:} height=${1%,} width=$2 echo $height $width ) unset maxsize fi # # If using Xdialog(1), swap DIALOG_TITLE with DIALOG_BACKTITLE. # The reason for this is because many dialog(1) applications use # --backtitle for the program name (which is better suited as # --title with Xdialog(1)). # if [ "$USE_XDIALOG" ]; then _DIALOG_TITLE="$DIALOG_TITLE" DIALOG_TITLE="$DIALOG_BACKTITLE" DIALOG_BACKTITLE="$_DIALOG_TITLE" unset _DIALOG_TITLE fi f_dprintf "f_dialog_init: dialog(1) API initialized." } ############################################################ MAIN # # Self-initialize unless requested otherwise # f_dprintf "%s: DIALOG_SELF_INITIALIZE=[%s]" \ dialog.subr "$DIALOG_SELF_INITIALIZE" case "$DIALOG_SELF_INITIALIZE" in ""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;; *) f_dialog_init esac f_dprintf "%s: Successfully loaded." dialog.subr fi # ! $_DIALOG_SUBR Index: head/usr.sbin/bsdconfig/startup/misc =================================================================== --- head/usr.sbin/bsdconfig/startup/misc (revision 251243) +++ head/usr.sbin/bsdconfig/startup/misc (revision 251244) @@ -1,434 +1,434 @@ #!/bin/sh #- # 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 (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/mustberoot.subr f_include $BSDCFG_SHARE/sysrc.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ GLOBALS # # Operating environment # UNAME_P=$( uname -p ) # Processor Architecture (i.e. i386) ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list var_list defaultitem= local hline="$hline_arrows_tab_enter" local prompt="$msg_miscellaneous_menu_text" # Obtain default-item (adjusted below for dynamic tags) - f_getvar DEFAULTITEM_$$ defaultitem + f_dialog_default_fetch defaultitem local ditem="${defaultitem%%[$IFS]*}" menu_list=" 'X <<< $msg_exit' '$msg_exit_this_menu' " # END-QUOTE var_list=" accounting_enable local_startup lpd_enable named_enable named_flags nis_client_enable nis_server_enable nisdomainname startup_dirs " # END-QUOTE if [ "$UNAME_P" = "i386" ]; then var_list="$var_list apm_enable ibcs2_enable svr4_enable " # END-QUOTE fi eval "$( . "$RC_DEFAULTS" source_rc_confs export $var_list export msg_apm msg_apm_desc export msg_startup_dirs msg_startup_dirs_desc export msg_named msg_named_desc export msg_named_flags msg_named_flags_desc export msg_nis_client msg_nis_client_desc export msg_nis_domainname msg_nis_domainname_desc export msg_nis_server msg_nis_server_desc export msg_accounting msg_accounting_desc export msg_lpd msg_lpd_desc export msg_sco msg_sco_desc export msg_svr4 msg_svr4_desc :| awk \ -v uname_p="$UNAME_P" \ -v menu_tags="$DIALOG_MENU_TAGS" \ -v menu_fmt="'%s' '%s'\n" \ -v mtag_fmt="%c [%c] %s" \ -v separator="' ' ' -- '\n" \ -v ditem="$ditem" \ ' function mprint(tag,item) { printf menu_fmt, tag, item } END { i = 1 defaultitem = "" printf "menu_list=\"$menu_list\n" if ( uname_p == "i386" ) { # # APM: Auto-power management services # (typically laptops) # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["apm_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_apm"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_apm_desc"]) if (ditem == char) defaultitem = tag } printf separator # # Startup dirs: Set the list of dirs to look for # startup scripts # char = substr(menu_tags, i++, 1) mark = ( length(ENVIRON["local_startup"]) > 0 \ ? "X" : " " ) subtag = ENVIRON["msg_startup_dirs"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_startup_dirs_desc"]) if (ditem == char) defaultitem = tag # # named: Run a local name server on this host # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["named_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_named"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_named_desc"]) if (ditem == char) defaultitem = tag # # named flags: Set default flags to named (if enabled) # char = substr(menu_tags, i++, 1) mark = ( length(ENVIRON["named_flags"]) > 0 \ ? "X" : " " ) subtag = ENVIRON["msg_named_flags"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_named_flags_desc"]) if (ditem == char) defaultitem = tag # # NIS client: This host wishes to be an NIS client. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["nis_client_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_nis_client"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_nis_client_desc"]) if (ditem == char) defaultitem = tag # # NIS domainname: Set NIS domainname (if enabled) # char = substr(menu_tags, i++, 1) mark = ( length(ENVIRON["nisdomainname"]) > 0 && \ ENVIRON["nisdomainname"] != "NO" \ ? "X" : " " ) subtag = ENVIRON["msg_nis_domainname"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_nis_domainname_desc"]) if (ditem == char) defaultitem = tag # # NIS server: This host wishes to be an NIS server. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["nis_server_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_nis_server"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_nis_server_desc"]) if (ditem == char) defaultitem = tag printf separator # # Accounting: This host wishes to run process # accounting. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["accounting_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_accounting"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_accounting_desc"]) if (ditem == char) defaultitem = tag # # lpd: This host has a printer and wants to run lpd. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["lpd_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_lpd"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_lpd_desc"]) if (ditem == char) defaultitem = tag if ( uname_p == "i386" ) { # # SCO: This host wants to be able to run IBCS2 # binaries. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["ibcs2_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_sco"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_sco_desc"]) if (ditem == char) defaultitem = tag # # SVR4: This host wants to be able to run SVR4 # binaries. # char = substr(menu_tags, i++, 1) mark = ( ENVIRON["svr4_enable"] ~ \ /^[Yy][Ee][Ss]$/ ? "X" : " " ) subtag = ENVIRON["msg_svr4"] tag = sprintf(mtag_fmt, char, mark, subtag) mprint(tag, ENVIRON["msg_svr4_desc"]) if (ditem == char) defaultitem = tag } printf "\"\n" if ( defaultitem ) printf "defaultitem=\"%s\"\n", defaultitem }' )" local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list local menu_choice menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --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" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } # dialog_input_value [ $prompt [ $init ] ] # # Prompt the user to input a value. If the user does not cancel or press ESC, # the return value is zero ($SUCCESS) and $value holds the user's input. # dialog_input_value() { local prompt="$1" _input="$2" f_dialog_title "$msg_value_required" f_dialog_input _input "$prompt" "$_input" "$hline_alnum_tab_enter" local retval=$? f_dialog_title_restore # Return if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || return $retval value="$_input" return $SUCCESS } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_miscellaneous_startup_services" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in "X <<< $msg_exit") break ;; ?" ["?"] $msg_apm") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set apm_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set apm_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_startup_dirs") dialog_input_value \ "$msg_startup_dirs_desc" \ "$( f_sysrc_get local_startup )" if [ $? -eq $SUCCESS ]; then err=$( f_sysrc_set local_startup "$value" ) || f_dialog_msgbox "$err\n" fi ;; ?" ["?"] $msg_named") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set named_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set named_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_named_flags") dialog_input_value \ "$msg_named_flags_desc" \ "$( f_sysrc_get named_flags )" if [ $? -eq $SUCCESS ]; then err=$( f_sysrc_set named_flags "$value" ) || f_dialog_msgbox "$err\n" fi ;; ?" ["?"] $msg_nis_client") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set nis_client_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set nis_client_enable YES 2>&1 ) \ && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_nis_domainname") dialog_input_value \ "$msg_nis_domainname_desc" \ "$( f_sysrc_get nisdomainname )" if [ $? -eq $SUCCESS ]; then err=$( f_sysrc_set nisdomainname "$value" ) || f_dialog_msgbox "$err\n" fi ;; ?" ["?"] $msg_nis_server") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set nis_server_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set nis_server_enable YES 2>&1 ) \ && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_accounting") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set accounting_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set accounting_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_lpd") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set lpd_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set lpd_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_sco") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; ?" ["?"] $msg_svr4") case "$mtag" in ?" [X] "*) err=$( f_sysrc_set svr4_enable NO 2>&1 ) ;; ?" [ ] "*) err=$( f_sysrc_set svr4_enable YES 2>&1 ) ;; esac [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/startup/rcconf =================================================================== --- head/usr.sbin/bsdconfig/startup/rcconf (revision 251243) +++ head/usr.sbin/bsdconfig/startup/rcconf (revision 251244) @@ -1,259 +1,263 @@ #!/bin/sh #- # 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 (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/mustberoot.subr f_include $BSDCFG_SHARE/sysrc.subr f_include $BSDCFG_SHARE/startup/rcconf.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ GLOBALS # # Global map/menu-list for the main menu # RCCONF_MAP= _RCCONF_MAP= RCCONF_MENU_LIST= # # Options # # Inherit SHOW_DESC value if set, otherwise default to 1 [ "${SHOW_DESC+set}" ] || SHOW_DESC=1 # Selectively inherit SHOW_* value (in order of preference) if [ "$SHOW_DEFAULT_VALUE" ]; then SHOW_DEFAULT_VALUE=1 SHOW_CONFIGURED= SHOW_VALUE= elif [ "$SHOW_CONFIGURED" ]; then SHOW_DEFAULT_VALUE= SHOW_CONFIGURED=1 SHOW_VALUE= else SHOW_DEFAULT_VALUE= SHOW_CONFIGURED= SHOW_VALUE=1 fi ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below RCCONF_MENU_LIST=" 'X $msg_exit' '$msg_exit_desc' ${SHOW_DESC:+'$msg_exit_help'} '> $msg_add_new' '$msg_add_new_desc' ${SHOW_DESC:+'$msg_add_new_help'} '> $msg_delete' '$msg_delete_desc' ${SHOW_DESC:+'$msg_delete_help'} ${USE_XDIALOG:+ '> $msg_view_details' '$msg_view_details_desc' ${SHOW_DESC:+'$msg_view_details_help'} } " # END-QUOTE if [ ! "$_RCCONF_MAP" ]; then # Genreate RCCONF_MAP of `var desc ...' per-line f_dialog_info "$msg_creating_rcconf_map" f_startup_rcconf_map RCCONF_MAP export RCCONF_MAP # Generate _${var}_desc variables from $RCCONF_MAP f_startup_rcconf_map_expand RCCONF_MAP export _RCCONF_MAP=1 fi # Show infobox for modes that take a while to calculate/display [ "$SHOW_DEFAULT_VALUE" -o "$SHOW_CONFIGURED" ] && f_dialog_info "$msg_creating_menu_list" RCCONF_MENU_LIST="$RCCONF_MENU_LIST $( . "$RC_DEFAULTS" > /dev/null source_rc_confs > /dev/null var_list=$( f_startup_rcconf_list ) for var in $var_list; do eval export $var [ "$SHOW_DEFAULT_VALUE" ] && export \ _${var}_default="$( f_sysrc_get_default $var )" [ "$SHOW_CONFIGURED" ] && export \ _${var}_file="$( f_sysrc_find $var )" done export SHOW_VALUE SHOW_DESC SHOW_DEFAULT_VALUE SHOW_CONFIGURED export msg_default_value echo "$var_list" | awk ' BEGIN { prefix = "" } { cur_prefix = tolower(substr($1, 1, 1)) printf "'\''" if ( prefix != cur_prefix ) prefix = cur_prefix else printf " " var = $1 printf "%s'\'' '\''", var if ( ENVIRON["SHOW_DEFAULT_VALUE"] ) { default = ENVIRON["_" var "_default"] gsub(/'\''/, "'\''\\'\'\''", default) value = ENVIRON[var] gsub(/'\''/, "'\''\\'\'\''", value) printf ENVIRON["msg_default_value"] "; %s", default, value } else if ( ENVIRON["SHOW_CONFIGURED"] ) { printf "%s", ENVIRON["_" var "_file"] } else { # SHOW_VALUE (default behavior) value = ENVIRON[var] gsub(/'\''/, "'\''\\'\'\''", value) printf "%s", value } printf "'\''" if ( ENVIRON["SHOW_DESC"] ) { desc = ENVIRON["_" var "_desc"] gsub(/'\''/, "'\''\\'\'\''", desc) printf " '\''%s'\''", desc } printf "\n" }' )" set -f # noglob local height width rows eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $RCCONF_MENU_LIST + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_details\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $RCCONF_MENU_LIST \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_details\" \ + ${SHOW_DESC:+--item-help} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $RCCONF_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 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_view_edit_startup_configuration" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init while :; do dialog_menu_main retval=$? f_dialog_menutag_fetch mtag if [ "$USE_XDIALOG" ]; then case "$mtag" in "> $msg_view_details") f_dialog_input_view_details continue esac elif [ $retval -eq 2 ]; then # The ``Help'' button (labeled "Details") was pressed f_dialog_input_view_details continue fi [ $retval -eq 0 ] || f_die case "$mtag" in "X $msg_exit") break ;; "> $msg_add_new") $BSDCFG_LIBE/$APP_DIR/rcadd ${USE_XDIALOG:+-X} ;; "> $msg_delete") # rcdelete has a similar interface that can inherit the below: export SHOW_VALUE SHOW_DESC SHOW_DEFAULT_VALUE SHOW_CONFIGURED $BSDCFG_LIBE/$APP_DIR/rcdelete ${USE_XDIALOG:+-X} ;; *) # Anything else is a variable to edit $BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} "${mtag# }" esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/startup/rcdelete =================================================================== --- head/usr.sbin/bsdconfig/startup/rcdelete (revision 251243) +++ head/usr.sbin/bsdconfig/startup/rcdelete (revision 251244) @@ -1,409 +1,413 @@ #!/bin/sh #- # 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 (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/mustberoot.subr f_include $BSDCFG_SHARE/sysrc.subr f_include $BSDCFG_SHARE/startup/rcconf.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ GLOBALS # # Global map/menu-list for the main menu # RCCONF_MAP= RCCONF_MENU_LIST= # # Options # # Inherit SHOW_DESC value if set, otherwise default to 1 [ "${SHOW_DESC+set}" ] || SHOW_DESC=1 # Selectively inherit SHOW_* value (in order of preference) if [ "$SHOW_DEFAULT_VALUE" ]; then SHOW_DEFAULT_VALUE=1 SHOW_CONFIGURED= SHOW_VALUE= elif [ "$SHOW_CONFIGURED" ]; then SHOW_DEFAULT_VALUE= SHOW_CONFIGURED=1 SHOW_VALUE= else SHOW_DEFAULT_VALUE= SHOW_CONFIGURED= SHOW_VALUE=1 fi ############################################################ FUNCTIONS # dialog_create_main # # Create the dialog(1) main menu. Separated from dialog_menu_main (used to # display the menu) to speed up execution (we only call this function when # initializing or changing the view details). # dialog_create_main() { # Show infobox for modes that take a while to calculate/display [ "$SHOW_DEFAULT_VALUE" -o "$SHOW_CONFIGURED" ] && f_dialog_info "$msg_creating_menu_list" RCCONF_MENU_LIST=$( . "$RC_DEFAULTS" > /dev/null source_rc_confs > /dev/null var_list=$( f_startup_rcconf_list ) for var in $var_list; do eval export $var [ "$SHOW_DEFAULT_VALUE" ] && export \ _${var}_default="$( f_sysrc_get_default $var )" [ "$SHOW_CONFIGURED" ] && export \ _${var}_file="$( f_sysrc_find $var )" done export SHOW_VALUE SHOW_DESC SHOW_DEFAULT_VALUE SHOW_CONFIGURED export msg_default_value echo "$var_list" | awk ' BEGIN { prefix = "" } { cur_prefix = tolower(substr($1, 1, 1)) printf "'\''" if ( prefix != cur_prefix ) prefix = cur_prefix else printf " " var = $1 printf "%s'\'' '\''[", var if ( ENVIRON["_" var "_delete"] ) printf "X" else printf " " printf "] " if ( ENVIRON["SHOW_DEFAULT_VALUE"] ) { default = ENVIRON["_" var "_default"] gsub(/'\''/, "'\''\\'\'\''", default) value = ENVIRON[var] gsub(/'\''/, "'\''\\'\'\''", value) printf ENVIRON["msg_default_value"] "; %s", default, value } else if ( ENVIRON["SHOW_CONFIGURED"] ) { printf "%s", ENVIRON["_" var "_file"] } else { # SHOW_VALUE (default behavior) value = ENVIRON[var] gsub(/'\''/, "'\''\\'\'\''", value) printf "%s", value } printf "'\''" if ( ENVIRON["SHOW_DESC"] ) { desc = ENVIRON["_" var "_desc"] gsub(/'\''/, "'\''\\'\'\''", desc) printf " '\''%s'\''", desc } printf "\n" }' ) } # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below # # [Re-]Accent the menu list before incorporating it # local rcconf_var details help menu_buf delete eval set -- $RCCONF_MENU_LIST while [ $# -gt 0 ]; do rcconf_var="$1" details="$2" delete= f_shell_escape "$details" details if [ "$SHOW_DESC" ]; then help="$3" f_shell_escape "$help" help shift 3 # rcconf_var/details/help else shift 2 # rcconf_var/details fi # Update mark f_getvar _${rcconf_var# }_delete delete if [ "$delete" ]; then details="[X]${details#???}" else details="[ ]${details#???}" fi # Update buffer with modified elements menu_buf="$menu_buf '$rcconf_var' '$details' ${SHOW_DESC:+'$help'}" # End-Quote done local menu_list=" 'X $msg_exit_cancel' '$msg_exit_cancel_desc' ${SHOW_DESC:+'$msg_exit_cancel_help'} '> $msg_delete_selected' '$msg_delete_selected_desc' ${SHOW_DESC:+'$msg_delete_selected_help'} '> $msg_all' '$msg_all_desc' ${SHOW_DESC:+'$msg_all_help'} '> $msg_none' '$msg_none_desc' ${SHOW_DESC:+'$msg_none_help'} ${USE_XDIALOG:+ '> $msg_view_details' '$msg_view_details_desc' ${SHOW_DESC:+'$msg_view_details_help'} } $menu_buf " # END-QUOTE set -f # noglob (descriptions in $RCCONF_MENU_LIST may contain *) local height width rows eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --keep-tite \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_details\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --keep-tite \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_details\" \ + ${SHOW_DESC:+--item-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 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } # dialog_menu_confirm_delete $var1 [$var2 ...] # # Get the user's blessing to delete one or more variables. Returns success if # (and only-if) the user confirms (does not press ESC or Cancel/NO). Does NOT # return the user's menu-choice. # dialog_menu_confirm_delete() { local hline="$hline_arrows_tab_enter" local prompt="$msg_are_you_sure_you_want_delete_the_following" local var_list menu_list [ $# -ge 1 ] || return $FAILURE if [ $# -eq 1 ]; then f_noyes "$msg_are_you_sure_you_want_to_delete" "$delete_vars" return $? fi var_list=$( for var in $*; do echo "$var"; done | sort -u ) menu_list=$( . "$RC_DEFAULTS" source_rc_confs echo "$var_list" | awk ' BEGIN { prefix = "" } { cur_prefix = tolower(substr($1, 1, 1)) printf "'\''" if ( prefix != cur_prefix ) prefix = cur_prefix else printf " " var = $1 printf "%s'\'' '\'\''\n", var }' ) local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list local defaultno="defaultno" [ "$USE_XDIALOG" ] && defaultno="default-no" eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ --$defaultno \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --menu \"\$prompt\" \ $height $width $rows \ $menu_list \ 2> /dev/null # Menu choice ignored; status of above command returned } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_delete_startup_directives" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # Genreate $RCCONF_MAP of `var desc ...' per-line (see share/rcconf.subr) f_dialog_info "$msg_creating_rcconf_map" f_startup_rcconf_map RCCONF_MAP # Generate _${var}_desc variables from $RCCONF_MAP f_startup_rcconf_map_expand RCCONF_MAP # Generate RCCONF_MENU_LIST from $RCCONF_MAP dialog_create_main while :; do dialog_menu_main retval=$? f_dialog_menutag_fetch mtag if [ "$USE_XDIALOG" ]; then case "$mtag" in "> $msg_view_details") f_dialog_input_view_details && dialog_create_main continue esac elif [ $retval -eq 2 ]; then # The ``Help'' button (labeled "Details") was pressed f_dialog_input_view_details && dialog_create_main continue fi [ $retval -eq 0 ] || f_die case "$mtag" in "X $msg_exit_cancel") break ;; "> $msg_delete_selected") delete_vars= for var in $( f_startup_rcconf_list ); do [ "$( eval echo \$_${var}_delete )" ] || continue delete_vars="$delete_vars${delete_vars:+ }$var" done unset var # no longer needed if dialog_menu_confirm_delete $delete_vars; then f_dialog_title "$msg_info" f_dialog_info "$msg_deleting_selected_directives" f_dialog_title_restore for var in $delete_vars; do err=$( f_sysrc_delete $var 2>&1 ) if [ $? -ne $SUCCESS ]; then f_dialog_msgbox "$err\n" break fi done unset var # no longer needed dialog_create_main fi ;; "> $msg_all") for var in $( f_startup_rcconf_list ); do setvar _${var}_delete 1 export _${var}_delete done unset var # no longer needed ;; "> $msg_none") var_list=$( set | awk -F= " /$STARTUP_RCCONF_REGEX/ { if (\$1 ~ /^_[[:alpha:]_][[:alnum:]_]*_delete/) print \$1 }" ) [ "$var_list" ] && unset $var_list unset var_list # no longer needed ;; *) # Anything else is a variable to edit var="${mtag# }" # Toggle the state-variable and loop back to menu if f_isset _${var}_delete; then unset _${var}_delete else setvar _${var}_delete 1 export _${var}_delete fi unset var # no longer needed esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/startup/rcvar =================================================================== --- head/usr.sbin/bsdconfig/startup/rcvar (revision 251243) +++ head/usr.sbin/bsdconfig/startup/rcvar (revision 251244) @@ -1,208 +1,212 @@ #!/bin/sh #- # 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 (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/mustberoot.subr f_include $BSDCFG_SHARE/sysrc.subr f_include $BSDCFG_SHARE/startup/rcvar.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ GLOBALS # # Global map/menu-list for the main menu # RCVAR_MAP= _RCVAR_MAP= RCVAR_MENU_LIST= # # Options # # Inherit SHOW_DESC value if set, otherwise default to 1 [ "${SHOW_DESC+set}" ] || SHOW_DESC=1 ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below RCVAR_MENU_LIST=" 'X $msg_exit' '$msg_exit_this_menu' ${SHOW_DESC:+'$msg_exit_this_menu'} " # END-QUOTE if [ ! "$_RCVAR_MAP" ]; then # Generate RCVAR_MAP of `rcvar dflt script desc ...' per-line f_dialog_info "$msg_creating_rcvar_map" RCVAR_MAP=$( f_startup_rcvar_map ) export RCVAR_MAP export _RCVAR_MAP=1 fi RCVAR_MENU_LIST="$RCVAR_MENU_LIST $( . "$RC_DEFAULTS" > /dev/null source_rc_confs > /dev/null for rcvar in $( echo "$RCVAR_MAP" | awk '{print $1}' ); do eval export $rcvar done export SHOW_DESC msg_default_value echo "$RCVAR_MAP" | awk ' BEGIN { prefix = "" rword = "^[[:space:]]*[^[:space:]]*[[:space:]]*" } { cur_prefix = tolower(substr($1, 1, 1)) printf "'\''" if ( prefix != cur_prefix ) prefix = cur_prefix else printf " " rcvar = $1 default = $2 script = $3 printf "%s'\'' '\''", rcvar if ( ENVIRON[rcvar] ~ /[Yy][Ee][Ss]/ ) printf "[X] " else printf "[ ] " printf "%s; " ENVIRON["msg_default_value"], script, default printf "'\''" if ( ENVIRON["SHOW_DESC"] ) { desc = $0 sub(rword, "", desc) sub(rword, "", desc) sub(rword, "", desc) gsub(/'\''/, "'\''\\'\'\''", desc) printf " '\''%s'\''", desc } printf "\n" }' )" set -f # noglob local height width rows eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $RCVAR_MENU_LIST + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --keep-tite \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $RCVAR_MENU_LIST \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --keep-tite \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + ${SHOW_DESC:+--item-help} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $RCVAR_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_toggle_startup_services" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in "X $msg_exit") break ;; *) # Anything else is an rcvar to toggle rcvar="${mtag# }" value=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \ \"\$mtag\" $RCVAR_MENU_LIST ) # Determine the new [toggled] value to use case "$value" in "[X]"*) value="NO";; *) value="YES";; esac err=$( f_sysrc_set "$rcvar" "$value" 2>&1 ) || f_dialog_msgbox "$err" esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/startup/startup =================================================================== --- head/usr.sbin/bsdconfig/startup/startup (revision 251243) +++ head/usr.sbin/bsdconfig/startup/startup (revision 251244) @@ -1,135 +1,139 @@ #!/bin/sh #- # 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 (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/mustberoot.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' '1' '$msg_toggle_startup_services' '2' '$msg_view_edit_startup_configuration' '3' '$msg_miscellaneous_startup_services' " # END-QUOTE local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$prompt\" \ \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --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" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_startup" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Launch application main menu # while :; do dialog_menu_main || f_die f_dialog_menutag_fetch mtag case "$mtag" in X) # Exit break ;; 1) # Toggle Startup Services $BSDCFG_LIBE/$APP_DIR/rcvar ${USE_XDIALOG:+-X} ;; 2) # View/Edit Startup Configuration $BSDCFG_LIBE/$APP_DIR/rcconf ${USE_XDIALOG:+-X} ;; 3) # Miscellaneous Startup Services $BSDCFG_LIBE/$APP_DIR/misc ${USE_XDIALOG:+-X} ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/timezone/timezone =================================================================== --- head/usr.sbin/bsdconfig/timezone/timezone (revision 251243) +++ head/usr.sbin/bsdconfig/timezone/timezone (revision 251244) @@ -1,467 +1,471 @@ #!/bin/sh #- # Copyright (c) 2011-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/mustberoot.subr f_include $BSDCFG_SHARE/strings.subr f_include $BSDCFG_SHARE/timezone/continents.subr f_include $BSDCFG_SHARE/timezone/countries.subr f_include $BSDCFG_SHARE/timezone/iso3166.subr f_include $BSDCFG_SHARE/timezone/menus.subr f_include $BSDCFG_SHARE/timezone/zones.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="090.timezone" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ CONFIGURATION # # Standard pathnames # _PATH_DB="/var/db/zoneinfo" _PATH_WALL_CMOS_CLOCK="/etc/wall_cmos_clock" ############################################################ GLOBALS # # Options # REALLYDOIT=1 REINSTALL= USEDIALOG=1 SKIPUTC= VERBOSE= TZ_OR_FAIL= CHROOTENV= # # Dummy vars (populated dynamically) # COUNTRIES= # list of 2-character country codes created by f_read_iso3166_table ############################################################ FUNCTIONS # 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_select_region" + local defaultitem= # Calculated below local height width rows eval f_dialog_menu_size height width rows \ \"\$title\" \ \"\$btitle\" \ \"\$prompt\" \ \"\" \ $continent_menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $continent_menu_list \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $continent_menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts C:ehnrsv$GETOPTS_STDARGS flag; do case "$flag" in C) CHROOTENV="$OPTARG";; e) TZ_OR_FAIL=1;; n) REALLYDOIT=;; r) REINSTALL=1 USEDIALOG=;; s) SKIPUTC=1;; v) VERBOSE=1;; h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_time_zone" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # Process `-C chroot_directory' command-line argument # if [ "$CHROOTENV" ]; then _PATH_ZONETAB="$CHROOTENV$_PATH_ZONETAB" _PATH_ISO3166="$CHROOTENV$_PATH_ISO3166" _PATH_ZONEINFO="$CHROOTENV$_PATH_ZONEINFO" _PATH_LOCALTIME="$CHROOTENV$_PATH_LOCALTIME" _PATH_DB="$CHROOTENV$_PATH_DB" _PATH_WALL_CMOS_CLOCK="$CHROOTENV$_PATH_WALL_CMOS_CLOCK" fi # # Process `-r' command-line option # if [ "$REINSTALL" ]; then [ -f "$_PATH_DB" -a -r "$_PATH_DB" ] || f_die 1 "$msg_cannot_open_for_reading" "$_PATH_DB" zoneinfo=$( cat "$_PATH_DB" ) || f_die 1 "$msg_error_reading" "$_PATH_DB" [ "$zoneinfo" ] || f_die 1 "$msg_unable_to_determine_name_from_db" "$_PATH_DB" f_install_zoneinfo "$zoneinfo" exit $? fi # # If the arguments on the command-line do not specify a file, # then interpret it as a zoneinfo name # if [ $# -ge 1 ]; then zoneinfo="$1" if [ ! -f "$zoneinfo" ]; then USEDIALOG= f_install_zoneinfo "$zoneinfo" exit $? fi # FALLTHROUGH fi # # Process the UTC option # if [ "$_PATH_WALL_CMOS_CLOCK" -a ! "$SKIPUTC" ]; then f_dialog_title "$msg_select_local_or_utc" title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore msg="$msg_is_machine_clock_utc" if [ "$USE_XDIALOG" ]; then defaultno="default-no" height=10 width=77 else defaultno="defaultno" height=7 width=73 fi if [ "$USE_XDIALOG" ]; then $DIALOG \ --title "$title" \ --backtitle "$btitle" \ --$defaultno \ --ok-label "$msg_yes" \ --cancel-label "$msg_no" \ --yesno "$msg" $height $width result=$? else $DIALOG \ --title "$title" \ --backtitle "$btitle" \ --$defaultno \ --yes-label "$msg_yes" \ --no-label "$msg_no" \ --yesno "$msg" $height $width result=$? fi if [ $result -eq 0 ]; then # User chose YES [ "$REALLYDOIT" ] && f_quietly rm -f "$_PATH_WALL_CMOS_CLOCK" else # User chose NO, pressed ESC (or Ctrl-C), or closed box [ "$REALLYDOIT" ] && ( umask 222 && :> "$_PATH_WALL_CMOS_CLOCK" ) fi fi # # Process optional default zone argument # if [ $# -ge 1 ]; then default="$1" f_dialog_title "$msg_default_zone_provided" title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore msg=$( printf "\n$msg_use_default_zone" "$default" ) f_dialog_buttonbox_size height width "$title" "$btitle" "$msg" if [ "$USE_XDIALOG" ]; then eval $DIALOG \ --title \"\$title\" \ --backtitle \"\$btitle\" \ --ok-label \"\$msg_yes\" \ --cancel-label \"\$msg_no\" \ --yesno \"\$msg\" $height $width result=$? else eval $DIALOG \ --title \"\$title\" \ --backtitle \"\$btitle\" \ --yes-label \"\$msg_yes\" \ --no-label \"\$msg_no\" \ --yesno \"\$msg\" $height $width result=$? fi if [ $result -eq 0 ]; then # User chose YES f_install_zoneinfo_file "$default" result=$? [ ! "$USE_XDIALOG" ] && f_dialog_clear exit $result fi [ ! "$USE_XDIALOG" ] && f_dialog_clear fi # # Override the user-supplied umask # umask 022 # # Read databases and perform initialization # f_read_iso3166_table # creates $COUNTRIES and $country_*_name f_read_zones # creates $country_*_{descr,cont,filename} f_sort_countries # sorts the countries listed for each continent f_make_menus # creates $continent_menu_list and $continent_*_menu_list # # Launch application main menu # defaultctry="" defaultzone="" NEED_CONTINENT=1 NEED_COUNTRY=1 while :; do if [ "$NEED_CONTINENT" ]; then dialog_menu_main # prompt the user to select a continent/ocean retval=$? f_dialog_menutag_fetch mtag if [ $retval -ne 0 ]; then [ "$TZ_OR_FAIL" ] && f_die exit $SUCCESS fi NEED_CONTINENT= continent=$( eval f_dialog_menutag2item \"\$mtag\" \ $continent_menu_list ) cont=$( f_find_continent "$continent" ) cont_title=$( f_continent $cont title ) nitems=$( f_continent $cont nitems ) isocean=$( f_OCEANP $cont ) fi if [ "$NEED_COUNTRY" ]; then if [ "$cont_title" = "$continent_utc_title" ]; then if f_set_zone_utc; then break else NEED_CONTINENT=1 continue fi fi # # Short cut -- if there's only one country, don't post a menu. # if [ $nitems -eq 1 ]; then tag=1 else # # It's amazing how much good grammar really matters... # if [ ! "$isocean" ]; then title=$( printf "$msg_country_title" \ "$cont_title" ) f_dialog_title "$title" title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore prompt="$msg_select_country" else title=$( printf "$msg_island_and_group_title" \ "$cont_title" ) f_dialog_title "$title" title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore prompt="$msg_select_island_or_group" fi # # Calculate size of menu # menu_list=$( f_continent $cont menu_list ) eval f_dialog_menu_size height width rows \ \"\$title\" \ \"\$btitle\" \ \"\$prompt\" \ \"\" \ $menu_list # # Launch the country selection menu # tag=$( eval $DIALOG \ --title \"\$title\" \ --backtitle \"\$btitle\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultctry\" \ --menu \"\$prompt\" \ $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize tag defaultctry="$tag" if [ $retval -ne 0 ]; then NEED_CONTINENT=1 continue # back to main menu fi fi # Get the country code from the user's selection tlc=$( f_continent $cont tlc_$tag ) NEED_COUNTRY= fi # # If the selection has only one zone (nzones == -1), # just set it. # nzones=$( f_country $tlc nzones ) if [ $nzones -lt 0 ]; then real_cont=$( f_country $tlc cont ) real_continent=$( f_continent $real_cont name ) name=$( f_country $tlc name ) filename=$( f_country $tlc filename ) if ! f_confirm_zone "$real_continent/$filename"; then [ $nitems -eq 1 ] && NEED_CONTINENT=1 NEED_COUNTRY=1 continue fi else title=$( printf "$msg_country_time_zones" \ "$( f_country $tlc name )" ) f_dialog_title "$title" title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore prompt="$msg_select_zone" menu_list=$( f_country $tlc menu_list ) eval f_dialog_menu_size height width rows \ \"\$title\" \"\$btitle\" \"\$prompt\" \"\" $menu_list # # Launch the zone selection menu # NOTE: This is as deep as we go # n=$( eval $DIALOG \ --title \"\$title\" \ --backtitle \"\$btitle\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultzone\" \ --menu \"\$prompt\" \ $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize n defaultzone="$n" if [ $retval -ne 0 ]; then [ $nitems -eq 1 ] && NEED_CONTINENT=1 NEED_COUNTRY=1 continue fi real_cont=$( f_country $tlc cont_$n ) real_continent=$( f_continent $real_cont name ) name=$( f_country $tlc name ) filename=$( f_country $tlc filename_$n ) f_confirm_zone "$real_continent/$filename" || continue fi [ $retval -eq 0 ] || continue # back to main menu if ! f_install_zoneinfo "$real_continent/$filename"; then [ $nzones -lt 0 ] && NEED_COUNTRY=1 else break fi done ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/usermgmt/groupinput =================================================================== --- head/usr.sbin/bsdconfig/usermgmt/groupinput (revision 251243) +++ head/usr.sbin/bsdconfig/usermgmt/groupinput (revision 251244) @@ -1,298 +1,299 @@ #!/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$ # ############################################################ 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/mustberoot.subr f_include $BSDCFG_SHARE/usermgmt/group_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ CONFIGURATION # set some reasonable defaults if /etc/adduser.conf does not exist. [ -f /etc/adduser.conf ] && f_include /etc/adduser.conf : ${passwdtype:="yes"} ############################################################ FUNCTIONS # save_changes # # Save any/all settings (actions performed depend on $mode value). # save_changes() { local err retval=$SUCCESS case "$mode" in Delete) err=$( pw groupdel "$group_name" 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_group_deleted" ;; Add) local cmd="pw groupadd -n '$group_name'" [ "$group_gid" ] && cmd="$cmd -g '$group_gid'" [ "$group_members" != "$cur_group_members" ] && cmd="$cmd -M '$group_members'" if [ "$pw_group_password_disable" ]; then cmd="$cmd -h -" elif [ "$group_password" ]; then cmd="echo \"\$group_password\" | $cmd -h 0" fi f_dprintf "cmd=%s" "$cmd" err=$( eval $cmd 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_group_added" ;; Edit/View) local cmd="pw groupmod -n '$group_name'" [ "$group_gid" ] && cmd="$cmd -g '$group_gid'" [ "$group_members" != "$cur_group_members" ] && cmd="$cmd -M '$group_members'" if [ "$pw_group_password_disable" ]; then cmd="$cmd -h -" elif [ "$group_password" ]; then cmd="echo \"\$group_password\" | $cmd -h 0" fi f_dprintf "cmd=%s" "$cmd" err=$( eval $cmd 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_group_updated" ;; esac save_flag= return $SUCCESS } # dialog_title_update $mode # # Set the title based on the given $mode. # dialog_title_update() { local mode="$1" case "$mode" in Add) f_dialog_title "$msg_add $msg_group" ;; Edit/View) f_dialog_title "$msg_edit_view $msg_group: $group" ;; Delete) f_dialog_title "$msg_delete $msg_group: $group" ;; esac } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while [ $# -gt 0 ]; do key="${1%%=*}" value="${1#*=}" f_dprintf "key=[%s] value=[%s]" "$key" "$value" case "$key" in mode) mode="$value";; group) group="$value";; esac shift done f_dprintf "mode=[%s] group=[%s]" "$mode" "$group" # # Initialize # dialog_title_update "$mode" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init menu_text= save_flag= hline="$hline_arrows_tab_enter" if [ "$mode" = "Add" ]; then # # Ask a series of questions to pre-fill the editor screen. # # The defaults used in each dialog should allow the user to simply # hit ENTER to proceed, because cancelling a single dialog will # cause them to be returned to the main groupmenu. # f_dialog_input_group_name || exit 0 [ "$passwdtype" = "yes" ] && { f_dialog_input_group_password || exit 0; } f_dialog_input_group_gid || exit 0 f_dialog_input_group_members || exit 0 fi if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then f_input_group "$group" || f_die 1 "$msg_group_not_found" fi cur_group_name="$group_name" cur_group_password="$group_password" cur_group_gid="$group_gid" cur_group_members="$group_members" [ "$mode" = "Delete" ] && save_flag=1 # # Loop until the user decides to Exit, Cancel, or presses ESC # while :; do dialog_title_update "$mode" menu_text= menu_exit="$msg_exit" if [ "$save_flag" ]; then if [ "$mode" = "Delete" ]; then menu_exit="$msg_delete/$msg_exit" menu_text="$msg_delete_exit_or_cancel" else menu_exit="$msg_save/$msg_exit" menu_text="$msg_save_exit_or_cancel" fi fi case "$mode" in Delete) menu_items=" 'X' '$menu_exit' '1' '$msg_group: $group_name' '-' '$msg_password: -----' '-' '$msg_group_id: $group_gid' '-' '$msg_group_members: $group_members' " # END-QUOTE ;; *) menu_items=" 'X' '$menu_exit' '1' '$msg_group: $group_name' '2' '$msg_password: -----' '3' '$msg_group_id: $group_gid' '4' '$msg_group_members: $group_members' " # END-QUOTE esac eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$menu_text\" \ \"\$hline\" \ $menu_items + f_dialog_default_fetch defaultitem mtag=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" \ - $height $width $rows \ - $menu_items \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$menu_text\" \ + $height $width $rows \ + $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize mtag - setvar DEFAULTITEM_$$ "$mtag" + f_dialog_default_store "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || f_die case "$mtag" in X) # Exit if [ "$save_flag" ]; then save_changes || continue fi break ;; 1) # Group Name case "$mode" in Add) f_dialog_input_group_name "$group_name" ;; Edit/View|Delete) f_dialog_menu_group_list "$group_name" retval=$? f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || continue [ "$mtag" = "X $msg_exit" ] && continue group="$mtag" f_input_group "$group" || f_die 1 "$msg_group_not_found" cur_group_name="$group_name" cur_group_password="$group_password" cur_group_gid="$group_gid" cur_group_members="$group_members" [ "$mode" != "Delete" ] && save_flag= esac ;; 2) # Password f_dialog_input_group_password ;; 3) # GID f_dialog_input_group_gid "$group_gid" ;; 4) # Users in Group f_dialog_input_group_members "$group_members" ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/usermgmt/userinput =================================================================== --- head/usr.sbin/bsdconfig/usermgmt/userinput (revision 251243) +++ head/usr.sbin/bsdconfig/usermgmt/userinput (revision 251244) @@ -1,518 +1,519 @@ #!/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$ # ############################################################ 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/mustberoot.subr f_include $BSDCFG_SHARE/usermgmt/user_input.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ CONFIGURATION # set some reasonable defaults if /etc/adduser.conf does not exist. [ -f /etc/adduser.conf ] && f_include /etc/adduser.conf : ${passwdtype:="yes"} : ${homeprefix:="/home"} : ${defaultshell:="/bin/sh"} : ${udotdir:="/usr/share/skel"} ############################################################ FUNCTIONS # copy_dotfiles # # Copy `skel' dot-files to a new home directory. # copy_dotfiles() { ( # Operate within sub-shell to protect CWD/glob of parent cd "$udotdir" || exit $? set +f # glob for file in dot.*; do cp -n "$file" "$pw_home_dir/${file#dot}" || exit $? done ) } # save_changes # # Save any/all settings (actions performed depend on $mode value). # save_changes() { local err retval=$SUCCESS case "$mode" in Delete) err=$( pw userdel -u "$pw_uid" 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_login_deleted" if [ "$pw_group_delete" = "$msg_yes" ] && f_quietly pw groupshow -g "$pw_gid" then err=$( pw groupdel -g "$pw_gid" 2>&1 ) || f_dialog_msgbox "$msg_warning $err\n" fi if [ "$pw_home_delete" = "$msg_yes" ]; then f_dialog_info "$msg_deleting_home_directory" err=$( rm -Rf "$pw_home_dir" 2>&1 ) || f_dialog_msgbox "$msg_warning $err\n" fi ;; Add) local cmd="pw useradd -n '$pw_name'" [ "$pw_member_groups" ] && cmd="$cmd -G '$pw_member_groups'" [ "$pw_class" ] && cmd="$cmd -L '$pw_class'" [ "$pw_gecos" ] && cmd="$cmd -c '$pw_gecos'" [ "$pw_home_dir" ] && cmd="$cmd -d '$pw_home_dir'" [ "$pw_account_expire" ] && cmd="$cmd -e '$pw_account_expire'" [ "$pw_gid" ] && cmd="$cmd -g '$pw_gid'" [ "$pw_password_expire" ] && cmd="$cmd -p '$pw_password_expire'" [ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'" [ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'" if [ "$pw_password_disable" ]; then cmd="$cmd -h -" elif [ "$pw_password" ]; then cmd="echo \"\$pw_password\" | $cmd -h 0" fi f_dprintf "cmd=%s" "$cmd" err=$( eval $cmd 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_login_added" if [ "$pw_home_create" = "$msg_yes" ]; then err=$( mkdir -p "$pw_home_dir" 2>&1 ) if [ $? -ne $SUCCESS ]; then f_dialog_msgbox "$msg_warning $err\n" elif [ -e "$pw_home_dir" ]; then err=$( chown -R "$pw_uid:$pw_gid" \ "$pw_home_dir" 2>&1 ) [ $? -eq $SUCCESS ] || f_dialog_msgbox "$msg_warning $err\n" fi fi if [ "$pw_dotfiles_create" = "$msg_yes" ]; then err=$( copy_dotfiles 2>&1 ) || f_dialog_msgbox "$msg_warning $err\n" fi user="$pw_name" f_quietly pw usershow -n "$pw_name" && mode="Edit/View" # Change mode ;; Edit/View) local cmd="pw usermod -n '$pw_name'" [ "$pw_member_groups" ] && cmd="$cmd -G '$pw_member_groups'" [ "$pw_class" ] && cmd="$cmd -L '$pw_class'" [ "$pw_gecos" ] && cmd="$cmd -c '$pw_gecos'" [ "$pw_home_dir" ] && cmd="$cmd -d '$pw_home_dir'" [ "$pw_account_expire" ] && cmd="$cmd -e '$pw_account_expire'" [ "$pw_gid" ] && cmd="$cmd -g '$pw_gid'" [ "$pw_password_expire" ] && cmd="$cmd -p '$pw_password_expire'" [ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'" [ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'" if [ "$pw_password_disable" ]; then cmd="$cmd -h -" elif [ "$pw_password" ]; then cmd="echo \"\$pw_password\" | $cmd -h 0" fi f_dprintf "cmd=%s" "$cmd" err=$( eval $cmd 2>&1 ) retval=$? if [ $retval -ne $SUCCESS ]; then f_dialog_msgbox "$msg_error $err\n" return $retval fi f_dialog_msgbox "$msg_login_updated" if [ "$pw_home_create" = "$msg_yes" ]; then err=$( mkdir -p "$pw_home_dir" ) if [ $? -ne $SUCCESS ]; then f_dialog_msgbox "$msg_warning $err\n" elif [ -e "$pw_home_dir" ]; then err=$( chown -R "$pw_uid:$pw_gid" \ "$pw_home_dir" 2>&1 ) [ $? -eq $SUCCESS ] || f_dialog_msgbox "$msg_warning $err\n" fi fi if [ "$pw_dotfiles_create" = "$msg_yes" ]; then err=$( copy_dotfiles 2>&1 ) || f_dialog_msgbox "$msg_warning $err\n" fi ;; esac save_flag= return $SUCCESS } # dialog_title_update $mode # # Set the title based on the given $mode. # dialog_title_update() { local mode="$1" case "$mode" in Add) f_dialog_title "$msg_add $msg_user" ;; Edit/View) f_dialog_title "$msg_edit_view $msg_user: $user" ;; Delete) f_dialog_title "$msg_delete $msg_user: $user" ;; esac } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while [ $# -gt 0 ]; do key="${1%%=*}" value="${1#*=}" f_dprintf "key=[%s] value=[%s]" "$key" "$value" case "$key" in mode) mode="$value";; user) user="$value";; esac shift done f_dprintf "mode=[%s] user=[%s]" "$mode" "$user" # # Initialize # dialog_title_update "$mode" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init menu_text= save_flag= hline="$hline_arrows_tab_enter" if [ "$mode" = "Add" ]; then # # Ask a series of questions to pre-fill the editor screen. # # The defaults used in each dialog should allow the user to simply # hit ENTER to proceed, because cancelling a single dialog will # cause them to be returned to the main usermenu. # f_dialog_input_name || exit 0 f_dialog_input_gecos "$pw_name" || exit 0 [ "$passwdtype" = "yes" ] && { f_dialog_input_password || exit 0; } f_dialog_input_uid || exit 0 f_dialog_input_gid || exit 0 f_dialog_input_member_groups || exit 0 f_dialog_input_class || exit 0 f_dialog_input_change || exit 0 f_dialog_input_expire || exit 0 f_dialog_input_home_dir "$homeprefix/$pw_name" || exit 0 pw_dotfiles_create="$msg_no" if [ ! -d "$homeprefix/$pw_name" ]; then f_dialog_input_home_create || exit 0 [ "$pw_home_create" = "$msg_yes" ] && { f_dialog_input_dotfiles_create || exit 0; } fi f_dialog_input_shell "$defaultshell" || exit 0 fi if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then f_input_user "$user" || f_die 1 "$msg_login_not_found" fi if [ "$mode" = "Edit/View" ]; then [ -d "$pw_home_dir" ] || pw_home_create="$msg_no" pw_dotfiles_create="$msg_no" fi if [ "$mode" = "Delete" ]; then f_dialog_input_group_delete || exit 0 pw_home_delete="$msg_no" [ -d "$pw_home_dir" ] && { f_dialog_input_home_delete || exit 0; } fi cur_pw_name="$pw_name" cur_pw_password="$pw_password" cur_pw_uid="$pw_uid" cur_pw_gid="$pw_gid" cur_pw_member_groups="$pw_member_groups" cur_pw_class="$pw_class" cur_pw_password_expire="$pw_password_expire" cur_pw_account_expire="$pw_account_expire" cur_pw_gecos="$pw_gecos" cur_pw_home_dir="$pw_home_dir" cur_pw_shell="$pw_shell" cur_pw_group_delete="$pw_group_delete" cur_pw_home_create="$pw_home_create" cur_pw_home_delete="$pw_home_delete" cur_pw_dotfiles_create="$pw_dotfiles_create" [ "$mode" = "Delete" ] && save_flag=1 # # Loop until the user decides to Exit, Cancel, or presses ESC # while :; do dialog_title_update "$mode" menu_text= menu_exit="$msg_exit" if [ "$save_flag" ]; then if [ "$mode" = "Delete" ]; then menu_exit="$msg_delete/$msg_exit" menu_text="$msg_delete_exit_or_cancel" else menu_exit="$msg_save/$msg_exit" menu_text="$msg_save_exit_or_cancel" fi fi pw_password_expires_on="$pw_password_expire" f_isinteger "$pw_password_expire" && [ $pw_password_expire -ne 0 ] && pw_password_expires_on=$( date -r "$pw_password_expire" "+%F %T %Z" ) pw_account_expires_on="$pw_account_expire" f_isinteger "$pw_account_expire" && [ "$pw_account_expire" -ne 0 ] && pw_account_expires_on=$( date -r "$pw_account_expire" "+%F %T %Z" ) case "$mode" in Delete) menu_items=" 'X' '$menu_exit' '1' '$msg_login: $pw_name' '-' '$msg_full_name: $pw_gecos' '-' '$msg_password: -----' '-' '$msg_user_id: $pw_uid' '-' '$msg_group_id: $pw_gid' '-' '$msg_member_of_groups: $pw_member_groups' '-' '$msg_login_class: $pw_class' '-' '$msg_password_expires_on: $pw_password_expires_on' '-' '$msg_account_expires_on: $pw_account_expires_on' '-' '$msg_home_directory: $pw_home_dir' '-' '$msg_shell: $pw_shell' " # END-QUOTE ;; *) menu_items=" 'X' '$menu_exit' '1' '$msg_login: $pw_name' '2' '$msg_full_name: $pw_gecos' '3' '$msg_password: -----' '4' '$msg_user_id: $pw_uid' '5' '$msg_group_id: $pw_gid' '6' '$msg_member_of_groups: $pw_member_groups' '7' '$msg_login_class: $pw_class' '8' '$msg_password_expires_on: $pw_password_expires_on' '9' '$msg_account_expires_on: $pw_account_expires_on' 'A' '$msg_home_directory: $pw_home_dir' 'B' '$msg_shell: $pw_shell' " # END-QUOTE esac case "$mode" in Add|Edit/View) if [ -d "$pw_home_dir" ]; then menu_items="$menu_items '-' '$msg_create_home_directory: $msg_n_a' 'D' '$msg_create_dotfiles: $pw_dotfiles_create' "; else menu_items="$menu_items 'C' '$msg_create_home_directory: $pw_home_create' 'D' '$msg_create_dotfiles: $pw_dotfiles_create' "; fi ;; Delete) if [ -d "$pw_home_dir" ]; then menu_items="$menu_items 'C' '$msg_delete_primary_group: $pw_group_delete' 'D' '$msg_delete_home_directory: $pw_home_delete' "; else menu_items="$menu_items 'C' '$msg_delete_primary_group: $pw_group_delete' '-' '$msg_delete_home_directory: $msg_n_a' "; fi ;; esac eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\$menu_text\" \ \"\$hline\" \ $menu_items + f_dialog_default_fetch defaultitem mtag=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" \ - $height $width $rows \ - $menu_items \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$menu_text\" \ + $height $width $rows \ + $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize mtag - setvar DEFAULTITEM_$$ "$mtag" + f_dialog_default_store "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || f_die case "$mtag" in X) # Exit if [ "$save_flag" ]; then save_changes || continue fi break ;; 1) # Login case "$mode" in Add) f_dialog_input_name "$pw_name" ;; Edit/View|Delete) f_dialog_menu_user_list "$pw_name" retval=$? f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || continue [ "$mtag" = "X $msg_exit" ] && continue user="$mtag" f_input_user "$user" || f_die 1 "$msg_login_not_found" cur_pw_name="$pw_name" cur_pw_password="$pw_password" cur_pw_uid="$pw_uid" cur_pw_gid="$pw_gid" cur_pw_member_groups="$pw_member_groups" cur_pw_class="$pw_class" cur_pw_password_expire="$pw_password_expire" cur_pw_account_expire="$pw_account_expire" cur_pw_gecos="$pw_gecos" cur_pw_home_dir="$pw_home_dir" cur_pw_shell="$pw_shell" cur_pw_group_delete="$pw_group_delete" cur_pw_home_create="$pw_home_create" cur_pw_home_delete="$pw_home_delete" cur_pw_dotfiles_create="$pw_dotfiles_create" [ "$mode" != "Delete" ] && save_flag= esac ;; 2) # Full Name f_dialog_input_gecos "$pw_gecos" ;; 3) # Password f_dialog_input_password ;; 4) # UID f_dialog_input_uid "$pw_uid" ;; 5) # Default Group f_dialog_input_gid "$pw_gid" ;; 6) # Member of Groups f_dialog_input_member_groups "$pw_member_groups" ;; 7) # Login Class f_dialog_input_class "$pw_class" ;; 8) # Password Expire on f_dialog_input_change "$pw_password_expire" ;; 9) # Account Expire on f_dialog_input_expire "$pw_account_expire" ;; A) # Home Directory f_dialog_input_home_dir "$pw_home_dir" ;; B) # Shell f_dialog_input_shell "$pw_shell" ;; esac case "$mode" in Delete) case "$mtag" in C) # Delete Primary Group f_dialog_input_group_delete ;; D) # Delete Home Directory f_dialog_input_home_delete ;; esac ;; Add|Edit/View) case "$mtag" in C) # Create Home Directory f_dialog_input_home_create [ "$pw_home_create" = "$msg_no" ] && pw_dotfiles_create="$msg_no" ;; D) # Create Dotfiles f_dialog_input_dotfiles_create [ "$pw_dotfiles_create" = "$msg_yes" ] && pw_home_create="$msg_yes" ;; esac ;; esac done exit $SUCCESS ################################################################################ # END ################################################################################ Index: head/usr.sbin/bsdconfig/usermgmt/usermgmt =================================================================== --- head/usr.sbin/bsdconfig/usermgmt/usermgmt (revision 251243) +++ head/usr.sbin/bsdconfig/usermgmt/usermgmt (revision 251244) @@ -1,178 +1,182 @@ #!/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$ # ############################################################ 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/mustberoot.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr USERMGMT_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/usermgmt.hlp ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" ############################################################ FUNCTIONS # dialog_menu_main # # Display the dialog(1)-based application main menu. # dialog_menu_main() { local menu_list local hline="$hline_arrows_tab_enter" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' '1' '$msg_add_login' '2' '$msg_edit_login' '3' '$msg_delete_login' '-' '-' '4' '$msg_add_group' '5' '$msg_edit_group' '6' '$msg_delete_group' " # END-QUOTE local height width rows eval f_dialog_menu_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\" \ \"\$hline\" \ $menu_list # When using Xdialog(1) we need to bump the width for the buttons [ "$USE_XDIALOG" ] && width=40 + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_help\" \ - ${USE_XDIALOG:+--help \"\"} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" \ - $height $width $rows \ - $menu_list \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --default-item \"\$defaultitem\" \ + --menu \"\" \ + $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 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } ############################################################ MAIN # Incorporate rc-file if it exists [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" # # Process command-line arguments # while getopts h$GETOPTS_STDARGS flag; do case "$flag" in h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; esac done shift $(( $OPTIND - 1 )) # # Initialize # f_dialog_title "$msg_login_management" f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" f_mustberoot_init # # 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 "$USERMGMT_HELPFILE" continue elif [ $retval -ne $SUCCESS ]; then f_die fi case "$mtag" in X) # Exit exit 0 ;; 1) # Add User $BSDCFG_LIBE/$APP_DIR/useradd ${USE_XDIALOG:+-X} ;; 2) # Edit/View User $BSDCFG_LIBE/$APP_DIR/useredit ${USE_XDIALOG:+-X} ;; 3) # Delete User $BSDCFG_LIBE/$APP_DIR/userdel ${USE_XDIALOG:+-X} ;; 4) # Add Group $BSDCFG_LIBE/$APP_DIR/groupadd ${USE_XDIALOG:+-X} ;; 5) # Edit/View Group $BSDCFG_LIBE/$APP_DIR/groupedit ${USE_XDIALOG:+-X} ;; 6) # Delete Group $BSDCFG_LIBE/$APP_DIR/groupdel ${USE_XDIALOG:+-X} ;; esac done ################################################################################ # END ################################################################################