rcedit.subr revision 259054
1118621Snjlif [ ! "$_STARTUP_RCEDIT_SUBR" ]; then _STARTUP_RCEDIT_SUBR=1 2118621Snjl# 3118621Snjl# Copyright (c) 2012 Devin Teske 4118621Snjl# All rights reserved. 5118621Snjl# 6118621Snjl# Redistribution and use in source and binary forms, with or without 7118621Snjl# modification, are permitted provided that the following conditions 8118621Snjl# are met: 9118621Snjl# 1. Redistributions of source code must retain the above copyright 10118621Snjl# notice, this list of conditions and the following disclaimer. 11118621Snjl# 2. Redistributions in binary form must reproduce the above copyright 12118621Snjl# notice, this list of conditions and the following disclaimer in the 13118621Snjl# documentation and/or other materials provided with the distribution. 14118621Snjl# 15118621Snjl# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16118621Snjl# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17118621Snjl# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18118621Snjl# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19118621Snjl# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20118621Snjl# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21118621Snjl# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22118621Snjl# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23118621Snjl# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24118621Snjl# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25118621Snjl# SUCH DAMAGE. 26118621Snjl# 27118621Snjl# $FreeBSD: head/usr.sbin/bsdconfig/startup/share/rcedit.subr 259054 2013-12-07 00:31:01Z dteske $ 28130420Sru# 29118621Snjl############################################################ INCLUDES 30179153Srpaulo 31118621SnjlBSDCFG_SHARE="/usr/share/bsdconfig" 32118621Snjl. $BSDCFG_SHARE/common.subr || exit 1 33118621Snjlf_dprintf "%s: loading includes..." startup/rcedit.subr 34118621Snjlf_include $BSDCFG_SHARE/dialog.subr 35118621Snjlf_include $BSDCFG_SHARE/strings.subr 36118621Snjlf_include $BSDCFG_SHARE/sysrc.subr 37118621Snjl 38179153SrpauloBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" 39118621Snjlf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40118621Snjl 41118621Snjl############################################################ FUNCTIONS 42118621Snjl 43118621Snjl# f_dialog_rcedit $var [[--] $init ...] 44118621Snjl# 45118621Snjl# Allow the user to enter a new value for a given rc.conf(5) variable. If the 46118621Snjl# user does not cancel or press ESC, the variable will be saved without 47118621Snjl# confirmation. 48118621Snjl# 49118621Snjl# If the second argument is non-NULL, it will be processed as the initial text 50118621Snjl# to be displayed, overriding the default behavior to display the currently 51118621Snjl# configured value as the initial text. 52118621Snjl# 53118621Snjl# If instead the second argument is "--", then the third argument (NULL or 54118621Snjl# otherwise) will be treated as the initial text. 55118621Snjl# 56118621Snjlf_dialog_rcedit() 57118621Snjl{ 58118621Snjl local funcname=f_dialog_rcedit 59118621Snjl local msg var="$1" _input 60179153Srpaulo 61118621Snjl f_sprintf msg "$msg_please_enter_a_new_value" \ 62118621Snjl "$var" "$( f_sysrc_get_default "$var" )" 63118621Snjl 64118621Snjl shift 1 # var 65118621Snjl if [ "$1" ]; then 66130420Sru [ "$1" = "--" ] && shift 1 # -- 67130420Sru _input="$1" 68118621Snjl else 69118621Snjl _input=$( f_sysrc_get "$var" ) 70130420Sru fi 71118621Snjl 72179153Srpaulo # Return if user has either pressed ESC or chosen Cancel/No 73118621Snjl f_dialog_input _input "$msg" "$_input" \ 74118621Snjl "$hline_alnum_punc_tab_enter" || return $? 75118621Snjl 76130420Sru # Return if the value has not changed from current 77130420Sru local cur_val="$( f_sysrc_get "$var" )" 78118621Snjl [ "$_input" = "$cur_val" ] && return $DIALOG_OK 79130420Sru 80118621Snjl f_dprintf "%s: [%s]->[%s]" "$var" "$cur_val" "$_input" 81118621Snjl 82118621Snjl f_eval_catch $funcname f_sysrc_set \ 83118621Snjl 'f_sysrc_set "%s" "%s"' "$var" "$_input" 84118621Snjl} 85118621Snjl 86179153Srpaulo############################################################ MAIN 87179153Srpaulo 88130420Sruf_dprintf "%s: Successfully loaded." startup/rcedit.subr 89130420Sru 90130420Srufi # ! $_STARTUP_RCEDIT_SUBR 91130420Sru