startup revision 240684
1#!/bin/sh
2#-
3# Copyright (c) 2012 Devin Teske
4# All Rights Reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/startup/startup 240684 2012-09-18 22:28:42Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_include $BSDCFG_SHARE/dialog.subr
34f_include $BSDCFG_SHARE/mustberoot.subr
35
36BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup"
37f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
38
39ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
40[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
41
42############################################################ FUNCTIONS
43
44# dialog_menu_main
45#
46# Display the dialog(1)-based application main menu.
47#
48dialog_menu_main()
49{
50	local menu_list size
51	local hline="$hline_arrows_tab_enter"
52	local prompt=""
53
54	menu_list="
55		'X' '$msg_exit'
56		'1' '$msg_toggle_startup_services'
57		'2' '$msg_view_edit_startup_configuration'
58		'3' '$msg_miscellaneous_startup_services'
59	" # END-QUOTE
60
61	size=$( eval f_dialog_menu_size \
62	        	\"\$DIALOG_TITLE\"     \
63	        	\"\$DIALOG_BACKTITLE\" \
64	                \"\$prompt\"           \
65	        	\"\$hline\"            \
66	        	$menu_list             )
67
68	eval $DIALOG \
69		--clear --title \"\$DIALOG_TITLE\" \
70		--backtitle \"\$DIALOG_BACKTITLE\" \
71		--hline \"\$hline\"                \
72		--ok-label \"\$msg_ok\"            \
73		--cancel-label \"\$msg_cancel\"    \
74		--menu \"\$prompt\" $size          \
75		$menu_list                         \
76		2> "$DIALOG_TMPDIR/dialog.menu.$$"
77}
78
79############################################################ MAIN
80
81# Incorporate rc-file if it exists
82[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
83
84#
85# Process command-line arguments
86#
87while getopts hSX flag; do
88	case "$flag" in
89	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
90	esac
91done
92shift $(( $OPTIND - 1 ))
93
94#
95# Initialize
96#
97f_dialog_init
98f_dialog_title "$msg_startup"
99f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
100f_mustberoot_init
101
102#
103# Launch application main menu
104#
105while :; do
106	dialog_menu_main
107	retval=$?
108	mtag=$( f_dialog_menutag )
109
110	[ $retval -eq 0 ] || f_die
111
112	case "$mtag" in
113	X) # Exit
114		break ;;
115	1) # Toggle Startup Services
116		$BSDCFG_LIBE/$APP_DIR/rcvar ${USE_XDIALOG:+-X} ;;
117	2) # View/Edit Startup Configuration
118		$BSDCFG_LIBE/$APP_DIR/rcconf ${USE_XDIALOG:+-X} ;;
119	3) # Miscellaneous Startup Services
120		$BSDCFG_LIBE/$APP_DIR/misc ${USE_XDIALOG:+-X} ;;
121	esac
122done
123
124exit $SUCCESS
125
126################################################################################
127# END
128################################################################################
129