xref: /freebsd/usr.sbin/bsdconfig/console/saver (revision 298cf604ccf133b101c6fad42d1a078a1fac58ca)
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$
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
35f_include $BSDCFG_SHARE/sysrc.subr
36
37BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
38f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39
40ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
41[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
42
43############################################################ FUNCTIONS
44
45# dialog_menu_main
46#
47# Display the dialog(1)-based application main menu.
48#
49dialog_menu_main()
50{
51	local menu_list size
52	local hline="$hline_choose_a_screen_saver"
53	local prompt="$msg_saver_menu_text"
54
55	menu_list="
56		'1 $msg_blank'   '$msg_blank_desc'
57		'2 $msg_beastie' '$msg_beastie_desc'
58		'3 $msg_daemon'  '$msg_daemon_desc'
59		'4 $msg_dragon'  '$msg_dragon_desc'
60		'5 $msg_fade'    '$msg_fade_desc'
61		'6 $msg_fire'    '$msg_fire_desc'
62		'7 $msg_green'   '$msg_green_desc'
63		'8 $msg_logo'    '$msg_logo_desc'
64		'9 $msg_rain'    '$msg_rain_desc'
65		'a $msg_snake'   '$msg_snake_desc'
66		'b $msg_star'    '$msg_star_desc'
67		'c $msg_warp'    '$msg_warp_desc'
68		'd $msg_none'    '$msg_none_saver_desc'
69		'$msg_timeout'   '$msg_timeout_desc'
70	" # END-QUOTE
71
72	size=$( eval f_dialog_menu_size \
73	        	\"\$DIALOG_TITLE\"     \
74	        	\"\$DIALOG_BACKTITLE\" \
75	                \"\$prompt\"           \
76	        	\"\$hline\"            \
77	        	$menu_list             )
78
79	local dialog_menu
80	dialog_menu=$( eval $DIALOG \
81		--clear --title \"\$DIALOG_TITLE\" \
82		--backtitle \"\$DIALOG_BACKTITLE\" \
83		--hline \"\$hline\"                \
84		--ok-label \"\$msg_ok\"            \
85		--cancel-label \"\$msg_cancel\"    \
86		--menu \"\$prompt\" $size          \
87		$menu_list                         \
88		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
89	)
90	local retval=$?
91	setvar DIALOG_MENU_$$ "$dialog_menu"
92	return $retval
93}
94
95############################################################ MAIN
96
97# Incorporate rc-file if it exists
98[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
99
100#
101# Process command-line arguments
102#
103while getopts hSX flag; do
104	case "$flag" in
105	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
106	esac
107done
108shift $(( $OPTIND - 1 ))
109
110#
111# Initialize
112#
113f_dialog_init
114f_dialog_title "$msg_system_console_screen_saver"
115f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
116f_mustberoot_init
117
118#
119# Launch application main menu
120#
121while :; do
122	dialog_menu_main
123	retval=$?
124	mtag=$( f_dialog_menutag )
125
126	[ $retval -eq 0 ] || f_die
127
128	case "$mtag" in
129	"1 $msg_blank") # Simply blank the screen
130		f_sysrc_set saver "blank" || f_die
131		break ;;
132	"2 $msg_beastie") # "BSD Daemon" animated screen saver (graphics)
133		f_sysrc_set saver "beastie" || f_die
134		break ;;
135	"3 $msg_daemon") # "BSD Daemon" animated screen saver (text)
136		f_sysrc_set saver "daemon" || f_die
137		break ;;
138	"4 $msg_dragon") # Dragon screensaver (graphics)
139		f_sysrc_set saver "dragon" || f_die
140		break ;;
141	"5 $msg_fade") # Fade out effect screen saver
142		f_sysrc_set saver "fade" || f_die
143		break ;;
144	"6 $msg_fire") # Flames effect screen saver
145		f_sysrc_set saver "fire" || f_die
146		break ;;
147	"7 $msg_green") # "Green" power saving mode (if supported by monitor)
148		f_sysrc_set saver "green" || f_die
149		break ;;
150	"8 $msg_logo") # FreeBSD "logo" animated screen saver (graphics)
151		f_sysrc_set saver "logo" || f_die
152		break ;;
153	"9 $msg_rain") # Rain drops screen saver
154		f_sysrc_set saver "rain" || f_die
155		break ;;
156	"a $msg_snake") # Draw a FreeBSD "snake" on your screen
157		f_sysrc_set saver "snake" || f_die
158		break ;;
159	"b $msg_star") # A "twinkling stars" effect
160		f_sysrc_set saver "star" || f_die
161		break ;;
162	"c $msg_warp") # A "stars warping" effect
163		f_sysrc_set saver "warp" || f_die
164		break ;;
165	"d $msg_none") # Disable the screensaver
166		f_sysrc_set saver "NO" || f_die
167		break ;;
168	"$msg_timeout") # Set the screen saver timeout interval
169		f_dialog_title "$msg_value_required"
170		blanktime=$( f_dialog_input "$msg_enter_timeout_period" \
171		                            "$( f_sysrc_get blanktime )"
172		           ) && f_sysrc_set blanktime "$blanktime"
173		f_dialog_title_restore
174		;;
175	esac
176done
177
178exit $SUCCESS
179
180################################################################################
181# END
182################################################################################
183