1238438Sdteskeif [ ! "$_STARTUP_RCEDIT_SUBR" ]; then _STARTUP_RCEDIT_SUBR=1 2238438Sdteske# 3238438Sdteske# Copyright (c) 2012 Devin Teske 4238438Sdteske# All rights reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16238438Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20238438Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD$ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33244675Sdteskef_dprintf "%s: loading includes..." startup/rcedit.subr 34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 35259054Sdteskef_include $BSDCFG_SHARE/strings.subr 36240684Sdteskef_include $BSDCFG_SHARE/sysrc.subr 37238438Sdteske 38240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" 39238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40238438Sdteske 41238438Sdteske############################################################ FUNCTIONS 42238438Sdteske 43238438Sdteske# f_dialog_rcedit $var [[--] $init ...] 44238438Sdteske# 45238438Sdteske# Allow the user to enter a new value for a given rc.conf(5) variable. If the 46238438Sdteske# user does not cancel or press ESC, the variable will be saved without 47238438Sdteske# confirmation. 48238438Sdteske# 49238438Sdteske# If the second argument is non-NULL, it will be processed as the initial text 50238438Sdteske# to be displayed, overriding the default behavior to display the currently 51238438Sdteske# configured value as the initial text. 52238438Sdteske# 53238438Sdteske# If instead the second argument is "--", then the third argument (NULL or 54238438Sdteske# otherwise) will be treated as the initial text. 55238438Sdteske# 56238438Sdteskef_dialog_rcedit() 57238438Sdteske{ 58259054Sdteske local funcname=f_dialog_rcedit 59244548Sdteske local msg var="$1" _input 60238438Sdteske 61259054Sdteske f_sprintf msg "$msg_please_enter_a_new_value" \ 62259054Sdteske "$var" "$( f_sysrc_get_default "$var" )" 63238438Sdteske 64238438Sdteske shift 1 # var 65238438Sdteske if [ "$1" ]; then 66238438Sdteske [ "$1" = "--" ] && shift 1 # -- 67238438Sdteske _input="$1" 68238438Sdteske else 69238438Sdteske _input=$( f_sysrc_get "$var" ) 70238438Sdteske fi 71238438Sdteske 72238438Sdteske # Return if user has either pressed ESC or chosen Cancel/No 73251242Sdteske f_dialog_input _input "$msg" "$_input" \ 74256181Sdteske "$hline_alnum_punc_tab_enter" || return $? 75238438Sdteske 76238438Sdteske # Return if the value has not changed from current 77238438Sdteske local cur_val="$( f_sysrc_get "$var" )" 78256181Sdteske [ "$_input" = "$cur_val" ] && return $DIALOG_OK 79243476Sdteske 80244550Sdteske f_dprintf "%s: [%s]->[%s]" "$var" "$cur_val" "$_input" 81238438Sdteske 82259054Sdteske f_eval_catch $funcname f_sysrc_set \ 83259054Sdteske 'f_sysrc_set "%s" "%s"' "$var" "$_input" 84238438Sdteske} 85238438Sdteske 86244675Sdteske############################################################ MAIN 87244675Sdteske 88244675Sdteskef_dprintf "%s: Successfully loaded." startup/rcedit.subr 89244675Sdteske 90238438Sdteskefi # ! $_STARTUP_RCEDIT_SUBR 91