1641a6cfbSDevin Teske#!/bin/sh 2641a6cfbSDevin Teske#- 3641a6cfbSDevin Teske# Copyright (c) 2012 Ron McDowell 41c64959bSDevin Teske# Copyright (c) 2012-2021 Devin Teske 5641a6cfbSDevin Teske# All rights reserved. 6641a6cfbSDevin Teske# 7641a6cfbSDevin Teske# Redistribution and use in source and binary forms, with or without 8641a6cfbSDevin Teske# modification, are permitted provided that the following conditions 9641a6cfbSDevin Teske# are met: 10641a6cfbSDevin Teske# 1. Redistributions of source code must retain the above copyright 11641a6cfbSDevin Teske# notice, this list of conditions and the following disclaimer. 12641a6cfbSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 13641a6cfbSDevin Teske# notice, this list of conditions and the following disclaimer in the 14641a6cfbSDevin Teske# documentation and/or other materials provided with the distribution. 15641a6cfbSDevin Teske# 16641a6cfbSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17641a6cfbSDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18641a6cfbSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19641a6cfbSDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20641a6cfbSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21641a6cfbSDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22641a6cfbSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23641a6cfbSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24641a6cfbSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25641a6cfbSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26641a6cfbSDevin Teske# SUCH DAMAGE. 27641a6cfbSDevin Teske# 28641a6cfbSDevin Teske# 29641a6cfbSDevin Teske############################################################ INCLUDES 30641a6cfbSDevin Teske 315b4765c3SDevin Teske# When common.subr is included, it automatically scans "$@" for `-d' and/or 325b4765c3SDevin Teske# `-D file' arguments to conditionally enable debugging. Similarly, when 335b4765c3SDevin Teske# dialog.subr is included, it automatically scans "$@" for `-X' and/or `-S'. 345b4765c3SDevin Teske# To prevent this scanning from becoming confused by extra options, define 355b4765c3SDevin Teske# any/all extra arguments to use in the optstring to getopts when scanning 365b4765c3SDevin Teske# for dedicated options such as those described. 375b4765c3SDevin Teske# 385b4765c3SDevin Teske# NOTE: This needs to be declared before including `common.subr'. 395b4765c3SDevin Teske# NOTE: You really only need to list flags that require an argument as unknown 405b4765c3SDevin Teske# flags are silently accepted unless they take an argument (in which case 415b4765c3SDevin Teske# the following argument will terminate option processing unless it looks 425b4765c3SDevin Teske# like a flag). 435b4765c3SDevin Teske# 445b4765c3SDevin TeskeGETOPTS_EXTRA="f:" 455b4765c3SDevin Teske 46ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 47ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 4856961fd7SDevin Teskef_dprintf "%s: loading includes..." "$0" 49ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 50ab2043b8SDevin Teskef_include $BSDCFG_SHARE/mustberoot.subr 51ab2043b8SDevin Teskef_include $BSDCFG_SHARE/strings.subr 52ab2043b8SDevin Teske 53641a6cfbSDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 54641a6cfbSDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr 5540dfc82dSDevin Teske 5640dfc82dSDevin TeskeBSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp 5740dfc82dSDevin TeskeUSAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp 58641a6cfbSDevin Teske 591da51566SDevin Teske############################################################ CONFIGURATION 601da51566SDevin Teske 611da51566SDevin Teske# 621da51566SDevin Teske# Alternate `local' libexec directory for add-on modules (e.g., from ports) 631da51566SDevin Teske# 641da51566SDevin TeskeBSDCFG_LOCAL_LIBE="/usr/local/libexec/bsdconfig" 651da51566SDevin Teske 66641a6cfbSDevin Teske############################################################ FUNCTIONS 67641a6cfbSDevin Teske 68641a6cfbSDevin Teske# usage 69641a6cfbSDevin Teske# 70641a6cfbSDevin Teske# display usage and exit 71641a6cfbSDevin Teske# 72641a6cfbSDevin Teskeusage() 73641a6cfbSDevin Teske{ 74052f8969SDevin Teske local index="INDEX" 75052f8969SDevin Teske local cmd_list # Calculated below 76641a6cfbSDevin Teske 77641a6cfbSDevin Teske cd $BSDCFG_LIBE 78e14ddd1fSDevin Teske # No need to preserve CWD (headed toward exit) 79641a6cfbSDevin Teske 80641a6cfbSDevin Teske # Test for language-specific indices 81641a6cfbSDevin Teske f_quietly ls */"$index.${LANG:-$LC_ALL}" && 82641a6cfbSDevin Teske index="$index.${LANG:-$LC_ALL}" 83641a6cfbSDevin Teske 84641a6cfbSDevin Teske cmd_list=$( 85641a6cfbSDevin Teske awk '/^menu_selection="/ { 86641a6cfbSDevin Teske sub(/\|.*/, "") 87641a6cfbSDevin Teske sub(/^menu_selection="/, "") 88641a6cfbSDevin Teske print 89641a6cfbSDevin Teske }' */$index | sort 90641a6cfbSDevin Teske ) 91641a6cfbSDevin Teske 921da51566SDevin Teske local alt_cmd_list # Calculated below (if $BSDCFG_LOCAL_LIBE exists) 931da51566SDevin Teske if f_quietly cd $BSDCFG_LOCAL_LIBE; then 941da51566SDevin Teske # No need to preserve CWD (headed toward exit) 951da51566SDevin Teske 961da51566SDevin Teske # Test for language-specific indices 971da51566SDevin Teske f_quietly ls */"$index.${LANG:-$LC_ALL}" && 981da51566SDevin Teske index="$index.${LANG:-$LC_ALL}" 991da51566SDevin Teske 1001da51566SDevin Teske alt_cmd_list=$( 1011da51566SDevin Teske awk '/^menu_selection="/ { 1021da51566SDevin Teske sub(/\|.*/, "") 1031da51566SDevin Teske sub(/^menu_selection="/, "") 1041da51566SDevin Teske print 1051da51566SDevin Teske }' */$index 2> /dev/null | sort 1061da51566SDevin Teske ) 1071da51566SDevin Teske 1081da51566SDevin Teske # Conflate lists, removing duplicates 1091da51566SDevin Teske cmd_list=$( printf "%s\n%s\n" \ 1101da51566SDevin Teske "$cmd_list" "$alt_cmd_list" | sort -u ) 1111da51566SDevin Teske fi 1121da51566SDevin Teske 113641a6cfbSDevin Teske # 114641a6cfbSDevin Teske # Determine the longest command-length (in characters) 115641a6cfbSDevin Teske # 116641a6cfbSDevin Teske local longest_cmd 117641a6cfbSDevin Teske longest_cmd=$( echo "$cmd_list" | f_longest_line_length ) 118526e1dc1SDevin Teske f_dprintf "longest_cmd=[%s]" "$longest_cmd" 119641a6cfbSDevin Teske 120641a6cfbSDevin Teske # 121641a6cfbSDevin Teske # Determine the maximum width of terminal/console 122641a6cfbSDevin Teske # 123c01472c1SDevin Teske local max_size="$( stty size 2> /dev/null )" 124641a6cfbSDevin Teske : ${max_size:="24 80"} 125c01472c1SDevin Teske local max_width="${max_size#*[$IFS]}" 126526e1dc1SDevin Teske f_dprintf "max_width=[%s]" "$max_width" 127641a6cfbSDevin Teske 128641a6cfbSDevin Teske # 129641a6cfbSDevin Teske # Using the longest command-length as the width of a single column, 130641a6cfbSDevin Teske # determine if we can use more than one column to display commands. 131641a6cfbSDevin Teske # 132641a6cfbSDevin Teske local x=$longest_cmd ncols=1 133463a577bSEitan Adler x=$(( $x + 8 )) # Accommodate leading tab character 1341c64959bSDevin Teske x=$(( $x + 3 + $longest_cmd )) # Pre-load end of next column 135641a6cfbSDevin Teske while [ $x -lt $max_width ]; do 136641a6cfbSDevin Teske ncols=$(( $ncols + 1 )) 137641a6cfbSDevin Teske x=$(( $x + 3 + $longest_cmd )) 138641a6cfbSDevin Teske done 139526e1dc1SDevin Teske f_dprintf "ncols=[%u] x=[%u]" $ncols $x 140641a6cfbSDevin Teske 141641a6cfbSDevin Teske # 142641a6cfbSDevin Teske # Re-format the command-list into multiple columns 143641a6cfbSDevin Teske # 144641a6cfbSDevin Teske cmd_list=$( eval "$( echo "$cmd_list" | 145641a6cfbSDevin Teske awk -v ncols=$ncols -v size=$longest_cmd ' 146641a6cfbSDevin Teske BEGIN { 147641a6cfbSDevin Teske n = 0 148641a6cfbSDevin Teske row_item[1] = "" 149641a6cfbSDevin Teske } 150641a6cfbSDevin Teske function print_row() 151641a6cfbSDevin Teske { 152641a6cfbSDevin Teske fmt = "printf \"\\t%-" size "s" 153641a6cfbSDevin Teske for (i = 1; i < cur_col; i++) 154641a6cfbSDevin Teske fmt = fmt " %-" size "s" 155641a6cfbSDevin Teske fmt = fmt "\\n\"" 156641a6cfbSDevin Teske printf "%s", fmt 157641a6cfbSDevin Teske for (i = 1; i <= cur_col; i++) 158641a6cfbSDevin Teske printf " \"%s\"", row_item[i] 159641a6cfbSDevin Teske print "" 160641a6cfbSDevin Teske } 161641a6cfbSDevin Teske { 162641a6cfbSDevin Teske n++ 163641a6cfbSDevin Teske cur_col = (( n - 1 ) % ncols ) + 1 164526e1dc1SDevin Teske printf "f_dprintf \"row_item[%u]=[%%s]\" \"%s\"\n", 165526e1dc1SDevin Teske cur_col, $0 166641a6cfbSDevin Teske row_item[cur_col] = $0 167641a6cfbSDevin Teske if ( cur_col == ncols ) print_row() 168641a6cfbSDevin Teske } 169641a6cfbSDevin Teske END { 170641a6cfbSDevin Teske if ( cur_col < ncols ) print_row() 171641a6cfbSDevin Teske }' )" 172641a6cfbSDevin Teske ) 173641a6cfbSDevin Teske 174641a6cfbSDevin Teske f_usage $BSDCFG_LIBE/USAGE \ 175641a6cfbSDevin Teske "PROGRAM_NAME" "$pgm" \ 176641a6cfbSDevin Teske "COMMAND_LIST" "$cmd_list" 177e14ddd1fSDevin Teske 1781c64959bSDevin Teske # NOTREACHED 179641a6cfbSDevin Teske} 180641a6cfbSDevin Teske 181641a6cfbSDevin Teske# dialog_menu_main 182641a6cfbSDevin Teske# 183641a6cfbSDevin Teske# Display the dialog(1)-based application main menu. 184641a6cfbSDevin Teske# 185641a6cfbSDevin Teskedialog_menu_main() 186641a6cfbSDevin Teske{ 187641a6cfbSDevin Teske local title="$DIALOG_TITLE" 188641a6cfbSDevin Teske local btitle="$DIALOG_BACKTITLE" 189641a6cfbSDevin Teske local prompt="$msg_menu_text" 190052f8969SDevin Teske local menu_list=" 191641a6cfbSDevin Teske 'X' '$msg_exit' '$msg_exit_bsdconfig' 19214599250SDevin Teske '1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system' 193641a6cfbSDevin Teske " # END-QUOTE 194052f8969SDevin Teske local defaultitem= # Calculated below 195052f8969SDevin Teske local hline= 196641a6cfbSDevin Teske 1971da51566SDevin Teske # 1981da51566SDevin Teske # Pick up the base modules (directories named `[0-9][0-9][0-9].*') 1991da51566SDevin Teske # 20014599250SDevin Teske local menuitem menu_title menu_help menu_selection index=2 201e14ddd1fSDevin Teske for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do 202636621d9SDevin Teske [ -f "$BSDCFG_LIBE/$menuitem/INDEX" ] || continue 203641a6cfbSDevin Teske [ $index -lt ${#DIALOG_MENU_TAGS} ] || break 204641a6cfbSDevin Teske 205e363bf2bSDevin Teske menu_program= menu_title= menu_help= 206e14ddd1fSDevin Teske f_include_lang $BSDCFG_LIBE/$menuitem/INDEX 207641a6cfbSDevin Teske [ "$menu_program" ] || continue 208641a6cfbSDevin Teske 209641a6cfbSDevin Teske case "$menu_program" in 210641a6cfbSDevin Teske /*) : already fully qualified ;; 211f4a3220cSDevin Teske *) menu_program="$menuitem/$menu_program" 212641a6cfbSDevin Teske esac 213641a6cfbSDevin Teske 214d356ca0cSDevin Teske f_substr -v tag "$DIALOG_MENU_TAGS" $index 1 215e363bf2bSDevin Teske setvar "menu_program$tag" "$menu_program" 216e363bf2bSDevin Teske 21744392705SDevin Teske f_shell_escape "$menu_title" menu_title 21844392705SDevin Teske f_shell_escape "$menu_help" menu_help 219641a6cfbSDevin Teske menu_list="$menu_list '$tag' '$menu_title' '$menu_help'" 220641a6cfbSDevin Teske 221641a6cfbSDevin Teske index=$(( $index + 1 )) 222641a6cfbSDevin Teske done 223641a6cfbSDevin Teske 2241da51566SDevin Teske # 2251da51566SDevin Teske # Process the `local' libexec sources. 2261da51566SDevin Teske # 2271da51566SDevin Teske # Whereas modules in $BSDCFG_LIBE must be named [0-9][0-9][0-9].* 2281da51566SDevin Teske # modules in $BSDCFG_LOCAL_LIBE should NOT be named this way (making it 2291da51566SDevin Teske # more practical for port-maintainers). 2301da51566SDevin Teske # 2311da51566SDevin Teske # This also has the fortunate side-effect of making the de-duplication 2321da51566SDevin Teske # effort rather simple (because so-called `base' modules must be named 2331da51566SDevin Teske # differently than add-on modules). 2341da51566SDevin Teske # 2351da51566SDevin Teske local separator_added= 2361da51566SDevin Teske for menuitem in $( cd "$BSDCFG_LOCAL_LIBE" 2> /dev/null && ls -d * ) 2371da51566SDevin Teske do 2381da51566SDevin Teske # Skip the module if it looks like a `base' module 2391da51566SDevin Teske case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac 2401da51566SDevin Teske 241636621d9SDevin Teske [ -f "$BSDCFG_LOCAL_LIBE/$menuitem/INDEX" ] || continue 2424b97e14fSDevin Teske [ $index -lt ${#DIALOG_MENU_TAGS} ] || break 2434b97e14fSDevin Teske 2441da51566SDevin Teske menu_program= menu_title= menu_help= 2451da51566SDevin Teske f_include_lang $BSDCFG_LOCAL_LIBE/$menuitem/INDEX || continue 2461da51566SDevin Teske [ "$menu_program" ] || continue 2471da51566SDevin Teske 2481da51566SDevin Teske if [ ! "$separator_added" ]; then 2491da51566SDevin Teske menu_list="$menu_list '-' '-' ''" 2501da51566SDevin Teske separator_added=1 2511da51566SDevin Teske fi 2521da51566SDevin Teske 2531da51566SDevin Teske case "$menu_program" in 2541da51566SDevin Teske /*) : already fully qualified ;; 2551da51566SDevin Teske *) menu_program="$BSDCFG_LOCAL_LIBE/$menuitem/$menu_program" 2561da51566SDevin Teske esac 2571da51566SDevin Teske 258d356ca0cSDevin Teske f_substr -v tag "$DIALOG_MENU_TAGS" $index 1 2591da51566SDevin Teske setvar "menu_program$tag" "$menu_program" 2601da51566SDevin Teske 2611da51566SDevin Teske f_shell_escape "$menu_title" menu_title 2621da51566SDevin Teske f_shell_escape "$menu_help" menu_help 2631da51566SDevin Teske menu_list="$menu_list '$tag' '$menu_title' '$menu_help'" 2641da51566SDevin Teske 2651da51566SDevin Teske index=$(( $index + 1 )) 2661da51566SDevin Teske done 2671da51566SDevin Teske 26874036c4dSDevin Teske local height width rows 26974036c4dSDevin Teske eval f_dialog_menu_with_help_size height width rows \ 270641a6cfbSDevin Teske \"\$title\" \ 271641a6cfbSDevin Teske \"\$btitle\" \ 272641a6cfbSDevin Teske \"\$prompt\" \ 273052f8969SDevin Teske \"\$hline\" \ 27474036c4dSDevin Teske $menu_list 275641a6cfbSDevin Teske 27677599778SDevin Teske # Obtain default-item from previously stored selection 27777599778SDevin Teske f_dialog_default_fetch defaultitem 27877599778SDevin Teske 279fd962ac6SDevin Teske local menu_choice 280fd962ac6SDevin Teske menu_choice=$( eval $DIALOG \ 281641a6cfbSDevin Teske --clear \ 282641a6cfbSDevin Teske --title \"\$title\" \ 283641a6cfbSDevin Teske --backtitle \"\$btitle\" \ 284052f8969SDevin Teske --hline \"\$hline\" \ 285641a6cfbSDevin Teske --item-help \ 286641a6cfbSDevin Teske --ok-label \"\$msg_ok\" \ 287641a6cfbSDevin Teske --cancel-label \"\$msg_exit_bsdconfig\" \ 2886e0adcdaSDevin Teske --help-button \ 2893c91c65aSDevin Teske --help-label \"\$msg_help\" \ 2909c6cbb8aSDevin Teske ${USE_XDIALOG:+--help \"\"} \ 29177599778SDevin Teske --default-item \"\$defaultitem\" \ 29274036c4dSDevin Teske --menu \"\$prompt\" \ 29374036c4dSDevin Teske $height $width $rows \ 29474036c4dSDevin Teske $menu_list \ 29589498fdfSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 29689498fdfSDevin Teske ) 29789498fdfSDevin Teske local retval=$? 298fd962ac6SDevin Teske f_dialog_data_sanitize menu_choice 299fd962ac6SDevin Teske f_dialog_menutag_store "$menu_choice" 300d3a0f918SDevin Teske 301d3a0f918SDevin Teske # Only update default-item on success 302f677a9e2SDevin Teske [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" 303d3a0f918SDevin Teske 30489498fdfSDevin Teske return $retval 305641a6cfbSDevin Teske} 306641a6cfbSDevin Teske 307641a6cfbSDevin Teske############################################################ MAIN 308641a6cfbSDevin Teske 309641a6cfbSDevin Teske# 31099bc932eSDevin Teske# If $0 is not "bsdconfig", interpret it either as a keyword to a menuitem or 31199bc932eSDevin Teske# as a valid resword (see script.subr for additional details about reswords). 31248c5129fSDevin Teske# 31399bc932eSDevin Teskeif [ "$pgm" != "bsdconfig" ]; then 31499bc932eSDevin Teske if indexfile=$( f_index_file "$pgm" ) && 31548c5129fSDevin Teske cmd=$( f_index_menusel_command "$indexfile" "$pgm" ) 31648c5129fSDevin Teske then 31783e449a3SDevin Teske f_dprintf "pgm=[%s] cmd=[%s] *=[%s]" "$pgm" "$cmd" "$*" 31848c5129fSDevin Teske exec "$cmd" "$@" || exit 1 31999bc932eSDevin Teske else 32099bc932eSDevin Teske f_include $BSDCFG_SHARE/script.subr 32199bc932eSDevin Teske for resword in $RESWORDS; do 32299bc932eSDevin Teske [ "$pgm" = "$resword" ] || continue 32399bc932eSDevin Teske # Found a match 32499bc932eSDevin Teske f_dprintf "pgm=[%s] A valid resWord!" "$pgm" 325e5cb2e69SDevin Teske f_dispatch $resword $resword "$@" 32699bc932eSDevin Teske exit $? 32799bc932eSDevin Teske done 32899bc932eSDevin Teske fi 32948c5129fSDevin Teskefi 33048c5129fSDevin Teske 33148c5129fSDevin Teske# 332641a6cfbSDevin Teske# Process command-line arguments 333641a6cfbSDevin Teske# 33499bc932eSDevin Teskescripts_loaded=0 335c3755aa3SDevin Teskewhile getopts f:h$GETOPTS_STDARGS flag; do 336641a6cfbSDevin Teske case "$flag" in 33799bc932eSDevin Teske f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr 33899bc932eSDevin Teske f_script_load "$OPTARG" 33999bc932eSDevin Teske scripts_loaded=$(( $scripts_loaded + 1 )) ;; 340641a6cfbSDevin Teske h|\?) usage ;; 341641a6cfbSDevin Teske esac 342641a6cfbSDevin Teskedone 343641a6cfbSDevin Teskeshift $(( $OPTIND - 1 )) 344641a6cfbSDevin Teske 34599bc932eSDevin Teske# If we've loaded any scripts, do not continue any further 34699bc932eSDevin Teske[ $scripts_loaded -gt 0 ] && exit 34799bc932eSDevin Teske 348641a6cfbSDevin Teske# 349641a6cfbSDevin Teske# Initialize 350641a6cfbSDevin Teske# 351641a6cfbSDevin Teskef_dialog_title "$msg_main_menu" 352641a6cfbSDevin Teske 353641a6cfbSDevin Teske[ "$SECURE" ] && f_mustberoot_init 354641a6cfbSDevin Teske 355641a6cfbSDevin Teske# Incorporate rc-file if it exists 356641a6cfbSDevin Teske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 357641a6cfbSDevin Teske 358641a6cfbSDevin Teske# 359641a6cfbSDevin Teske# If a non-option argument was passed, process it as a menuitem selection... 360641a6cfbSDevin Teske# 361641a6cfbSDevin Teskeif [ "$1" ]; then 362641a6cfbSDevin Teske # 363641a6cfbSDevin Teske # ...unless it's a long-option for usage. 364641a6cfbSDevin Teske # 36565c7c087SDevin Teske case "$1" in -help|--help|-\?) 36665c7c087SDevin Teske usage 3671c64959bSDevin Teske # NOTREACHED 368641a6cfbSDevin Teske esac 369641a6cfbSDevin Teske 370641a6cfbSDevin Teske # 37148c5129fSDevin Teske # Find the INDEX (possibly i18n) claiming this keyword and get the 37248c5129fSDevin Teske # command to execute from the menu_selection line. 373641a6cfbSDevin Teske # 37448c5129fSDevin Teske if ! { indexfile=$( f_index_file "$1" ) && 37548c5129fSDevin Teske cmd=$( f_index_menusel_command "$indexfile" "$1" ) 37648c5129fSDevin Teske }; then 3771c64959bSDevin Teske # No matches, display usage (which shows valid keywords) 378641a6cfbSDevin Teske f_err "%s: %s: $msg_not_found\n" "$pgm" "$1" 379641a6cfbSDevin Teske usage 3801c64959bSDevin Teske # NOTREACHED 381641a6cfbSDevin Teske fi 382641a6cfbSDevin Teske 383c4364d01SDevin Teske f_dprintf "cmd=[%s] *=[%s]" "$cmd" "$*" 384641a6cfbSDevin Teske shift 385641a6cfbSDevin Teske exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1 3861c64959bSDevin Teske # NOTREACHED 387641a6cfbSDevin Teskefi 388641a6cfbSDevin Teske 389641a6cfbSDevin Teske# 390641a6cfbSDevin Teske# Launch application main menu 391641a6cfbSDevin Teske# 392641a6cfbSDevin Teskewhile :; do 393641a6cfbSDevin Teske dialog_menu_main 394641a6cfbSDevin Teske retval=$? 395fd962ac6SDevin Teske f_dialog_menutag_fetch mtag 396526e1dc1SDevin Teske f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" 397641a6cfbSDevin Teske 398f677a9e2SDevin Teske if [ $retval -eq $DIALOG_HELP ]; then 39940dfc82dSDevin Teske f_show_help "$BSDCONFIG_HELPFILE" 4006e0adcdaSDevin Teske continue 401f677a9e2SDevin Teske elif [ $retval -ne $DIALOG_OK ]; then 4026e0adcdaSDevin Teske f_die 4036e0adcdaSDevin Teske fi 404641a6cfbSDevin Teske 405641a6cfbSDevin Teske case "$mtag" in 406fd3d4fecSDevin Teske X) break ;; 40714599250SDevin Teske 1) # Usage 40840dfc82dSDevin Teske f_show_help "$USAGE_HELPFILE" 40914599250SDevin Teske continue 410fd3d4fecSDevin Teske esac 41114599250SDevin Teske 412fd3d4fecSDevin Teske # Anything else is a dynamically loaded menuitem 413fd3d4fecSDevin Teske 4145421f6b1SDevin Teske f_getvar menu_program$mtag menu_program 4155421f6b1SDevin Teske case "$menu_program" in 4165421f6b1SDevin Teske /*) cmd="$menu_program" ;; 4175421f6b1SDevin Teske *) cmd="$BSDCFG_LIBE/$menu_program" 4185421f6b1SDevin Teske esac 419526e1dc1SDevin Teske f_dprintf "cmd=[%s]" "$cmd" 420641a6cfbSDevin Teske $cmd ${USE_XDIALOG:+-X} 421641a6cfbSDevin Teskedone 422641a6cfbSDevin Teske 423641a6cfbSDevin Teskeexit $SUCCESS 424641a6cfbSDevin Teske 425641a6cfbSDevin Teske################################################################################ 426641a6cfbSDevin Teske# END 427641a6cfbSDevin Teske################################################################################ 428