1#!/bin/sh 2#- 3# Copyright (c) 2012-2013 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 (INCLUDING, 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# 28############################################################ INCLUDES 29 30BSDCFG_SHARE="/usr/share/bsdconfig" 31. $BSDCFG_SHARE/common.subr || exit 1 32f_dprintf "%s: loading includes..." "$0" 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 40f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && 41 pgm="${ipgm:-$pgm}" 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 prompt="$msg_saver_menu_text" 52 local menu_list=" 53 '1 $msg_none' '$msg_none_saver_desc' 54 '2 $msg_blank' '$msg_blank_desc' 55 '3 $msg_beastie' '$msg_beastie_desc' 56 '4 $msg_daemon' '$msg_daemon_desc' 57 '5 $msg_dragon' '$msg_dragon_desc' 58 '6 $msg_fade' '$msg_fade_desc' 59 '7 $msg_fire' '$msg_fire_desc' 60 '8 $msg_green' '$msg_green_desc' 61 '9 $msg_logo' '$msg_logo_desc' 62 'a $msg_rain' '$msg_rain_desc' 63 'b $msg_snake' '$msg_snake_desc' 64 'c $msg_star' '$msg_star_desc' 65 'd $msg_warp' '$msg_warp_desc' 66 '$msg_timeout' '$msg_timeout_desc' 67 " # END-QUOTE 68 local defaultitem= # Calculated below 69 local hline="$hline_choose_a_screen_saver" 70 71 local height width rows 72 eval f_dialog_menu_size height width rows \ 73 \"\$DIALOG_TITLE\" \ 74 \"\$DIALOG_BACKTITLE\" \ 75 \"\$prompt\" \ 76 \"\$hline\" \ 77 $menu_list 78 79 case "$( f_sysrc_get saver )" in 80 [Nn][Oo]|'') defaultitem="1 $msg_none" ;; 81 blank) defaultitem="2 $msg_blank" ;; 82 beastie) defaultitem="3 $msg_beastie" ;; 83 daemon) defaultitem="4 $msg_daemon" ;; 84 dragon) defaultitem="5 $msg_dragon" ;; 85 fade) defaultitem="6 $msg_fade" ;; 86 fire) defaultitem="7 $msg_fire" ;; 87 green) defaultitem="8 $msg_green" ;; 88 logo) defaultitem="9 $msg_logo" ;; 89 rain) defaultitem="a $msg_rain" ;; 90 snake) defaultitem="b $msg_snake" ;; 91 star) defaultitem="c $msg_star" ;; 92 warp) defaultitem="d $msg_warp" ;; 93 esac 94 95 local menu_choice 96 menu_choice=$( eval $DIALOG \ 97 --title \"\$DIALOG_TITLE\" \ 98 --backtitle \"\$DIALOG_BACKTITLE\" \ 99 --hline \"\$hline\" \ 100 --ok-label \"\$msg_ok\" \ 101 --cancel-label \"\$msg_cancel\" \ 102 --default-item \"\$defaultitem\" \ 103 --menu \"\$prompt\" \ 104 $height $width $rows \ 105 $menu_list \ 106 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 107 ) 108 local retval=$? 109 f_dialog_menutag_store -s "$menu_choice" 110 return $retval 111} 112 113############################################################ MAIN 114 115# Incorporate rc-file if it exists 116[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 117 118# 119# Process command-line arguments 120# 121while getopts h$GETOPTS_STDARGS flag; do 122 case "$flag" in 123 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 124 esac 125done 126shift $(( $OPTIND - 1 )) 127 128# 129# Initialize 130# 131f_dialog_title "$msg_system_console_screen_saver" 132f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 133f_mustberoot_init 134 135# 136# Launch application main menu 137# 138dialog_menu_main || f_die 139f_dialog_menutag_fetch mtag 140 141case "$mtag" in 142"$msg_timeout") # Set the screen saver timeout interval 143 f_dialog_title "$msg_value_required" 144 f_dialog_input blanktime "$msg_enter_timeout_period" \ 145 "$( f_sysrc_get blanktime )" && 146 f_eval_catch "$0" f_sysrc_set \ 147 'f_sysrc_set blanktime "%s"' "$blanktime" || f_die 148 f_dialog_title_restore 149 exit $SUCCESS 150esac 151 152saver_to_set= 153case "$mtag" in 154"1 $msg_none") # Disable the screensaver 155 saver_to_set="NO" ;; 156"2 $msg_blank") # Simply blank the screen 157 saver_to_set="blank" ;; 158"3 $msg_beastie") # "BSD Daemon" animated screen saver (graphics) 159 saver_to_set="beastie" ;; 160"4 $msg_daemon") # "BSD Daemon" animated screen saver (text) 161 saver_to_set="daemon" ;; 162"5 $msg_dragon") # Dragon screensaver (graphics) 163 saver_to_set="dragon" ;; 164"6 $msg_fade") # Fade out effect screen saver 165 saver_to_set="fade" ;; 166"7 $msg_fire") # Flames effect screen saver 167 saver_to_set="fire" ;; 168"8 $msg_green") # "Green" power saving mode (if supported by monitor) 169 saver_to_set="green" ;; 170"9 $msg_logo") # FreeBSD "logo" animated screen saver (graphics) 171 saver_to_set="logo" ;; 172"a $msg_rain") # Rain drops screen saver 173 saver_to_set="rain" ;; 174"b $msg_snake") # Draw a FreeBSD "snake" on your screen 175 saver_to_set="snake" ;; 176"c $msg_star") # A "twinkling stars" effect 177 saver_to_set="star" ;; 178"d $msg_warp") # A "stars warping" effect 179 saver_to_set="warp" ;; 180esac 181 182if [ "$saver_to_set" ]; then 183 f_eval_catch "$0" f_sysrc_set \ 184 'f_sysrc_set saver "%s"' "$saver_to_set" || f_die 185 break 186else 187 f_die 1 "$msg_unknown_saver" 188fi 189 190exit $SUCCESS 191 192################################################################################ 193# END 194################################################################################ 195