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_dprintf "%s: loading includes..." "$0" 34f_include $BSDCFG_SHARE/dialog.subr 35f_include $BSDCFG_SHARE/mustberoot.subr 36f_include $BSDCFG_SHARE/sysrc.subr 37 38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console" 39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40 41ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 42[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 43 44############################################################ FUNCTIONS 45 46# dialog_menu_main 47# 48# Display the dialog(1)-based application main menu. 49# 50dialog_menu_main() 51{ 52 local menu_list size 53 local hline="$hline_choose_a_screen_saver" 54 local prompt="$msg_saver_menu_text" 55 56 menu_list=" 57 '1 $msg_blank' '$msg_blank_desc' 58 '2 $msg_beastie' '$msg_beastie_desc' 59 '3 $msg_daemon' '$msg_daemon_desc' 60 '4 $msg_dragon' '$msg_dragon_desc' 61 '5 $msg_fade' '$msg_fade_desc' 62 '6 $msg_fire' '$msg_fire_desc' 63 '7 $msg_green' '$msg_green_desc' 64 '8 $msg_logo' '$msg_logo_desc' 65 '9 $msg_rain' '$msg_rain_desc' 66 'a $msg_snake' '$msg_snake_desc' 67 'b $msg_star' '$msg_star_desc' 68 'c $msg_warp' '$msg_warp_desc' 69 'd $msg_none' '$msg_none_saver_desc' 70 '$msg_timeout' '$msg_timeout_desc' 71 " # END-QUOTE 72 73 size=$( eval f_dialog_menu_size \ 74 \"\$DIALOG_TITLE\" \ 75 \"\$DIALOG_BACKTITLE\" \ 76 \"\$prompt\" \ 77 \"\$hline\" \ 78 $menu_list ) 79 80 local dialog_menu 81 dialog_menu=$( eval $DIALOG \ 82 --clear --title \"\$DIALOG_TITLE\" \ 83 --backtitle \"\$DIALOG_BACKTITLE\" \ 84 --hline \"\$hline\" \ 85 --ok-label \"\$msg_ok\" \ 86 --cancel-label \"\$msg_cancel\" \ 87 --menu \"\$prompt\" $size \ 88 $menu_list \ 89 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 90 ) 91 local retval=$? 92 setvar DIALOG_MENU_$$ "$dialog_menu" 93 return $retval 94} 95 96############################################################ MAIN 97 98# Incorporate rc-file if it exists 99[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 100 101# 102# Process command-line arguments 103# 104while getopts hSX flag; do 105 case "$flag" in 106 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 107 esac 108done 109shift $(( $OPTIND - 1 )) 110 111# 112# Initialize 113# 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