1238438Sdteske#!/bin/sh
2238438Sdteske#-
3249746Sdteske# Copyright (c) 2012-2013 Devin Teske
4252980Sdteske# 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
16252987Sdteske# 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
20252987Sdteske# 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..." "$0"
34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr
35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr
36238438Sdteske
37240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
38238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39238438Sdteske
40260678Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
41260678Sdteske	pgm="${ipgm:-$pgm}"
42238438Sdteske
43238438Sdteske############################################################ FUNCTIONS
44238438Sdteske
45238438Sdteske# dialog_menu_main
46238438Sdteske#
47238438Sdteske# Display the dialog(1)-based application main menu.
48238438Sdteske#
49238438Sdteskedialog_menu_main()
50238438Sdteske{
51251264Sdteske	local prompt=
52251264Sdteske	local menu_list="
53238438Sdteske		'X' '$msg_exit'
54238438Sdteske		'1' '$msg_toggle_startup_services'
55238438Sdteske		'2' '$msg_view_edit_startup_configuration'
56238438Sdteske		'3' '$msg_miscellaneous_startup_services'
57238438Sdteske	" # END-QUOTE
58251264Sdteske	local defaultitem= # Calculated below
59251264Sdteske	local hline="$hline_arrows_tab_enter"
60238438Sdteske
61251190Sdteske	local height width rows
62251190Sdteske	eval f_dialog_menu_size height width rows \
63251190Sdteske	                        \"\$DIALOG_TITLE\"     \
64251190Sdteske	                        \"\$DIALOG_BACKTITLE\" \
65251190Sdteske	                        \"\$prompt\"           \
66251190Sdteske	                        \"\$hline\"            \
67251190Sdteske	                        $menu_list
68238438Sdteske
69251244Sdteske	# Obtain default-item from previously stored selection
70251244Sdteske	f_dialog_default_fetch defaultitem
71251244Sdteske
72251236Sdteske	local menu_choice
73251236Sdteske	menu_choice=$( eval $DIALOG \
74251244Sdteske		--title \"\$DIALOG_TITLE\"         \
75251244Sdteske		--backtitle \"\$DIALOG_BACKTITLE\" \
76251244Sdteske		--hline \"\$hline\"                \
77251244Sdteske		--ok-label \"\$msg_ok\"            \
78251244Sdteske		--cancel-label \"\$msg_cancel\"    \
79251244Sdteske		--default-item \"\$defaultitem\"   \
80251244Sdteske		--menu \"\$prompt\"                \
81251244Sdteske		$height $width $rows               \
82251244Sdteske		$menu_list                         \
83240768Sdteske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
84240768Sdteske	)
85240768Sdteske	local retval=$?
86251236Sdteske	f_dialog_data_sanitize menu_choice
87251236Sdteske	f_dialog_menutag_store "$menu_choice"
88251244Sdteske	f_dialog_default_store "$menu_choice"
89240768Sdteske	return $retval
90238438Sdteske}
91238438Sdteske
92238438Sdteske############################################################ MAIN
93238438Sdteske
94238438Sdteske# Incorporate rc-file if it exists
95238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
96238438Sdteske
97238438Sdteske#
98238438Sdteske# Process command-line arguments
99238438Sdteske#
100250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do
101238438Sdteske	case "$flag" in
102252178Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
103238438Sdteske	esac
104238438Sdteskedone
105238438Sdteskeshift $(( $OPTIND - 1 ))
106238438Sdteske
107238438Sdteske#
108238438Sdteske# Initialize
109238438Sdteske#
110238438Sdteskef_dialog_title "$msg_startup"
111238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
112238438Sdteskef_mustberoot_init
113238438Sdteske
114238438Sdteske#
115238438Sdteske# Launch application main menu
116238438Sdteske#
117238438Sdteskewhile :; do
118251236Sdteske	dialog_menu_main || f_die
119251236Sdteske	f_dialog_menutag_fetch mtag
120238438Sdteske
121251967Sdteske	command=
122238438Sdteske	case "$mtag" in
123251967Sdteske	X) break ;;
124251967Sdteske	1) command=rcvar  ;; # Toggle Startup Services
125251967Sdteske	2) command=rcconf ;; # View/Edit Startup Configuration
126251967Sdteske	3) command=misc   ;; # Miscellaneous Startup Services
127238438Sdteske	esac
128251967Sdteske
129251967Sdteske	if [ "$command" ]; then
130251974Sdteske		$BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
131251967Sdteske	else
132251967Sdteske		f_die 1 "$msg_unknown_startup_menu_selection"
133251967Sdteske	fi
134238438Sdteskedone
135238438Sdteske
136238438Sdteskeexit $SUCCESS
137238438Sdteske
138238438Sdteske################################################################################
139238438Sdteske# END
140238438Sdteske################################################################################
141