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 (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#
| 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 (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/console/saver 250633 2013-05-14 03:21:13Z dteske $
| 27# $FreeBSD: head/usr.sbin/bsdconfig/console/saver 251190 2013-05-31 19:07:17Z dteske $
|
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{
| 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 defaultitem=
| 52 local menu_list defaultitem=
|
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
| 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 )
| 73 local height width rows 74 eval f_dialog_menu_size height width rows \ 75 \"\$DIALOG_TITLE\" \ 76 \"\$DIALOG_BACKTITLE\" \ 77 \"\$prompt\" \ 78 \"\$hline\" \ 79 $menu_list
|
79 80 case "$( f_sysrc_get saver )" in 81 blank) defaultitem="1 $msg_blank" ;; 82 beastie) defaultitem="2 $msg_beastie";; 83 daemon) defaultitem="3 $msg_daemon" ;; 84 dragon) defaultitem="4 $msg_dragon" ;; 85 fade) defaultitem="5 $msg_fade" ;; 86 fire) defaultitem="6 $msg_fire" ;; 87 green) defaultitem="7 $msg_green" ;; 88 logo) defaultitem="8 $msg_logo" ;; 89 rain) defaultitem="9 $msg_rain" ;; 90 snake) defaultitem="a $msg_snake" ;; 91 star) defaultitem="b $msg_star" ;; 92 warp) defaultitem="c $msg_warp" ;; 93 [Nn][Oo]|'') defaultitem="d $msg_none" ;; 94 esac 95 96 local dialog_menu 97 dialog_menu=$( eval $DIALOG \ 98 --title \"\$DIALOG_TITLE\" \ 99 --backtitle \"\$DIALOG_BACKTITLE\" \ 100 --hline \"\$hline\" \ 101 --ok-label \"\$msg_ok\" \ 102 --cancel-label \"\$msg_cancel\" \ 103 --default-item \"\$defaultitem\" \
| 80 81 case "$( f_sysrc_get saver )" in 82 blank) defaultitem="1 $msg_blank" ;; 83 beastie) defaultitem="2 $msg_beastie";; 84 daemon) defaultitem="3 $msg_daemon" ;; 85 dragon) defaultitem="4 $msg_dragon" ;; 86 fade) defaultitem="5 $msg_fade" ;; 87 fire) defaultitem="6 $msg_fire" ;; 88 green) defaultitem="7 $msg_green" ;; 89 logo) defaultitem="8 $msg_logo" ;; 90 rain) defaultitem="9 $msg_rain" ;; 91 snake) defaultitem="a $msg_snake" ;; 92 star) defaultitem="b $msg_star" ;; 93 warp) defaultitem="c $msg_warp" ;; 94 [Nn][Oo]|'') defaultitem="d $msg_none" ;; 95 esac 96 97 local dialog_menu 98 dialog_menu=$( eval $DIALOG \ 99 --title \"\$DIALOG_TITLE\" \ 100 --backtitle \"\$DIALOG_BACKTITLE\" \ 101 --hline \"\$hline\" \ 102 --ok-label \"\$msg_ok\" \ 103 --cancel-label \"\$msg_cancel\" \ 104 --default-item \"\$defaultitem\" \
|
104 --menu \"\$prompt\" $size \
| 105 --menu \"\$prompt\" \ 106 $height $width $rows \
|
105 $menu_list \ 106 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 107 ) 108 local retval=$? 109 setvar DIALOG_MENU_$$ "$dialog_menu" 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# 138while :; do 139 dialog_menu_main 140 retval=$? 141 mtag=$( f_dialog_menutag ) 142 143 [ $retval -eq 0 ] || f_die 144 145 case "$mtag" in 146 "1 $msg_blank") # Simply blank the screen 147 f_sysrc_set saver "blank" || f_die 148 break ;; 149 "2 $msg_beastie") # "BSD Daemon" animated screen saver (graphics) 150 f_sysrc_set saver "beastie" || f_die 151 break ;; 152 "3 $msg_daemon") # "BSD Daemon" animated screen saver (text) 153 f_sysrc_set saver "daemon" || f_die 154 break ;; 155 "4 $msg_dragon") # Dragon screensaver (graphics) 156 f_sysrc_set saver "dragon" || f_die 157 break ;; 158 "5 $msg_fade") # Fade out effect screen saver 159 f_sysrc_set saver "fade" || f_die 160 break ;; 161 "6 $msg_fire") # Flames effect screen saver 162 f_sysrc_set saver "fire" || f_die 163 break ;; 164 "7 $msg_green") # "Green" power saving mode (if supported by monitor) 165 f_sysrc_set saver "green" || f_die 166 break ;; 167 "8 $msg_logo") # FreeBSD "logo" animated screen saver (graphics) 168 f_sysrc_set saver "logo" || f_die 169 break ;; 170 "9 $msg_rain") # Rain drops screen saver 171 f_sysrc_set saver "rain" || f_die 172 break ;; 173 "a $msg_snake") # Draw a FreeBSD "snake" on your screen 174 f_sysrc_set saver "snake" || f_die 175 break ;; 176 "b $msg_star") # A "twinkling stars" effect 177 f_sysrc_set saver "star" || f_die 178 break ;; 179 "c $msg_warp") # A "stars warping" effect 180 f_sysrc_set saver "warp" || f_die 181 break ;; 182 "d $msg_none") # Disable the screensaver 183 f_sysrc_set saver "NO" || f_die 184 break ;; 185 "$msg_timeout") # Set the screen saver timeout interval 186 f_dialog_title "$msg_value_required" 187 blanktime=$( f_dialog_input "$msg_enter_timeout_period" \ 188 "$( f_sysrc_get blanktime )" 189 ) && f_sysrc_set blanktime "$blanktime" 190 f_dialog_title_restore 191 ;; 192 esac 193done 194 195exit $SUCCESS 196 197################################################################################ 198# END 199################################################################################
| 107 $menu_list \ 108 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 109 ) 110 local retval=$? 111 setvar DIALOG_MENU_$$ "$dialog_menu" 112 return $retval 113} 114 115############################################################ MAIN 116 117# Incorporate rc-file if it exists 118[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 119 120# 121# Process command-line arguments 122# 123while getopts h$GETOPTS_STDARGS flag; do 124 case "$flag" in 125 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 126 esac 127done 128shift $(( $OPTIND - 1 )) 129 130# 131# Initialize 132# 133f_dialog_title "$msg_system_console_screen_saver" 134f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 135f_mustberoot_init 136 137# 138# Launch application main menu 139# 140while :; do 141 dialog_menu_main 142 retval=$? 143 mtag=$( f_dialog_menutag ) 144 145 [ $retval -eq 0 ] || f_die 146 147 case "$mtag" in 148 "1 $msg_blank") # Simply blank the screen 149 f_sysrc_set saver "blank" || f_die 150 break ;; 151 "2 $msg_beastie") # "BSD Daemon" animated screen saver (graphics) 152 f_sysrc_set saver "beastie" || f_die 153 break ;; 154 "3 $msg_daemon") # "BSD Daemon" animated screen saver (text) 155 f_sysrc_set saver "daemon" || f_die 156 break ;; 157 "4 $msg_dragon") # Dragon screensaver (graphics) 158 f_sysrc_set saver "dragon" || f_die 159 break ;; 160 "5 $msg_fade") # Fade out effect screen saver 161 f_sysrc_set saver "fade" || f_die 162 break ;; 163 "6 $msg_fire") # Flames effect screen saver 164 f_sysrc_set saver "fire" || f_die 165 break ;; 166 "7 $msg_green") # "Green" power saving mode (if supported by monitor) 167 f_sysrc_set saver "green" || f_die 168 break ;; 169 "8 $msg_logo") # FreeBSD "logo" animated screen saver (graphics) 170 f_sysrc_set saver "logo" || f_die 171 break ;; 172 "9 $msg_rain") # Rain drops screen saver 173 f_sysrc_set saver "rain" || f_die 174 break ;; 175 "a $msg_snake") # Draw a FreeBSD "snake" on your screen 176 f_sysrc_set saver "snake" || f_die 177 break ;; 178 "b $msg_star") # A "twinkling stars" effect 179 f_sysrc_set saver "star" || f_die 180 break ;; 181 "c $msg_warp") # A "stars warping" effect 182 f_sysrc_set saver "warp" || f_die 183 break ;; 184 "d $msg_none") # Disable the screensaver 185 f_sysrc_set saver "NO" || f_die 186 break ;; 187 "$msg_timeout") # Set the screen saver timeout interval 188 f_dialog_title "$msg_value_required" 189 blanktime=$( f_dialog_input "$msg_enter_timeout_period" \ 190 "$( f_sysrc_get blanktime )" 191 ) && f_sysrc_set blanktime "$blanktime" 192 f_dialog_title_restore 193 ;; 194 esac 195done 196 197exit $SUCCESS 198 199################################################################################ 200# END 201################################################################################
|