xref: /freebsd/usr.sbin/bsdconfig/mouse/port (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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="110.mouse"
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_port_menu_text"
52	local menu_list="
53		'1 $msg_ps2'      '$msg_ps2_desc'
54		'2 $msg_com1'     '$msg_com1_desc'
55		'3 $msg_com2'     '$msg_com2_desc'
56		'4 $msg_com3'     '$msg_com3_desc'
57		'5 $msg_com4'     '$msg_com4_desc'
58	" # END-QUOTE
59	local defaultitem= # Calculated below
60	local hline=
61
62	local height width rows
63	eval f_dialog_menu_size height width rows \
64	                        \"\$DIALOG_TITLE\"     \
65	                        \"\$DIALOG_BACKTITLE\" \
66	                        \"\$prompt\"           \
67	                        \"\$hline\"            \
68	                        $menu_list
69
70	case "$( f_sysrc_get moused_port )" in
71	/dev/psm0)  defaultitem="1 $msg_ps2"      ;;
72	/dev/cuau0) defaultitem="2 $msg_com1"     ;;
73	/dev/cuau1) defaultitem="3 $msg_com2"     ;;
74	/dev/cuau2) defaultitem="4 $msg_com3"     ;;
75	/dev/cuau3) defaultitem="5 $msg_com4"     ;;
76	esac
77
78	local menu_choice
79	menu_choice=$( eval $DIALOG \
80		--title \"\$DIALOG_TITLE\"         \
81		--backtitle \"\$DIALOG_BACKTITLE\" \
82		--hline \"\$hline\"                \
83		--ok-label \"\$msg_ok\"            \
84		--cancel-label \"\$msg_cancel\"    \
85		--default-item \"\$defaultitem\"   \
86		--menu \"\$prompt\"                \
87		$height $width $rows               \
88		$menu_list                         \
89		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
90	)
91	local retval=$?
92	f_dialog_menutag_store -s "$menu_choice"
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 h$GETOPTS_STDARGS 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_select_your_mouse_port_from_the_following_menu"
115f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
116f_mustberoot_init
117
118#
119# Launch application main menu
120#
121dialog_menu_main || f_die
122f_dialog_menutag_fetch mtag
123
124moused_port_to_set=
125case "$mtag" in
126"1 $msg_ps2") # PS/2 style mouse (/dev/psm0)
127	moused_port_to_set="/dev/psm0" ;;
128"2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0)
129	moused_port_to_set="/dev/cuau0" ;;
130"3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1)
131	moused_port_to_set="/dev/cuau1" ;;
132"4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2)
133	moused_port_to_set="/dev/cuau2" ;;
134"5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3)
135	moused_port_to_set="/dev/cuau3" ;;
136esac
137
138if [ "$moused_port_to_set" ]; then
139	f_eval_catch "$0" f_sysrc_set \
140		'f_sysrc_set moused_port "%s"' "$moused_port_to_set" || f_die
141else
142	f_die 1 "$msg_unknown_mouse_port_selection"
143fi
144
145exit $SUCCESS
146
147################################################################################
148# END
149################################################################################
150