rcadd revision 251579
13229Spst#!/bin/sh
23229Spst#-
33229Spst# Copyright (c) 2012-2013 Devin Teske
43229Spst# All Rights Reserved.
53229Spst#
63229Spst# Redistribution and use in source and binary forms, with or without
73229Spst# modification, are permitted provided that the following conditions
83229Spst# are met:
918471Swosch# 1. Redistributions of source code must retain the above copyright
1050476Speter#    notice, this list of conditions and the following disclaimer.
113229Spst# 2. Redistributions in binary form must reproduce the above copyright
123229Spst#    notice, this list of conditions and the following disclaimer in the
133229Spst#    documentation and/or other materials provided with the distribution.
143229Spst#
153229Spst# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1613575Spst# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
1713575Spst# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1813575Spst# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1913575Spst# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
203229Spst# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2169793Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2284125Siedowse# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
233229Spst# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
243229Spst# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2513575Spst# SUCH DAMAGE.
263229Spst#
273229Spst# $FreeBSD: head/usr.sbin/bsdconfig/startup/rcadd 251579 2013-06-09 15:36:13Z dteske $
283229Spst#
293229Spst############################################################ INCLUDES
303229Spst
313229SpstBSDCFG_SHARE="/usr/share/bsdconfig"
323229Spst. $BSDCFG_SHARE/common.subr || exit 1
333229Spstf_dprintf "%s: loading includes..." "$0"
343229Spstf_include $BSDCFG_SHARE/dialog.subr
353229Spstf_include $BSDCFG_SHARE/mustberoot.subr
363229Spstf_include $BSDCFG_SHARE/startup/rcconf.subr
373229Spst
383229SpstBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
393229Spstf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
403229Spst
413229Spstipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
423229Spst[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
433229Spst
443229Spst############################################################ GLOBALS
453229Spst
463229Spst#
473229Spst# Options
483229Spst#
493229Spst# Inherit SHOW_DESC value if set, otherwise default to 1
503229Spst[ "${SHOW_DESC+set}" ] || SHOW_DESC=1
513229Spst
523229Spst############################################################ FUNCTIONS
533229Spst
543229Spst# dialog_menu_main
553229Spst#
563229Spst# Display the dialog(1)-based application main menu.
573229Spst#
583229Spstdialog_menu_main()
593229Spst{
603229Spst	local prompt=
613229Spst	local menu_list="
623229Spst		'1' '$msg_add_from_list'
633229Spst		'2' '$msg_add_custom'
643229Spst	" # END-QUOTE
653229Spst	local hline="$hline_arrows_tab_enter"
663229Spst
673229Spst	local height width rows
683229Spst	eval f_dialog_menu_size height width rows \
693229Spst	                        \"\$DIALOG_TITLE\"     \
703229Spst	                        \"\$DIALOG_BACKTITLE\" \
713229Spst	                        \"\$prompt\"           \
723229Spst	                        \"\$hline\"            \
733229Spst	                        $menu_list
743229Spst
753229Spst	local menu_choice
763229Spst	menu_choice=$( eval $DIALOG \
773229Spst		--title \"\$DIALOG_TITLE\"         \
783229Spst		--backtitle \"\$DIALOG_BACKTITLE\" \
793229Spst		--hline \"\$hline\"                \
803229Spst		--ok-label \"\$msg_ok\"            \
813229Spst		--cancel-label \"\$msg_cancel\"    \
823229Spst		--menu \"\$prompt\"                \
833229Spst		$height $width $rows               \
843229Spst		$menu_list                         \
853229Spst		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
863229Spst	)
873229Spst	local retval=$?
883229Spst	f_dialog_menutag_store -s "$menu_choice"
893229Spst	return $retval
903229Spst}
913229Spst
923229Spst############################################################ MAIN
933229Spst
943229Spst# Incorporate rc-file if it exists
953229Spst[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
963229Spst
973229Spst#
983229Spst# Process command-line arguments
993229Spst#
1003229Spstwhile getopts h$GETOPTS_STDARGS flag; do
1013229Spst	case "$flag" in
1023229Spst	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
1033229Spst	esac
1043229Spstdone
1053229Spstshift $(( $OPTIND - 1 ))
1063229Spst
1073229Spst#
1083229Spst# Initialize
1093229Spst#
1103229Spstf_dialog_title "$msg_add_startup_directive"
1113229Spstf_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
1123229Spstf_mustberoot_init
1134131Sjkh
1143229Spst#
1153229Spst# Launch application main menu
11620287Swollman#
1173229Spstwhile :; do
1183229Spst	dialog_menu_main || f_die
1193229Spst	f_dialog_menutag_fetch mtag
1203229Spst
12184125Siedowse	case "$mtag" in
1223229Spst	1) # Add From List
1233229Spst		# Loop to allow adding multiple variables quickly
1243229Spst		defaultitem=
1253229Spst		while :; do
1263229Spst			f_dialog_input_rclist "$defaultitem" || f_die
1273229Spst			f_dialog_menutag_fetch mtag
12884125Siedowse			defaultitem="$mtag"
1293229Spst
1303229Spst			case "$mtag" in
1313229Spst			"X $msg_exit" ) break ;;
1323229Spst			*) # Anything else is a directive
1333229Spst				rcvar="${mtag# }"
1343229Spst				$BSDCFG_LIBE/$APP_DIR/rcedit \
1353229Spst					${USE_XDIALOG:+-X} "$rcvar"
1363229Spst			esac
1373229Spst		done
1383229Spst		;;
1393229Spst	2) # Add Custom
1403229Spst		f_dialog_input_rcvar || continue
1413229Spst		$BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} "$rcvar"
1423229Spst		;;
1433229Spst	esac
1443229Spstdone
1453229Spst
1463229Spstexit $SUCCESS
1473229Spst
1483229Spst################################################################################
1493229Spst# END
1503229Spst################################################################################
1513229Spst