2012-07-13 23:16:57 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
#-
|
2013-04-22 01:02:34 -04:00
|
|
|
# Copyright (c) 2012-2013 Devin Teske
|
2013-07-07 14:21:30 -04:00
|
|
|
# All rights reserved.
|
2012-07-13 23:16:57 -04:00
|
|
|
#
|
|
|
|
|
# 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
|
2013-07-07 14:51:44 -04:00
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
2012-07-13 23:16:57 -04:00
|
|
|
# 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
|
2013-07-07 14:51:44 -04:00
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
2012-07-13 23:16:57 -04:00
|
|
|
# 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
|
|
|
|
|
|
2012-09-18 18:28:42 -04:00
|
|
|
BSDCFG_SHARE="/usr/share/bsdconfig"
|
|
|
|
|
. $BSDCFG_SHARE/common.subr || exit 1
|
2012-12-25 05:47:45 -05:00
|
|
|
f_dprintf "%s: loading includes..." "$0"
|
2012-09-18 18:28:42 -04:00
|
|
|
f_include $BSDCFG_SHARE/dialog.subr
|
|
|
|
|
f_include $BSDCFG_SHARE/mustberoot.subr
|
|
|
|
|
f_include $BSDCFG_SHARE/sysrc.subr
|
2012-07-13 23:16:57 -04:00
|
|
|
|
2012-09-18 18:28:42 -04:00
|
|
|
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
|
2012-07-13 23:16:57 -04:00
|
|
|
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
|
|
|
|
|
|
2013-12-06 19:31:01 -05:00
|
|
|
f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
|
|
|
|
|
pgm="${ipgm:-$pgm}"
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
############################################################ FUNCTIONS
|
|
|
|
|
|
|
|
|
|
# dialog_menu_main
|
|
|
|
|
#
|
|
|
|
|
# Display the dialog(1)-based application main menu.
|
|
|
|
|
#
|
|
|
|
|
dialog_menu_main()
|
|
|
|
|
{
|
|
|
|
|
local prompt="$msg_miscellaneous_menu_text"
|
Standardize the way functions build their arguments leading up to a dialog
invocation. Specifically, "top-load" your arguments and in the order in-
which they will be displayed. For example, many [if not all] widgets display
information in the following order, top-to-bottom (visually):
+ backtitle (displayed behind the widget at top-left)
+ title (at the top of the `window')
+ prompt text (just below the title and above whatever widget you choose)
+ Depending on widget, _one_ of the following:
- menu list
- radio list
- check list
- text input box with initial text
- [Xdialog(1)] 2x or 3x text input boxes
- [dialog(1)] a multi-part form
- progress bar
- etc. (many more widget choices)
+ buttons (right below the selected widget)
+ [dialog(1)] the hline (displayed at bottom of `window')
NOTE: Xdialog(1) accepts and silently ignores --hline
When building local arguments for your dialog invocation, if the value can't
be cleanly loaded into a local, add "# Calculated below" to the end of the
local declaration while retaining the block order of argument declarations.
Move other local declarations that are not associated with this top-loading
the dialog arguments to right-above where they are first-used.
Also, standardize on the names of the arguments. For example, always use
$prompt (instead of sometimes $msg and sometimes $prompt); use $menu_list
or $shell_list or $radio_list for those respective widgets; ad nauseum.
While we're doing this, flush-out full arguments for many invocations that
were passing NULL strings (making it unapparent if you were staring at this
one invocation what argument that NULL string was supposed to represent).
Last, while we're in startup/rcconf let's remove the unnecessary use of a
GLOBAL (RCCONF_MENU_LIST) for the menu_list.
2013-06-02 16:02:50 -04:00
|
|
|
local menu_list="
|
2013-06-08 12:28:08 -04:00
|
|
|
'X $msg_exit' '$msg_exit_this_menu'
|
2012-07-13 23:16:57 -04:00
|
|
|
" # END-QUOTE
|
Standardize the way functions build their arguments leading up to a dialog
invocation. Specifically, "top-load" your arguments and in the order in-
which they will be displayed. For example, many [if not all] widgets display
information in the following order, top-to-bottom (visually):
+ backtitle (displayed behind the widget at top-left)
+ title (at the top of the `window')
+ prompt text (just below the title and above whatever widget you choose)
+ Depending on widget, _one_ of the following:
- menu list
- radio list
- check list
- text input box with initial text
- [Xdialog(1)] 2x or 3x text input boxes
- [dialog(1)] a multi-part form
- progress bar
- etc. (many more widget choices)
+ buttons (right below the selected widget)
+ [dialog(1)] the hline (displayed at bottom of `window')
NOTE: Xdialog(1) accepts and silently ignores --hline
When building local arguments for your dialog invocation, if the value can't
be cleanly loaded into a local, add "# Calculated below" to the end of the
local declaration while retaining the block order of argument declarations.
Move other local declarations that are not associated with this top-loading
the dialog arguments to right-above where they are first-used.
Also, standardize on the names of the arguments. For example, always use
$prompt (instead of sometimes $msg and sometimes $prompt); use $menu_list
or $shell_list or $radio_list for those respective widgets; ad nauseum.
While we're doing this, flush-out full arguments for many invocations that
were passing NULL strings (making it unapparent if you were staring at this
one invocation what argument that NULL string was supposed to represent).
Last, while we're in startup/rcconf let's remove the unnecessary use of a
GLOBAL (RCCONF_MENU_LIST) for the menu_list.
2013-06-02 16:02:50 -04:00
|
|
|
local defaultitem= # Calculated below
|
|
|
|
|
local hline="$hline_arrows_tab_enter"
|
2012-07-13 23:16:57 -04:00
|
|
|
|
2013-06-02 18:34:40 -04:00
|
|
|
# List of variables we'll need from rc.conf(5)
|
Standardize the way functions build their arguments leading up to a dialog
invocation. Specifically, "top-load" your arguments and in the order in-
which they will be displayed. For example, many [if not all] widgets display
information in the following order, top-to-bottom (visually):
+ backtitle (displayed behind the widget at top-left)
+ title (at the top of the `window')
+ prompt text (just below the title and above whatever widget you choose)
+ Depending on widget, _one_ of the following:
- menu list
- radio list
- check list
- text input box with initial text
- [Xdialog(1)] 2x or 3x text input boxes
- [dialog(1)] a multi-part form
- progress bar
- etc. (many more widget choices)
+ buttons (right below the selected widget)
+ [dialog(1)] the hline (displayed at bottom of `window')
NOTE: Xdialog(1) accepts and silently ignores --hline
When building local arguments for your dialog invocation, if the value can't
be cleanly loaded into a local, add "# Calculated below" to the end of the
local declaration while retaining the block order of argument declarations.
Move other local declarations that are not associated with this top-loading
the dialog arguments to right-above where they are first-used.
Also, standardize on the names of the arguments. For example, always use
$prompt (instead of sometimes $msg and sometimes $prompt); use $menu_list
or $shell_list or $radio_list for those respective widgets; ad nauseum.
While we're doing this, flush-out full arguments for many invocations that
were passing NULL strings (making it unapparent if you were staring at this
one invocation what argument that NULL string was supposed to represent).
Last, while we're in startup/rcconf let's remove the unnecessary use of a
GLOBAL (RCCONF_MENU_LIST) for the menu_list.
2013-06-02 16:02:50 -04:00
|
|
|
local var_list="
|
2012-07-13 23:16:57 -04:00
|
|
|
accounting_enable
|
|
|
|
|
local_startup
|
|
|
|
|
lpd_enable
|
|
|
|
|
named_enable
|
|
|
|
|
named_flags
|
|
|
|
|
nis_client_enable
|
|
|
|
|
nis_server_enable
|
|
|
|
|
nisdomainname
|
|
|
|
|
startup_dirs
|
|
|
|
|
" # END-QUOTE
|
|
|
|
|
|
2013-06-02 18:34:40 -04:00
|
|
|
# Add i386-specific variables if appropriate
|
2012-07-13 23:16:57 -04:00
|
|
|
if [ "$UNAME_P" = "i386" ]; then
|
|
|
|
|
var_list="$var_list
|
|
|
|
|
apm_enable
|
|
|
|
|
" # END-QUOTE
|
|
|
|
|
fi
|
|
|
|
|
|
Standardize the way functions build their arguments leading up to a dialog
invocation. Specifically, "top-load" your arguments and in the order in-
which they will be displayed. For example, many [if not all] widgets display
information in the following order, top-to-bottom (visually):
+ backtitle (displayed behind the widget at top-left)
+ title (at the top of the `window')
+ prompt text (just below the title and above whatever widget you choose)
+ Depending on widget, _one_ of the following:
- menu list
- radio list
- check list
- text input box with initial text
- [Xdialog(1)] 2x or 3x text input boxes
- [dialog(1)] a multi-part form
- progress bar
- etc. (many more widget choices)
+ buttons (right below the selected widget)
+ [dialog(1)] the hline (displayed at bottom of `window')
NOTE: Xdialog(1) accepts and silently ignores --hline
When building local arguments for your dialog invocation, if the value can't
be cleanly loaded into a local, add "# Calculated below" to the end of the
local declaration while retaining the block order of argument declarations.
Move other local declarations that are not associated with this top-loading
the dialog arguments to right-above where they are first-used.
Also, standardize on the names of the arguments. For example, always use
$prompt (instead of sometimes $msg and sometimes $prompt); use $menu_list
or $shell_list or $radio_list for those respective widgets; ad nauseum.
While we're doing this, flush-out full arguments for many invocations that
were passing NULL strings (making it unapparent if you were staring at this
one invocation what argument that NULL string was supposed to represent).
Last, while we're in startup/rcconf let's remove the unnecessary use of a
GLOBAL (RCCONF_MENU_LIST) for the menu_list.
2013-06-02 16:02:50 -04:00
|
|
|
# Obtain default-item (adjusted below for dynamic tags)
|
|
|
|
|
f_dialog_default_fetch defaultitem
|
|
|
|
|
local ditem="${defaultitem%%[$IFS]*}"
|
|
|
|
|
|
2013-04-22 01:52:06 -04:00
|
|
|
eval "$(
|
2012-07-13 23:16:57 -04:00
|
|
|
. "$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
|
|
|
|
|
:| awk \
|
2013-04-22 01:52:06 -04:00
|
|
|
-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 {
|
2012-07-13 23:16:57 -04:00
|
|
|
i = 1
|
2013-04-22 01:52:06 -04:00
|
|
|
defaultitem = ""
|
|
|
|
|
|
|
|
|
|
printf "menu_list=\"$menu_list\n"
|
|
|
|
|
|
2012-07-13 23:16:57 -04:00
|
|
|
if ( uname_p == "i386" )
|
|
|
|
|
{
|
|
|
|
|
#
|
|
|
|
|
# APM: Auto-power management services
|
|
|
|
|
# (typically laptops)
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
2013-04-22 01:52:06 -04:00
|
|
|
printf separator
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Startup dirs: Set the list of dirs to look for
|
|
|
|
|
# startup scripts
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# named: Run a local name server on this host
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# named flags: Set default flags to named (if enabled)
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# NIS client: This host wishes to be an NIS client.
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# NIS domainname: Set NIS domainname (if enabled)
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# NIS server: This host wishes to be an NIS server.
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
2013-04-22 01:52:06 -04:00
|
|
|
printf separator
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Accounting: This host wishes to run process
|
|
|
|
|
# accounting.
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# lpd: This host has a printer and wants to run lpd.
|
|
|
|
|
#
|
2013-04-22 01:52:06 -04:00
|
|
|
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
|
2012-07-13 23:16:57 -04:00
|
|
|
|
2013-04-22 01:52:06 -04:00
|
|
|
printf "\"\n"
|
|
|
|
|
|
|
|
|
|
if ( defaultitem )
|
|
|
|
|
printf "defaultitem=\"%s\"\n", defaultitem
|
2012-07-13 23:16:57 -04:00
|
|
|
}'
|
|
|
|
|
)"
|
|
|
|
|
|
2013-05-31 15:07:17 -04:00
|
|
|
local height width rows
|
|
|
|
|
eval f_dialog_menu_size height width rows \
|
|
|
|
|
\"\$DIALOG_TITLE\" \
|
|
|
|
|
\"\$DIALOG_BACKTITLE\" \
|
|
|
|
|
\"\$prompt\" \
|
|
|
|
|
\"\$hline\" \
|
|
|
|
|
$menu_list
|
2012-07-13 23:16:57 -04:00
|
|
|
|
Improve portion of the dialog(1) API in dialog.subr responsible for
retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
and --radiolist widgets).
When we (Ron McDowell and I) developed the first version of bsdconfig, it
used temporary files to store responses from dialog(1). That hasn't been
true for some very long time, so the need to always store the return status
of dialog(1) and then call some function to clean-up is long-deprecated. The
function that used to do the clean-up was f_dialog_menutag().
We really don't need f_dialog_menutag() for its originally designed purpose,
as all dialog invocations (even when in a sub-shell) do not use temporary
files anymore.
However, we do need to keep f_dialog_menutag() around because it still fills
the need of being able to abstract the procedure for fetching stored data
provided by functions that display the aforementioned widgets.
In re-designing f_dialog_menutag(), four important changes are made:
1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
2. Introduce the new first-argument of $var_to_set to reduce number of forks
3. Create a corresponding f_dialog_menutag_store() to abstract the storage
4. Offload the sanitization to a new function, f_dialog_data_sanitize()
NOTE: That last one is important. Not all functions need to store their data
for later fetching, meanwhile every invocation of dialog should be sanitized
(as we learned early-on in the i18n-effort -- underlying libraries will spit
warnings to stderr for bad values of $LANG and since dialog outputs its
responses to stderr, we need to sanitize every response of these warnings).
These changes greatly improve readbaility and also improve performance by
reducing unnecessary forking.
2013-06-01 19:58:44 -04:00
|
|
|
local menu_choice
|
|
|
|
|
menu_choice=$( eval $DIALOG \
|
2013-04-22 01:52:06 -04:00
|
|
|
--title \"\$DIALOG_TITLE\" \
|
2012-07-13 23:16:57 -04:00
|
|
|
--backtitle \"\$DIALOG_BACKTITLE\" \
|
|
|
|
|
--hline \"\$hline\" \
|
|
|
|
|
--ok-label \"\$msg_ok\" \
|
|
|
|
|
--cancel-label \"\$msg_cancel\" \
|
2013-04-22 01:52:06 -04:00
|
|
|
--default-item \"\$defaultitem\" \
|
2013-05-31 15:07:17 -04:00
|
|
|
--menu \"\$prompt\" \
|
|
|
|
|
$height $width $rows \
|
2012-07-13 23:16:57 -04:00
|
|
|
$menu_list \
|
2012-09-20 19:44:13 -04:00
|
|
|
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
|
|
|
|
|
)
|
|
|
|
|
local retval=$?
|
Improve portion of the dialog(1) API in dialog.subr responsible for
retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
and --radiolist widgets).
When we (Ron McDowell and I) developed the first version of bsdconfig, it
used temporary files to store responses from dialog(1). That hasn't been
true for some very long time, so the need to always store the return status
of dialog(1) and then call some function to clean-up is long-deprecated. The
function that used to do the clean-up was f_dialog_menutag().
We really don't need f_dialog_menutag() for its originally designed purpose,
as all dialog invocations (even when in a sub-shell) do not use temporary
files anymore.
However, we do need to keep f_dialog_menutag() around because it still fills
the need of being able to abstract the procedure for fetching stored data
provided by functions that display the aforementioned widgets.
In re-designing f_dialog_menutag(), four important changes are made:
1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
2. Introduce the new first-argument of $var_to_set to reduce number of forks
3. Create a corresponding f_dialog_menutag_store() to abstract the storage
4. Offload the sanitization to a new function, f_dialog_data_sanitize()
NOTE: That last one is important. Not all functions need to store their data
for later fetching, meanwhile every invocation of dialog should be sanitized
(as we learned early-on in the i18n-effort -- underlying libraries will spit
warnings to stderr for bad values of $LANG and since dialog outputs its
responses to stderr, we need to sanitize every response of these warnings).
These changes greatly improve readbaility and also improve performance by
reducing unnecessary forking.
2013-06-01 19:58:44 -04:00
|
|
|
f_dialog_data_sanitize menu_choice
|
|
|
|
|
f_dialog_menutag_store "$menu_choice"
|
2013-06-02 05:02:12 -04:00
|
|
|
f_dialog_default_store "$menu_choice"
|
2012-09-20 19:44:13 -04:00
|
|
|
return $retval
|
2012-07-13 23:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
{
|
2012-12-21 13:58:19 -05:00
|
|
|
local prompt="$1" _input="$2"
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
f_dialog_title "$msg_value_required"
|
2013-06-02 01:45:25 -04:00
|
|
|
f_dialog_input _input "$prompt" "$_input" "$hline_alnum_tab_enter"
|
2012-12-21 13:58:19 -05:00
|
|
|
local retval=$?
|
2012-07-13 23:16:57 -04:00
|
|
|
f_dialog_title_restore
|
|
|
|
|
|
|
|
|
|
# Return if user has either pressed ESC or chosen Cancel/No
|
2013-10-09 04:12:26 -04:00
|
|
|
[ $retval -eq $DIALOG_OK ] || return $retval
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
value="$_input"
|
2013-10-09 04:12:26 -04:00
|
|
|
return $DIALOG_OK
|
2012-07-13 23:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
############################################################ MAIN
|
|
|
|
|
|
|
|
|
|
# Incorporate rc-file if it exists
|
|
|
|
|
[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Process command-line arguments
|
|
|
|
|
#
|
2013-05-13 23:21:13 -04:00
|
|
|
while getopts h$GETOPTS_STDARGS flag; do
|
2012-07-13 23:16:57 -04:00
|
|
|
case "$flag" in
|
2013-06-24 16:58:54 -04:00
|
|
|
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
|
2012-07-13 23:16:57 -04:00
|
|
|
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
|
Improve portion of the dialog(1) API in dialog.subr responsible for
retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
and --radiolist widgets).
When we (Ron McDowell and I) developed the first version of bsdconfig, it
used temporary files to store responses from dialog(1). That hasn't been
true for some very long time, so the need to always store the return status
of dialog(1) and then call some function to clean-up is long-deprecated. The
function that used to do the clean-up was f_dialog_menutag().
We really don't need f_dialog_menutag() for its originally designed purpose,
as all dialog invocations (even when in a sub-shell) do not use temporary
files anymore.
However, we do need to keep f_dialog_menutag() around because it still fills
the need of being able to abstract the procedure for fetching stored data
provided by functions that display the aforementioned widgets.
In re-designing f_dialog_menutag(), four important changes are made:
1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
2. Introduce the new first-argument of $var_to_set to reduce number of forks
3. Create a corresponding f_dialog_menutag_store() to abstract the storage
4. Offload the sanitization to a new function, f_dialog_data_sanitize()
NOTE: That last one is important. Not all functions need to store their data
for later fetching, meanwhile every invocation of dialog should be sanitized
(as we learned early-on in the i18n-effort -- underlying libraries will spit
warnings to stderr for bad values of $LANG and since dialog outputs its
responses to stderr, we need to sanitize every response of these warnings).
These changes greatly improve readbaility and also improve performance by
reducing unnecessary forking.
2013-06-01 19:58:44 -04:00
|
|
|
dialog_menu_main || f_die
|
|
|
|
|
f_dialog_menutag_fetch mtag
|
2012-07-13 23:16:57 -04:00
|
|
|
|
|
|
|
|
case "$mtag" in
|
2013-06-08 12:28:08 -04:00
|
|
|
"X $msg_exit") break ;;
|
2013-12-06 19:31:01 -05:00
|
|
|
?" [X] "*) toggled=1 reverse=NO ;;
|
|
|
|
|
*) toggled= reverse=YES
|
2013-06-18 19:18:32 -04:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
case "$mtag" in
|
|
|
|
|
# Simple On/Off toggle bits
|
2012-07-13 23:16:57 -04:00
|
|
|
?" ["?"] $msg_apm")
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set apm_enable "%s"' "$reverse" ;;
|
2012-07-13 23:16:57 -04:00
|
|
|
?" ["?"] $msg_named")
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set named_enable "%s"' "$reverse" ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
?" ["?"] $msg_accounting")
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set accounting_enable "%s"' "$reverse" ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
?" ["?"] $msg_lpd")
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set lpd_enable "%s"' "$reverse" ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
# Multi-variable On/Off toggle bits
|
2012-07-13 23:16:57 -04:00
|
|
|
?" ["?"] $msg_nis_client")
|
2013-12-06 19:31:01 -05:00
|
|
|
if f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set nis_client_enable "%s"' "$reverse"
|
|
|
|
|
then
|
|
|
|
|
[ "$reverse" = "NO" ] || f_eval_catch -dk err "$0" \
|
|
|
|
|
f_sysrc_set 'f_sysrc_set rpcbind_enable YES'
|
|
|
|
|
fi ;;
|
2012-07-13 23:16:57 -04:00
|
|
|
?" ["?"] $msg_nis_server")
|
2013-12-06 19:31:01 -05:00
|
|
|
if f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set nis_server_enable "%s"' "$reverse"
|
|
|
|
|
then
|
|
|
|
|
[ "$reverse" = "NO" ] || f_eval_catch -dk err "$0" \
|
|
|
|
|
f_sysrc_set 'f_sysrc_set rpcbind_enable YES'
|
|
|
|
|
fi ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
# Checkboxes for non-boolean options
|
|
|
|
|
?" ["?"] $msg_nis_domainname")
|
|
|
|
|
dialog_input_value "$msg_nis_domainname_desc" \
|
|
|
|
|
"$( f_sysrc_get nisdomainname )" || continue
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set nisdomainname "%s"' "$value" ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
?" ["?"] $msg_startup_dirs")
|
|
|
|
|
dialog_input_value "$msg_startup_dirs_desc" \
|
|
|
|
|
"$( f_sysrc_get local_startup )" || continue
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set local_startup "%s"' "$value" ;;
|
2013-06-18 19:18:32 -04:00
|
|
|
?" ["?"] $msg_named_flags")
|
|
|
|
|
dialog_input_value "$msg_named_flags_desc" \
|
|
|
|
|
"$( f_sysrc_get named_flags )" || continue
|
2013-12-06 19:31:01 -05:00
|
|
|
f_eval_catch -dk err "$0" f_sysrc_set \
|
|
|
|
|
'f_sysrc_set named_flags "%s"' "$value" ;;
|
2012-07-13 23:16:57 -04:00
|
|
|
esac
|
2013-06-18 19:18:32 -04:00
|
|
|
|
2013-10-09 04:12:26 -04:00
|
|
|
[ $? -eq $DIALOG_OK ] || f_dialog_msgbox "$err\n"
|
2012-07-13 23:16:57 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit $SUCCESS
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# END
|
|
|
|
|
################################################################################
|