1252995Sdteske#!/bin/sh
2252995Sdteske#-
3252995Sdteske# Copyright (c) 2012-2013 Devin Teske
4252995Sdteske# All rights reserved.
5252995Sdteske#
6252995Sdteske# Redistribution and use in source and binary forms, with or without
7252995Sdteske# modification, are permitted provided that the following conditions
8252995Sdteske# are met:
9252995Sdteske# 1. Redistributions of source code must retain the above copyright
10252995Sdteske#    notice, this list of conditions and the following disclaimer.
11252995Sdteske# 2. Redistributions in binary form must reproduce the above copyright
12252995Sdteske#    notice, this list of conditions and the following disclaimer in the
13252995Sdteske#    documentation and/or other materials provided with the distribution.
14252995Sdteske#
15252995Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16252995Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17252995Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18252995Sdteske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19252995Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20252995Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21252995Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22252995Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23252995Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24252995Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25252995Sdteske# SUCH DAMAGE.
26252995Sdteske#
27252995Sdteske# $FreeBSD$
28252995Sdteske#
29252995Sdteske############################################################ INCLUDES
30252995Sdteske
31252995SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
32252995Sdteske. $BSDCFG_SHARE/common.subr || exit 1
33252995Sdteskef_dprintf "%s: loading includes..." "$0"
34252995Sdteskef_include $BSDCFG_SHARE/dialog.subr
35252995Sdteskef_include $BSDCFG_SHARE/mustberoot.subr
36252995Sdteske
37252995SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
38252995Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39252995Sdteske
40263791Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
41263791Sdteske	pgm="${ipgm:-$pgm}"
42252995Sdteske
43252995Sdteske############################################################ FUNCTIONS
44252995Sdteske
45252995Sdteske# dialog_menu_main
46252995Sdteske#
47252995Sdteske# Display the dialog(1)-based application main menu.
48252995Sdteske#
49252995Sdteskedialog_menu_main()
50252995Sdteske{
51252995Sdteske	local prompt=
52252995Sdteske	local menu_list="
53252995Sdteske		'X' '$msg_exit'
54252995Sdteske		'1' '$msg_toggle_startup_services'
55252995Sdteske		'2' '$msg_view_edit_startup_configuration'
56252995Sdteske		'3' '$msg_miscellaneous_startup_services'
57252995Sdteske	" # END-QUOTE
58252995Sdteske	local defaultitem= # Calculated below
59252995Sdteske	local hline="$hline_arrows_tab_enter"
60252995Sdteske
61252995Sdteske	local height width rows
62252995Sdteske	eval f_dialog_menu_size height width rows \
63252995Sdteske	                        \"\$DIALOG_TITLE\"     \
64252995Sdteske	                        \"\$DIALOG_BACKTITLE\" \
65252995Sdteske	                        \"\$prompt\"           \
66252995Sdteske	                        \"\$hline\"            \
67252995Sdteske	                        $menu_list
68252995Sdteske
69252995Sdteske	# Obtain default-item from previously stored selection
70252995Sdteske	f_dialog_default_fetch defaultitem
71252995Sdteske
72252995Sdteske	local menu_choice
73252995Sdteske	menu_choice=$( eval $DIALOG \
74252995Sdteske		--title \"\$DIALOG_TITLE\"         \
75252995Sdteske		--backtitle \"\$DIALOG_BACKTITLE\" \
76252995Sdteske		--hline \"\$hline\"                \
77252995Sdteske		--ok-label \"\$msg_ok\"            \
78252995Sdteske		--cancel-label \"\$msg_cancel\"    \
79252995Sdteske		--default-item \"\$defaultitem\"   \
80252995Sdteske		--menu \"\$prompt\"                \
81252995Sdteske		$height $width $rows               \
82252995Sdteske		$menu_list                         \
83252995Sdteske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
84252995Sdteske	)
85252995Sdteske	local retval=$?
86252995Sdteske	f_dialog_data_sanitize menu_choice
87252995Sdteske	f_dialog_menutag_store "$menu_choice"
88252995Sdteske	f_dialog_default_store "$menu_choice"
89252995Sdteske	return $retval
90252995Sdteske}
91252995Sdteske
92252995Sdteske############################################################ MAIN
93252995Sdteske
94252995Sdteske# Incorporate rc-file if it exists
95252995Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
96252995Sdteske
97252995Sdteske#
98252995Sdteske# Process command-line arguments
99252995Sdteske#
100252995Sdteskewhile getopts h$GETOPTS_STDARGS flag; do
101252995Sdteske	case "$flag" in
102252995Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
103252995Sdteske	esac
104252995Sdteskedone
105252995Sdteskeshift $(( $OPTIND - 1 ))
106252995Sdteske
107252995Sdteske#
108252995Sdteske# Initialize
109252995Sdteske#
110252995Sdteskef_dialog_title "$msg_startup"
111252995Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
112252995Sdteskef_mustberoot_init
113252995Sdteske
114252995Sdteske#
115252995Sdteske# Launch application main menu
116252995Sdteske#
117252995Sdteskewhile :; do
118252995Sdteske	dialog_menu_main || f_die
119252995Sdteske	f_dialog_menutag_fetch mtag
120252995Sdteske
121252995Sdteske	command=
122252995Sdteske	case "$mtag" in
123252995Sdteske	X) break ;;
124252995Sdteske	1) command=rcvar  ;; # Toggle Startup Services
125252995Sdteske	2) command=rcconf ;; # View/Edit Startup Configuration
126252995Sdteske	3) command=misc   ;; # Miscellaneous Startup Services
127252995Sdteske	esac
128252995Sdteske
129252995Sdteske	if [ "$command" ]; then
130252995Sdteske		$BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
131252995Sdteske	else
132252995Sdteske		f_die 1 "$msg_unknown_startup_menu_selection"
133252995Sdteske	fi
134252995Sdteskedone
135252995Sdteske
136252995Sdteskeexit $SUCCESS
137252995Sdteske
138252995Sdteske################################################################################
139252995Sdteske# END
140252995Sdteske################################################################################
141