3 # Copyright (c) 2012-2013 Devin Teske
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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
29 ############################################################ INCLUDES
31 BSDCFG_SHARE="/usr/share/bsdconfig"
32 . $BSDCFG_SHARE/common.subr || exit 1
33 f_dprintf "%s: loading includes..." "$0"
34 f_include $BSDCFG_SHARE/dialog.subr
35 f_include $BSDCFG_SHARE/mustberoot.subr
36 f_include $BSDCFG_SHARE/sysrc.subr
38 BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="080.console"
39 f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
41 ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
42 [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
44 ############################################################ CONFIGURATION
51 ############################################################ FUNCTIONS
55 # Display the dialog(1)-based application main menu.
59 local prompt="$msg_ttys_menu_text"
61 '1 $msg_none' '$msg_none_ttys_desc'
62 '2 $msg_ibm_437_vga_default' 'cons25'
63 '3 $msg_iso_8859_1' 'cons25l1'
64 '4 $msg_iso_8859_2' 'cons25l2'
65 '5 $msg_iso_8859_7' 'cons25l7'
66 '6 $msg_koi8_r' 'cons25r'
67 '7 $msg_koi8_u' 'cons25u'
68 '8 $msg_us_ascii' 'cons25w'
70 local hline="$hline_choose_a_terminal_type"
72 local height width rows
73 eval f_dialog_menu_size height width rows \
75 \"\$DIALOG_BACKTITLE\" \
81 menu_choice=$( eval $DIALOG \
82 --title \"\$DIALOG_TITLE\" \
83 --backtitle \"\$DIALOG_BACKTITLE\" \
85 --ok-label \"\$msg_ok\" \
86 --cancel-label \"\$msg_cancel\" \
88 $height $width $rows \
90 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
93 f_dialog_menutag_store -s "$menu_choice"
95 if [ $retval -eq $DIALOG_OK ]; then
97 item=$( eval f_dialog_menutag2item \
98 \"\$menu_choice\" $menu_list )
99 f_dialog_menuitem_store "$item"
105 # ttys_set_type $consterm
107 # Set terminal type of `ttyv*' and `cons[0-9]' entries in ttys(5) to $consterm.
111 local consterm="$1" err
114 # Create new temporary file to write our ttys(5) update with new types.
116 local tmpfile="$( mktemp -t "$pgm" )"
117 [ "$tmpfile" ] || return $FAILURE
120 # Fixup permissions and ownership (mktemp(1) creates the temporary file
121 # with 0600 permissions -- change the permissions and ownership to
122 # match ttys(5) before we write it out and mv(1) it into place).
124 local mode="$( stat -f '%#Lp' "$ETC_TTYS" 2> /dev/null )"
125 local owner="$( stat -f '%u:%g' "$ETC_TTYS" 2> /dev/null )"
126 f_quietly chmod "${mode:-0644}" "$tmpfile"
127 f_quietly chown "${owner:-root:wheel}" "$tmpfile"
130 # Operate on ttys(5), replacing only the types of `ttyv*' and
131 # `cons[0-9]' terminals with the new type.
133 if ! err=$( awk -v consterm="$consterm" '
137 # "Skip" blank-lines, lines containing only whitespace, and
138 # lines containing only a comment or whitespace-then-comment.
140 if ( $0 ~ /^[[:space:]]*(#|$)/ ) { print; next }
142 # "Skip" terminal types other than those supported
144 if ( $1 !~ /^(ttyv.*|cons[0-9])$/ ) { print; next }
146 # Change the terminal type to the new value
148 match($0, /[[:alnum:]\.\+-_]+[[:space:]]+(on|off).*$/)
149 if ( ! RSTART ) { print; next }
150 left = substr($0, 0, RSTART - 1)
151 match($0, /[[:space:]]+(on|off).*$/)
152 right = substr($0, RSTART)
153 printf "%s%s%s\n", left, consterm, right
155 ' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then
156 f_dialog_msgbox "$err"
159 if ! err=$( mv -f "$tmpfile" "$ETC_TTYS" 2>&1 ); then
160 f_dialog_msgbox "$err"
167 ############################################################ MAIN
169 # Incorporate rc-file if it exists
170 [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
173 # Process command-line arguments
175 while getopts h$GETOPTS_STDARGS flag; do
177 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
180 shift $(( $OPTIND - 1 ))
185 f_dialog_title "$msg_system_console_terminal_type"
186 f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
190 # Launch application main menu
192 dialog_menu_main || f_die
193 f_dialog_menutag_fetch mtag
195 [ "$mtag" = "1 $msg_none" ] && exit $SUCCESS
197 f_dialog_menuitem_fetch consterm
198 ttys_set_type "$consterm" || f_die
202 ################################################################################
204 ################################################################################