diff options
author | dteske <dteske@FreeBSD.org> | 2012-07-14 03:16:57 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-07-14 03:16:57 +0000 |
commit | 3981b9b76aa0266598ee7b724e5981627d8ac129 (patch) | |
tree | 8b439d31cf63b5d5c97b653a3cd721fd9961baa5 /usr.sbin/bsdconfig/startup | |
parent | 5d2a55de5070f6d3a8e4b9762a397596e7b308ae (diff) | |
download | FreeBSD-src-3981b9b76aa0266598ee7b724e5981627d8ac129.zip FreeBSD-src-3981b9b76aa0266598ee7b724e5981627d8ac129.tar.gz |
Import bsdconfig(8) as a replacement for the post-install abilities of
deprecated sysinstall(8). NOTE: WITH_BSDCONFIG is currently required.
Submitted by: Devin Teske (dteske), Ron McDowell <rcm@fuzzwad.org>
Reviewed by: Ron McDowell <rcm@fuzzwad.org>
Approved by: Ed Maste (emaste)
Diffstat (limited to 'usr.sbin/bsdconfig/startup')
-rw-r--r-- | usr.sbin/bsdconfig/startup/INDEX | 58 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/Makefile | 16 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/USAGE | 33 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/include/Makefile | 11 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/include/messages.subr | 112 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/include/rcconf.subr | 466 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/include/rcedit.subr | 106 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/startup/include/rcvar.subr | 206 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/misc | 406 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcadd | 153 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcconf | 246 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcdelete | 355 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcedit | 69 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcvar | 200 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/startup | 128 |
15 files changed, 2565 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/startup/INDEX b/usr.sbin/bsdconfig/startup/INDEX new file mode 100644 index 0000000..1b6f5cd --- /dev/null +++ b/usr.sbin/bsdconfig/startup/INDEX @@ -0,0 +1,58 @@ +# Copyright (c) 2012 Ron McDowell +# Copyright (c) 2012 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$ + +# +# Title that will be shown on the bsdconfig menu +menu_title="Startup" +# +# a short descriptive line shown at the bottom of the bsdconfig menu. +# keep it short because any line longer than the terminal width will +# be truncated. +menu_help="Set Startup Parameters" +# +# two-part variable that defines an action to take when 'keyword' +# is passed on a bsdconfig command line. variable takes the form +# "keyword|command" and multiple occurrences of the variable +# (with different 'keyword's, or different 'keyword's AND 'command's) +# are allowed. If 'command' begins with a '/' then the full +# path to the program is needed. If 'command' begins with anything +# else it is a path relative to the directory this INDEX file is in. +# 'keyword' can be i18n'ed but 'command' is the name of a script. +menu_selection="startup|startup" +menu_selection="startup_misc|misc" +menu_selection="startup_rcadd|rcadd" +menu_selection="startup_rcconf|rcconf" +menu_selection="startup_rcdelete|rcdelete" +menu_selection="startup_rcvar|rcvar" +# +# Items below this line do NOT need i18n translation---------------------- +# +# Name of the program to be run when this menu choice is selected. +# if it begins with a '/' then the full path to the program is needed. +# if it begins with anything else it is a path relative to the directory +# this INDEX file is in. +menu_program="startup" diff --git a/usr.sbin/bsdconfig/startup/Makefile b/usr.sbin/bsdconfig/startup/Makefile new file mode 100644 index 0000000..dc198da --- /dev/null +++ b/usr.sbin/bsdconfig/startup/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +NO_OBJ= + +SUBDIR= include + +FILESDIR= ${LIBEXECDIR}/bsdconfig/140.startup +FILES= INDEX USAGE + +SCRIPTSDIR= ${FILESDIR} +SCRIPTS= misc rcadd rcconf rcdelete rcedit rcvar startup + +beforeinstall: + mkdir -p ${DESTDIR}${FILESDIR} + +.include <bsd.prog.mk> diff --git a/usr.sbin/bsdconfig/startup/USAGE b/usr.sbin/bsdconfig/startup/USAGE new file mode 100644 index 0000000..9aa4dca --- /dev/null +++ b/usr.sbin/bsdconfig/startup/USAGE @@ -0,0 +1,33 @@ +# Copyright (c) 2012 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$ + +Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS] + +OPTIONS: + -h Print usage statement and exit. + -S Secure X11 mode (implies `-X'). As root, always prompt-for + and validate sudo(8) username/password before starting. + -X Use Xdialog(1) in place of dialog(1). diff --git a/usr.sbin/bsdconfig/startup/include/Makefile b/usr.sbin/bsdconfig/startup/include/Makefile new file mode 100644 index 0000000..c155eb0 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/include/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +NO_OBJ= + +FILESDIR= ${LIBEXECDIR}/bsdconfig/140.startup/include +FILES= messages.subr rcconf.subr rcedit.subr rcvar.subr + +beforeinstall: + mkdir -p ${DESTDIR}${FILESDIR} + +.include <bsd.prog.mk> diff --git a/usr.sbin/bsdconfig/startup/include/messages.subr b/usr.sbin/bsdconfig/startup/include/messages.subr new file mode 100644 index 0000000..b3cb57f --- /dev/null +++ b/usr.sbin/bsdconfig/startup/include/messages.subr @@ -0,0 +1,112 @@ +# Copyright (c) 2012 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$ + +hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER" +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_accounting="Accounting" +msg_accounting_desc="This host wishes to run process accounting." +msg_add_custom="Add Custom" +msg_add_from_list="Add From List" +msg_add_new="Add New" +msg_add_new_desc="Add new directive" +msg_add_new_help="Add new rc.conf(5) configuration directive" +msg_add_startup_directive="Add Startup Directive" +msg_all="All" +msg_all_desc="Select all directives" +msg_all_help="Select all displayed rc.conf(5) configuration directives" +msg_apm="APM" +msg_apm_desc="Auto-power management services (typically laptops)" +msg_are_you_sure_you_want_to_delete="Are you sure you want to delete the \`%s' directive\nfrom the rc.conf(5) collection of system configuration files?" +msg_are_you_sure_you_want_delete_the_following="Are you sure you want to delete the following directives\nfrom the rc.conf(5) collection of system configuration files?" +msg_cancel="Cancel" +msg_choose_view_details="Choose View Details" +msg_creating_menu_list="Creating menu list...\nThis may take a while." +msg_creating_rcconf_map="Creating rc.conf(5) map...\nThis may take a while." +msg_creating_rcvar_map="Creating rcvar map...\nThis may take a while." +msg_default_value="Default: %s" +msg_delete="Delete" +msg_delete_desc="Delete directive(s)" +msg_delete_help="Select one or more directives from a list to delete" +msg_delete_selected="Delete Selected" +msg_delete_selected_desc="Delete selected directive(s)" +msg_delete_selected_help="Delete each of the selected rc.conf(5) configuration directives" +msg_delete_startup_directives="Delete Startup Directive(s)" +msg_deleting_selected_directives="Deleting selected directive(s)..." +msg_desc="Description" +msg_desc_desc="Toggle display of system description" +msg_details="Details" +msg_exit="Exit" +msg_exit_cancel="Exit/Cancel" +msg_exit_cancel_desc="Return to previous menu" +msg_exit_cancel_help="Return to the previous menu (selected items are untouched)" +msg_exit_desc="Return to previous menu" +msg_exit_help="Exit this menu (returning to previous)" +msg_exit_this_menu="Exit this menu (returning to previous)" +msg_info="Info" +msg_lpd="lpd" +msg_lpd_desc="This host has a printer and wants to run lpd." +msg_miscellaneous_startup_services="Miscellaneous Startup Services" +msg_miscellaneous_menu_text="This menu allows you to configure various aspects of your system's\nstartup configuration. Use [SPACE] or [ENTER] to select items, and\n[TAB] to move to the buttons. Select Exit to leave this menu." +msg_named="named" +msg_named_desc="Run a local name server on this host" +msg_named_flags="named flags" +msg_named_flags_desc="Set default flags to named (if enabled)" +msg_nis_client="NIS client" +msg_nis_client_desc="This host wishes to be an NIS client." +msg_nis_domainname="NIS domainname" +msg_nis_domainname_desc="Set NIS domainname (if enabled)" +msg_nis_server="NIS Server" +msg_nis_server_desc="This host wishes to be an NIS server." +msg_none="None" +msg_none_desc="Un-Select all directives" +msg_none_help="Un-Select all rc.conf(5) configuration directives" +msg_ok="OK" +msg_please_enter_a_new_value="Please enter a new value for \`%s' (Default: %s):" +msg_please_enter_rcvar_name="Please enter rc.conf(5) variable name:" +msg_please_select_an_rcconf_directive="Please select an rc.conf(5) directive:" +msg_rcvar_contains_invalid_chars="ERROR! rc.conf(5) variable name contains invalid characters.\n Name may only consist of letters [a-zA-Z], numbers [0-9],\n or underscore [_] and must not start with a number." +msg_rcvar_must_start_with="ERROR! rc.conf(5) variable name must start with\n a letter [a-zA-Z] or underscore [_]." +msg_reset="Reset" +msg_reset_desc="Reset to default view settings" +msg_sco="SCO" +msg_sco_desc="This host wants to be able to run IBCS2 binaries." +msg_show_configured="Show Configured" +msg_show_configured_desc="Calculate rc.conf(5) locations (slow)" +msg_show_default_value="Show Default/Value" +msg_show_default_value_desc="Show default/configured values" +msg_show_value="Show Value" +msg_show_value_desc="Show configured startup value" +msg_startup="Startup" +msg_startup_dirs="Startup dirs" +msg_startup_dirs_desc="Set the list of dirs to look for startup scripts" +msg_svr4="SVR4" +msg_svr4_desc="This host wants to be able to run SVR4 binaries." +msg_toggle_startup_services="Toggle Startup Services" +msg_value_required="Value Required" +msg_view_details="View Details" +msg_view_details_desc="Choose view details" +msg_view_details_help="Choose which details are shown in the current view" +msg_view_edit_startup_configuration="View/Edit Startup Configuration" diff --git a/usr.sbin/bsdconfig/startup/include/rcconf.subr b/usr.sbin/bsdconfig/startup/include/rcconf.subr new file mode 100644 index 0000000..88bed49 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/include/rcconf.subr @@ -0,0 +1,466 @@ +if [ ! "$_STARTUP_RCCONF_SUBR" ]; then _STARTUP_RCCONF_SUBR=1 +# +# Copyright (c) 2006-2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ GLOBALS + +# +# Initialize in-memory cache variables +# +STARTUP_RCCONF_MAP= +_STARTUP_RCCONF_MAP= + +# +# Define what a variable looks like +# +STARTUP_RCCONF_REGEX="^[[:alpha:]_][[:alnum:]_]*=" + +# +# Default path to on-disk cache file(s) +# +STARTUP_RCCONF_MAP_CACHEFILE="/var/run/bsdconfig/startup_rcconf_map.cache" + +############################################################ FUNCTIONS + +# f_startup_rcconf_list +# +# Produce a list of non-default configuration variables configured in the +# rc.conf(5) collection of files. +# +f_startup_rcconf_list() +{ + ( # Operate within a sub-shell to protect the parent environment + . "$RC_DEFAULTS" > /dev/null + f_clean_env --except PATH STARTUP_RCCONF_REGEX rc_conf_files + source_rc_confs > /dev/null + export _rc_conf_files_file="$( f_sysrc_find rc_conf_files )" + export RC_DEFAULTS + set | awk -F= " + function test_print(var) + { + if ( var == \"OPTIND\" ) return + if ( var == \"PATH\" ) return + if ( var == \"RC_DEFAULTS\" ) return + if ( var == \"STARTUP_RCCONF_REGEX\" ) return + if ( var == \"_rc_conf_files_file\" ) return + if ( var == \"rc_conf_files\" ) + { + if ( ENVIRON[\"_rc_conf_files_file\"] == \ + ENVIRON[\"RC_DEFAULTS\"] ) return + } + print var + } + /$STARTUP_RCCONF_REGEX/ { test_print(\$1) }" + ) +} + +# f_startup_rcconf_map +# +# Produce a map (beit from in-memory cache or on-disk cache) of rc.conf(5) +# variables and their descriptions. The map returned has the following format: +# +# var description +# +# With each as follows: +# +# var the rc.conf(5) variable +# description description of the variable +# +f_startup_rcconf_map() +{ + # If the in-memory cached value is available, return it immediately + if [ "$_STARTUP_RCCONF_MAP" ]; then + echo "$STARTUP_RCCONF_MAP" + return $SUCCESS + fi + + # + # create the in-memory cache (potentially from validated on-disk cache) + # + + # + # Calculate digest used to determine if the on-disk global persistant + # cache file (containg this digest on the first line) is valid and can + # be used to quickly populate the cache value for immediate return. + # + local rc_defaults_digest + rc_defaults_digest=$( md5 < "$RC_DEFAULTS" ) + + # + # Check to see if the global persistant cache file exists + # + if [ -f "$STARTUP_RCCONF_MAP_CACHEFILE" ]; then + # + # Attempt to populate the in-memory cache with the (soon to be) + # be validated on-disk cache. If validation fails, fall-back to + # the current value and provide error exit status. + # + STARTUP_RCCONF_MAP=$( + ( # Get digest as the first word on the first line + read digest rest_ignored + + # + # If the stored digest matches the calculated- + # one populate the in-memory cache from the on- + # disk cache and provide success exit status. + # + if [ "$digest" = "$rc_defaults_digest" ]; then + cat + exit $SUCCESS + else + # Otherwise, return the current value + echo "$STARTUP_RCCONF_MAP" + exit $FAILURE + fi + ) < "$STARTUP_RCCONF_MAP_CACHEFILE" + ) + export STARTUP_RCCONF_MAP + if [ $? -eq $SUCCESS ]; then + export _STARTUP_RCCONF_MAP=1 + echo "$STARTUP_RCCONF_MAP" + return $SUCCESS + fi + # Otherwise, fall-thru to create in-memory cache from scratch + fi + + # + # If we reach this point, we need to generate the data from scratch + # (and after we do, we'll attempt to create the global persistant + # cache file to speed up future executions). + # + + STARTUP_RCCONF_MAP=$( + f_clean_env --except \ + PATH \ + RC_DEFAULTS \ + STARTUP_RCCONF_REGEX \ + f_sysrc_desc_awk + . "$RC_DEFAULTS" + + # Unset variables we don't want reported + unset source_rc_confs_defined + + for var in $( set | awk -F= " + function test_print(var) + { + if ( var == \"OPTIND\" ) return + if ( var == \"PATH\" ) return + if ( var == \"RC_DEFAULTS\" ) return + if ( var == \"STARTUP_RCCONF_REGEX\" ) return + if ( var == \"f_sysrc_desc_awk\" ) return + print var + } + /$STARTUP_RCCONF_REGEX/ { test_print(\$1) } + " ); do + echo $var "$( f_sysrc_desc $var )" + done + ) + export STARTUP_RCCONF_MAP + export _STARTUP_RCCONF_MAP=1 + echo "$STARTUP_RCCONF_MAP" + + # + # Attempt to create the persistant global cache + # + + # Create a new temporary file to write to + local tmpfile="$( mktemp -t "$pgm" )" + [ "$tmpfile" ] || return $FAILURE + + # Write the temporary file contents + echo "$rc_defaults_digest" > "$tmpfile" + echo "$STARTUP_RCCONF_MAP" >> "$tmpfile" + + # Finally, move the temporary file into place + case "$STARTUP_RCCONF_MAP_CACHEFILE" in + */*) f_quietly mkdir -p "${STARTUP_RCCONF_MAP_CACHEFILE%/*}" + esac + mv "$tmpfile" "$STARTUP_RCCONF_MAP_CACHEFILE" +} + +# f_startup_rcconf_map_expand +# +# Expands the map ($RCCONF_MAP) into the shell environment namespace by +# creating _${var}_desc variables containing the description of each variable +# encountered. +# +# NOTE: Variables are exported for later-required awk(1) ENVIRON visibility. +# +f_startup_rcconf_map_expand() +{ + eval "$( echo "$RCCONF_MAP" | awk ' + BEGIN { + rword = "^[[:space:]]*[^[:space:]]*[[:space:]]*" + } + { + var = $1 + desc = $0 + sub(rword, "", desc) + gsub(/'\''/, "'\''\\'\'\''", desc) + printf "_%s_desc='\''%s'\''\n", var, desc + printf "export _%s_desc\n", var + }' )" +} + +# f_dialog_input_view_details +# +# Display a menu for selecting which details are to be displayed. The following +# variables are tracked/modified by the menu/user's selection: +# +# SHOW_DESC Show or hide descriptions +# +# Mutually exclusive options: +# +# SHOW_VALUE Show the value (default; override only) +# SHOW_VALUE_DEFAULT Show both value and default +# SHOW_CONFIGURED Show rc.conf(5) file variable is configured in +# +# Each variable is treated as a boolean (NULL for false, non-NULL for true). +# +# Variables are exported for later-required awk(1) ENVIRON visibility. +# +f_dialog_input_view_details() +{ + local menu_list size + local hline="$hline_arrows_tab_enter" + local prompt="" + + local md=" " m1=" " m2=" " m3=" " + [ "$SHOW_DESC" ] && md="X" + [ "$SHOW_VALUE" ] && m1="*" + [ "$SHOW_DEFAULT_VALUE" ] && m2="*" + [ "$SHOW_CONFIGURED" ] && m3="*" + + menu_list=" + 'X $msg_exit' '$msg_exit_this_menu' + 'R $msg_reset' '$msg_reset_desc' + 'D [$md] $msg_desc' '$msg_desc_desc' + '1 ($m1) $msg_show_value' '$msg_show_value_desc' + '2 ($m2) $msg_show_default_value' '$msg_show_default_value_desc' + '3 ($m3) $msg_show_configured' '$msg_show_configured_desc' + " # END-QUOTE + + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + f_dialog_title "$msg_choose_view_details" + + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" + + local retval=$? + local mtag="$( f_dialog_menutag )" + + f_dialog_title_restore + + [ $retval -eq 0 ] || return $SUCCESS + [ "$mtag" = "X $msg_exit" ] && return $SUCCESS + + case "$mtag" in + "R $msg_reset") + SHOW_VALUE=1 + SHOW_DESC=1 + SHOW_DEFAULT_VALUE= + SHOW_CONFIGURED= + ;; + "D [X] $msg_desc") SHOW_DESC= ;; + "D [ ] $msg_desc") SHOW_DESC=1 ;; + "1 ("?") $msg_show_value") + SHOW_VALUE=1 + SHOW_DEFAULT_VALUE= + SHOW_CONFIGURED= + ;; + "2 ("?") $msg_show_default_value") + SHOW_VALUE= + SHOW_DEFAULT_VALUE=1 + SHOW_CONFIGURED= + ;; + "3 ("?") $msg_show_configured") + SHOW_VALUE= + SHOW_DEFAULT_VALUE= + SHOW_CONFIGURED=1 + ;; + esac +} + +# f_dialog_input_rclist +# +# Presents a menu of rc.conf(5) defaults (with, or without descriptions). This +# function should be treated like a call to dialog(1) (the exit status should +# be captured and f_dialog_menutag() should be used to clean-up and get the +# user's response). +# +f_dialog_input_rclist() +{ + local size + local hline="$hline_arrows_tab_enter" + local prompt="$msg_please_select_an_rcconf_directive" + local menu_list + + menu_list=" + 'X $msg_exit' '' ${SHOW_DESC:+'$msg_exit_help'} + " # END-QUOTE + + if [ ! "$_RCCONF_MAP" ]; then + # Generate RCCONF_MAP of `var desc ...' per-line + f_dialog_info "$msg_creating_rcconf_map" + RCCONF_MAP=$( f_startup_rcconf_map ) + export RCCONF_MAP + # Generate _${var}_desc variables from $RCCONF_MAP + f_startup_rcconf_map_expand + export _RCCONF_MAP=1 + fi + + menu_list="$menu_list $( + export SHOW_DESC + echo "$RCCONF_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 + printf "%s'\'' '\'\''", rcvar + if ( ENVIRON["SHOW_DESC"] ) { + desc = $0 + sub(rword, "", desc) + gsub(/'\''/, "'\''\\'\'\''", desc) + printf " '\''%s'\''", desc + } + printf "\n" + }' + )" + + set -f # noglob + + size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + ${SHOW_DESC:+--item-help} \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +# f_dialog_input_rcvar [$init] +# +# Allows the user to enter the name for a new rc.conf(5) variable. If the user +# does not cancel or press ESC, the $rcvar variable will hold the newly- +# configured value upon return. +# +f_dialog_input_rcvar() +{ + local msg="$msg_please_enter_rcvar_name" + local hline="$hline_alnum_tab_enter" + + # + # Loop until the user provides taint-free/valid input + # + local size _input="$1" + while :; do + size=$( f_dialog_inputbox_size \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$_input" \ + "$hline" ) + + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --inputbox \"\$msg\" $size \ + \"\$_input\" \ + 2> $DIALOG_TMPDIR/dialog.inputbox.$$ + + retval=$? + _input=$( f_dialog_inputstr ) + + # Return if user either pressed ESC or chosen Cancel/No + [ $retval -eq $SUCCESS ] || return $retval + + # Check for invalid entry (1of2) + if ! echo "$_input" | grep -q "^[[:alpha:]_]"; then + f_show_msg "$msg_rcvar_must_start_with" + continue + fi + + # Check for invalid entry (2of2) + if ! echo "$_input" | grep -q "^[[:alpha:]_][[:alnum:]_]*$" + then + f_show_msg "$msg_rcvar_contains_invalid_chars" + continue + fi + + rcvar="$_input" + break + done + + f_dprintf "f_dialog_input_rcvar: rcvar->[$rcvar]" + + return $SUCCESS +} + +fi # ! $_STARTUP_RCCONF_SUBR diff --git a/usr.sbin/bsdconfig/startup/include/rcedit.subr b/usr.sbin/bsdconfig/startup/include/rcedit.subr new file mode 100644 index 0000000..325f1fe --- /dev/null +++ b/usr.sbin/bsdconfig/startup/include/rcedit.subr @@ -0,0 +1,106 @@ +if [ ! "$_STARTUP_RCEDIT_SUBR" ]; then _STARTUP_RCEDIT_SUBR=1 +# +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +############################################################ FUNCTIONS + +# f_dialog_rcedit $var [[--] $init ...] +# +# Allow the user to enter a new value for a given rc.conf(5) variable. If the +# user does not cancel or press ESC, the variable will be saved without +# confirmation. +# +# If the second argument is non-NULL, it will be processed as the initial text +# to be displayed, overriding the default behavior to display the currently +# configured value as the initial text. +# +# If instead the second argument is "--", then the third argument (NULL or +# otherwise) will be treated as the initial text. +# +f_dialog_rcedit() +{ + local msg size retval var="$1" _input + local hline="$hline_alnum_punc_tab_enter" + + msg=$( printf "$msg_please_enter_a_new_value" \ + "$var" "$( f_sysrc_get_default "$var" )" ) + + shift 1 # var + if [ "$1" ]; then + [ "$1" = "--" ] && shift 1 # -- + _input="$1" + else + _input=$( f_sysrc_get "$var" ) + fi + + size=$( f_dialog_inputbox_size \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$_input" \ + "$hline" ) + + local opterm="--" + [ "$USE_XDIALOG" ] && opterm= + + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --inputbox \"\$msg\" $size \ + $opterm \"\$_input\" \ + 2> $DIALOG_TMPDIR/dialog.inputbox.$$ + + retval=$? + _input=$( f_dialog_inputstr ) + + # Return if user has either pressed ESC or chosen Cancel/No + [ $retval -eq $SUCCESS ] || return $retval + + # Return if the value has not changed from current + local cur_val="$( f_sysrc_get "$var" )" + [ "$_input" = "$cur_val" ] && return $SUCCESS + + f_dprintf "$var: [$cur_val]->[$_input]" + + err=$( f_sysrc_set "$var" "$_input" 2>&1 ) || + f_show_msg "$err" +} + +fi # ! $_STARTUP_RCEDIT_SUBR diff --git a/usr.sbin/bsdconfig/startup/include/rcvar.subr b/usr.sbin/bsdconfig/startup/include/rcvar.subr new file mode 100644 index 0000000..c7ad74d --- /dev/null +++ b/usr.sbin/bsdconfig/startup/include/rcvar.subr @@ -0,0 +1,206 @@ +if [ ! "$_STARTUP_RCVAR_SUBR" ]; then _STARTUP_RCVAR_SUBR=1 +# +# Copyright (c) 2006-2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/sysrc.subr + +############################################################ CONFIGURATION + +# +# Default path to the `/etc/rc.d' directory where service(8) scripts are stored +# +: ${ETC_RC_D:=/etc/rc.d} + +# +# Default path to `/etc/rc.subr' (for find_local_scripts_new()) +# +: ${ETC_RC_SUBR:=/etc/rc.subr} + +############################################################ GLOBALS + +# +# Initialize in-memory cache variables +# +STARTUP_RCVAR_MAP= +_STARTUP_RCVAR_MAP= + +# +# Define what an rcvar looks like +# +STARTUP_RCVAR_REGEX='[[:alpha:]_][[:alnum:]_]*="([Yy][Ee][Ss]|[Nn][Oo])"' + +# +# Default path to on-disk cache file(s) +# +STARTUP_RCVAR_MAP_CACHEFILE="/var/run/bsdconfig/startup_rcvar_map.cache" + +############################################################ FUNCTIONS + +# f_startup_rcvar_map +# +# Produce a map (beit from in-memory cache or on-disk cache) of rc.d scripts +# and their associated rcvar's. The map returned has the following format: +# +# rcvar default script description +# +# With each as follows: +# +# rcvar the variable used to enable this rc.d script +# default default value for this variable +# script the rc.d script in-question +# description description of the variable from rc.conf(5) defaults +# +f_startup_rcvar_map() +{ + # If the in-memory cached value is available, return it immediately + if [ "$_STARTUP_RCVAR_MAP" ]; then + echo "$STARTUP_RCVAR_MAP" + return $SUCCESS + fi + + # + # create the in-memory cache (potentially from validated on-disk cache) + # + + # Get a list of /etc/rc.d scripts ... + local file rc_script_list= + for file in "$ETC_RC_D"/*; do + [ -f "$file" ] || continue + [ -x "$file" ] || continue + rc_script_list="$rc_script_list${rc_script_list:+ }$file" + done + # ... and /usr/local/etc/rc.d scripts + rc_script_list="$rc_script_list${rc_script_list:+ }$( + local_startup=$( f_sysrc_get local_startup ) + f_include "$ETC_RC_SUBR" + find_local_scripts_new + echo $local_rc + )" + + # + # Calculate a digest given the checksums of all dependencies (scripts and + # the defaults file). This digest will be used to determine if an on-disk + # global persistant cache file (containg this digest on the first line) + # is valid and can be used to quickly populate the cache value for + # immediate return. + # + local rc_script_list_digest + rc_script_list_digest=$( cd "$ETC_RC_D" && + cksum "$RC_DEFAULTS" $rc_script_list | md5 ) + + # + # Check to see if the global persistant cache file exists + # + if [ -f "$STARTUP_RCVAR_MAP_CACHEFILE" ]; then + # + # Attempt to populate the in-memory cache with the (soon to be) + # be validated on-disk cache. If validation fails, fall-back to + # the current value and provide error exit status. + # + STARTUP_RCVAR_MAP=$( + ( # Get digest as the first word on the first line + read digest rest_ignored + + # + # If the stored digest matches the calculated-one + # populate the in-memory cache from the on-disk + # cache and provide success exit status. + # + if [ "$digest" = "$rc_script_list_digest" ]; then + cat + exit $SUCCESS + else + # Otherwise, return the current value + echo "$STARTUP_RCVAR_MAP" + exit $FAILURE + fi + ) < "$STARTUP_RCVAR_MAP_CACHEFILE" + ) + export STARTUP_RCVAR_MAP + if [ $? -eq $SUCCESS ]; then + export _STARTUP_RCVAR_MAP=1 + echo "$STARTUP_RCVAR_MAP" + return $SUCCESS + fi + # Otherwise, fall-through to create in-memory cache from scratch + fi + + # + # If we reach this point, we need to generate the data from scratch + # (and after we do, we'll attempt to create the global persistant + # cache file to speed up future executions). + # + + STARTUP_RCVAR_MAP=$( + for script in $rc_script_list; do + rcvar_list=$( $script rcvar | awk -F= \ + -v script="$script" ' + /^'"$STARTUP_RCVAR_REGEX"'/ { + if ( $2 ~ /^"[Yy][Ee][Ss]"$/ ) + print $1 ",YES" + else + print $1 ",NO" + }' ) + for entry in $rcvar_list; do + rcvar="${entry%%,*}" + rcvar_default=$( f_sysrc_get_default "$rcvar" ) + [ "$rcvar_default" ] || + rcvar_default="${entry#*,}" + rcvar_desc=$( f_sysrc_desc "$rcvar" ) + echo $rcvar ${rcvar_default:-NO} \ + $script "$rcvar_desc" + done + done | sort -u + ) + export STARTUP_RCVAR_MAP + export _STARTUP_RCVAR_MAP=1 + echo "$STARTUP_RCVAR_MAP" + + # + # Attempt to create the persistant global cache + # + + # Create a new temporary file to write to + local tmpfile="$( mktemp -t "$pgm" )" + [ "$tmpfile" ] || return $FAILURE + + # Write the temporary file contents + echo "$rc_script_list_digest" > "$tmpfile" + echo "$STARTUP_RCVAR_MAP" >> "$tmpfile" + + # Finally, move the temporary file into place + case "$STARTUP_RCVAR_MAP_CACHEFILE" in + */*) f_quietly mkdir -p "${STARTUP_RCVAR_MAP_CACHEFILE%/*}" + esac + mv "$tmpfile" "$STARTUP_RCVAR_MAP_CACHEFILE" +} + +fi # ! $_STARTUP_RCVAR_SUBR diff --git a/usr.sbin/bsdconfig/startup/misc b/usr.sbin/bsdconfig/startup/misc new file mode 100755 index 0000000..1dd2694 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/misc @@ -0,0 +1,406 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $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 size + local hline="$hline_arrows_tab_enter" + local prompt="$msg_miscellaneous_menu_text" + + 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 + + menu_list="$menu_list $( + . "$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="'%c [%c] %s' '%s'\n" \ + -v sep_fmt="' ' ' -- '\n" \ + 'END { + i = 1 + if ( uname_p == "i386" ) + { + # + # APM: Auto-power management services + # (typically laptops) + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["apm_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_apm"], + ENVIRON["msg_apm_desc"] + } + + # Separator + printf sep_fmt + + # + # Startup dirs: Set the list of dirs to look for + # startup scripts + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( length(ENVIRON["local_startup"]) > 0 \ + ? "X" : " " ), + ENVIRON["msg_startup_dirs"], + ENVIRON["msg_startup_dirs_desc"] + + # + # named: Run a local name server on this host + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["named_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_named"], + ENVIRON["msg_named_desc"] + + # + # named flags: Set default flags to named (if enabled) + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( length(ENVIRON["named_flags"]) > 0 \ + ? "X" : " " ), + ENVIRON["msg_named_flags"], + ENVIRON["msg_named_flags_desc"] + + # + # NIS client: This host wishes to be an NIS client. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["nis_client_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_nis_client"], + ENVIRON["msg_nis_client_desc"] + + # + # NIS domainname: Set NIS domainname (if enabled) + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( length(ENVIRON["nisdomainname"]) > 0 \ + ? "X" : " " ), + ENVIRON["msg_nis_domainname"], + ENVIRON["msg_nis_domainname_desc"] + + # + # NIS server: This host wishes to be an NIS server. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["nis_server_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_nis_server"], + ENVIRON["msg_nis_server_desc"] + + # Separator + printf sep_fmt + + # + # Accounting: This host wishes to run process + # accounting. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["accounting_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_accounting"], + ENVIRON["msg_accounting_desc"] + + # + # lpd: This host has a printer and wants to run lpd. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["lpd_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_lpd"], + ENVIRON["msg_lpd_desc"] + + if ( uname_p == "i386" ) + { + # + # SCO: This host wants to be able to run IBCS2 + # binaries. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["ibcs2_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_sco"], + ENVIRON["msg_sco_desc"] + + # + # SVR4: This host wants to be able to run SVR4 + # binaries. + # + printf menu_fmt, substr(menu_tags, i++, 1), + ( ENVIRON["svr4_enable"] ~ \ + /^[Yy][Ee][Ss]$/ ? "X" : " " ), + ENVIRON["msg_svr4"], + ENVIRON["msg_svr4_desc"] + } + }' + )" + + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + eval $DIALOG \ + --clear --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +# 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 hline="$hline_alnum_tab_enter" + local size prompt="$1" _input="$2" + + f_dialog_title "$msg_value_required" + + size=$( f_dialog_inputbox_size \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$prompt" \ + "$_input" \ + "$hline" ) + + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --inputbox \"\$prompt\" $size \ + \"\$_input\" \ + 2> $DIALOG_TMPDIR/dialog.inputbox.$$ + + retval=$? + _input=$( f_dialog_inputstr ) + + 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 hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +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 + retval=$? + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || f_die + + 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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" + 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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" + 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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" + 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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" ;; + ?" ["?"] $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_show_msg "%s\n" "$err" ;; + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/rcadd b/usr.sbin/bsdconfig/startup/rcadd new file mode 100755 index 0000000..1fba829 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/rcadd @@ -0,0 +1,153 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr + +APP_DIR="140.startup" +f_include $BSDCFG_LIBE/$APP_DIR/include/rcconf.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) +[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" + +############################################################ GLOBALS + +# +# Options +# +# Inherit SHOW_DESC value if set, otherwise default to 1 +( : ${SHOW_DESC?} ) > /dev/null 2>&1 || SHOW_DESC=1 + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local menu_list size + local hline="$hline_arrows_tab_enter" + local prompt="" + + menu_list=" + '1' '$msg_add_from_list' + '2' '$msg_add_custom' + " # END-QUOTE + + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + eval $DIALOG \ + --clear --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_title "$msg_add_startup_directive" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main + retval=$? + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || f_die + + case "$mtag" in + 1) # Add From List + # Loop for easy return + while :; do + f_dialog_input_rclist + retval=$? + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || break + + case "$mtag" in + "X $msg_exit" ) break ;; + *) # Anything else is a directive + rcvar="${mtag# }" + $BSDCFG_LIBE/$APP_DIR/rcedit \ + ${USE_XDIALOG:+-X} \ + "$rcvar" || continue + esac + break + done + [ $retval -eq 0 ] || continue + ;; + 2) # Add Custom + f_dialog_input_rcvar || continue + $BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} "$rcvar" || + continue + ;; + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/rcconf b/usr.sbin/bsdconfig/startup/rcconf new file mode 100755 index 0000000..a18cad1 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/rcconf @@ -0,0 +1,246 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include $BSDCFG_LIBE/$APP_DIR/include/rcconf.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $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?} ) > /dev/null 2>&1 || 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 size + local hline="$hline_arrows_tab_enter" + local prompt="" + + 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" + RCCONF_MAP=$( f_startup_rcconf_map ) + export RCCONF_MAP + # Generate _${var}_desc variables from $RCCONF_MAP + f_startup_rcconf_map_expand + 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 + + size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $RCCONF_MENU_LIST ) + + eval $DIALOG \ + --clear --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} \ + --menu \"\$prompt\" $size \ + $RCCONF_MENU_LIST \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_title "$msg_view_edit_startup_configuration" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +while :; do + dialog_menu_main + retval=$? + mtag=$( f_dialog_menutag ) + + 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 +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/rcdelete b/usr.sbin/bsdconfig/startup/rcdelete new file mode 100755 index 0000000..acec48e --- /dev/null +++ b/usr.sbin/bsdconfig/startup/rcdelete @@ -0,0 +1,355 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include $BSDCFG_LIBE/$APP_DIR/include/rcconf.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $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?} ) > /dev/null 2>&1 || 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 size + local hline="$hline_arrows_tab_enter" + local prompt="" + + RCCONF_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'} + } + " # END-QUOTE + + if [ ! "$_RCCONF_MAP" ]; then + # Genreate RCCONF_MAP of `var desc ...' per-line + f_dialog_info "$msg_creating_rcconf_map" + RCCONF_MAP=$( f_startup_rcconf_map ) + export RCCONF_MAP + # Generate _${var}_desc variables from $RCCONF_MAP + f_startup_rcconf_map_expand + 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["_" 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" + }' + )" + + set -f # noglob + + size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $RCCONF_MENU_LIST ) + + eval $DIALOG \ + --clear --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} \ + --menu \"\$prompt\" $size \ + $RCCONF_MENU_LIST \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +# dialog_menu_delete $var1 [$var2 ...] +# +# Get the user's blessing to delete one or more variables. +# if (and only-if) the user confirms (does not press ESC or Cancel/NO). +# +dialog_menu_delete() +{ + local size + 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 + msg=$( printf "$msg_are_you_sure_you_want_to_delete" \ + "$delete_vars" ) + f_dialog_noyes "$msg" + 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 + }' + ) + + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + local defaultno="defaultno" + [ "$USE_XDIALOG" ] && defaultno="default-no" + + eval $DIALOG \ + --clear --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --$defaultno \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_title "$msg_delete_startup_directives" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +while :; do + dialog_menu_main + retval=$? + mtag=$( f_dialog_menutag ) + + 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_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_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_show_msg "%s\n" "$err" + break + fi + done + unset var # no longer needed + 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 ( eval : \${_${var}_delete?} ) > /dev/null 2>&1; then + unset _${var}_delete + else + setvar _${var}_delete 1 + export _${var}_delete + fi + unset var # no longer needed + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/rcedit b/usr.sbin/bsdconfig/startup/rcedit new file mode 100755 index 0000000..19d1941 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/rcedit @@ -0,0 +1,69 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr + +APP_DIR="140.startup" +f_include $BSDCFG_LIBE/$APP_DIR/include/rcedit.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) +[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +f_dialog_rcedit "$@" + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/rcvar b/usr.sbin/bsdconfig/startup/rcvar new file mode 100755 index 0000000..e66f3bb --- /dev/null +++ b/usr.sbin/bsdconfig/startup/rcvar @@ -0,0 +1,200 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr +f_include $BSDCFG_LIBE/include/sysrc.subr + +APP_DIR="140.startup" +f_include $BSDCFG_LIBE/$APP_DIR/include/rcvar.subr +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $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?} ) > /dev/null 2>&1 || SHOW_DESC=1 + +############################################################ FUNCTIONS + +# dialog_menu_main +# +# Display the dialog(1)-based application main menu. +# +dialog_menu_main() +{ + local size + local hline="$hline_arrows_tab_enter" + local prompt="" + + RCVAR_MENU_LIST=" + 'X $msg_exit' '$msg_exit_this_menu' + ${SHOW_DESC:+'$msg_exit_this_menu'} + " # END-QUOTE + + if [ ! "$_RCVAR_MAP" ]; then + # Genreate 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 + + size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $RCVAR_MENU_LIST ) + + eval $DIALOG \ + --clear --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + ${SHOW_DESC:+--item-help} \ + --menu \"\$prompt\" $size \ + $RCVAR_MENU_LIST \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_title "$msg_toggle_startup_services" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +while :; do + dialog_menu_main + retval=$? + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || f_die + + 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_show_msg "$err" + esac +done + +exit $SUCCESS + +################################################################################ +# END +################################################################################ diff --git a/usr.sbin/bsdconfig/startup/startup b/usr.sbin/bsdconfig/startup/startup new file mode 100755 index 0000000..70e82e0 --- /dev/null +++ b/usr.sbin/bsdconfig/startup/startup @@ -0,0 +1,128 @@ +#!/bin/sh +#- +# Copyright (c) 2012 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_LIBE="/usr/libexec/bsdconfig" +. $BSDCFG_LIBE/include/common.subr || exit 1 +f_include $BSDCFG_LIBE/include/dialog.subr +f_include $BSDCFG_LIBE/include/mustberoot.subr + +APP_DIR="140.startup" +f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr + +ipgm=$( f_index_menu_selection $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 size + local hline="$hline_arrows_tab_enter" + local prompt="" + + menu_list=" + 'X' '$msg_exit' + '1' '$msg_toggle_startup_services' + '2' '$msg_view_edit_startup_configuration' + '3' '$msg_miscellaneous_startup_services' + " # END-QUOTE + + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list ) + + eval $DIALOG \ + --clear --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$prompt\" $size \ + $menu_list \ + 2> "$DIALOG_TMPDIR/dialog.menu.$$" +} + +############################################################ MAIN + +# Incorporate rc-file if it exists +[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" + +# +# Process command-line arguments +# +while getopts hSX flag; do + case "$flag" in + h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; + esac +done +shift $(( $OPTIND - 1 )) + +# +# Initialize +# +f_dialog_init +f_dialog_title "$msg_startup" +f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" +f_mustberoot_init + +# +# Launch application main menu +# +while :; do + dialog_menu_main + retval=$? + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || f_die + + 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 +################################################################################ |