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 f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$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 funcname=ttys_set_type
112 local consterm="$1" err
115 # Create new temporary file to write our ttys(5) update with new types.
118 f_eval_catch -k tmpfile $funcname mktemp 'mktemp -t "%s"' "$pgm" ||
122 # Fixup permissions and ownership (mktemp(1) creates the temporary file
123 # with 0600 permissions -- change the permissions and ownership to
124 # match ttys(5) before we write it out and mv(1) it into place).
127 f_eval_catch -dk mode $funcname stat \
128 'stat -f "%%#Lp" "%s"' "$ETC_TTYS" || mode=0644
129 f_eval_catch -dk owner $funcname stat \
130 'stat -f "%%u:%%g" "%s"' "$ETC_TTYS" || owner="root:wheel"
131 f_eval_catch -d $funcname chmod 'chmod "%s" "%s"' "$mode" "$tmpfile"
132 f_eval_catch -d $funcname chown 'chown "%s" "%s"' "$owner" "$tmpfile"
135 # Operate on ttys(5), replacing only the types of `ttyv*' and
136 # `cons[0-9]' terminals with the new type.
138 if ! err=$( awk -v consterm="$consterm" '
142 # "Skip" blank-lines, lines containing only whitespace, and
143 # lines containing only a comment or whitespace-then-comment.
145 if ( $0 ~ /^[[:space:]]*(#|$)/ ) { print; next }
147 # "Skip" terminal types other than those supported
149 if ( $1 !~ /^(ttyv.*|cons[0-9])$/ ) { print; next }
151 # Change the terminal type to the new value
153 match($0, /[[:alnum:]\.\+-_]+[[:space:]]+(on|off).*$/)
154 if ( ! RSTART ) { print; next }
155 left = substr($0, 0, RSTART - 1)
156 match($0, /[[:space:]]+(on|off).*$/)
157 right = substr($0, RSTART)
158 printf "%s%s%s\n", left, consterm, right
160 ' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then
161 f_dialog_msgbox "$err"
164 f_eval_catch $funcname mv 'mv -f "%s" "%s"' "$tmpfile" "$ETC_TTYS" ||
170 ############################################################ MAIN
172 # Incorporate rc-file if it exists
173 [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
176 # Process command-line arguments
178 while getopts h$GETOPTS_STDARGS flag; do
180 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
183 shift $(( $OPTIND - 1 ))
188 f_dialog_title "$msg_system_console_terminal_type"
189 f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
193 # Launch application main menu
195 dialog_menu_main || f_die
196 f_dialog_menutag_fetch mtag
198 [ "$mtag" = "1 $msg_none" ] && exit $SUCCESS
200 f_dialog_menuitem_fetch consterm
201 ttys_set_type "$consterm" || f_die
205 ################################################################################
207 ################################################################################