port revision 238438
117680Spst#!/bin/sh
239297Sfenner#-
317680Spst# Copyright (c) 2012 Devin Teske
417680Spst# All Rights Reserved.
517680Spst#
617680Spst# Redistribution and use in source and binary forms, with or without
717680Spst# modification, are permitted provided that the following conditions
817680Spst# are met:
917680Spst# 1. Redistributions of source code must retain the above copyright
1017680Spst#    notice, this list of conditions and the following disclaimer.
1117680Spst# 2. Redistributions in binary form must reproduce the above copyright
1217680Spst#    notice, this list of conditions and the following disclaimer in the
1317680Spst#    documentation and/or other materials provided with the distribution.
1417680Spst#
1517680Spst# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1617680Spst# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
1717680Spst# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1817680Spst# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1917680Spst# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2017680Spst# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2117680Spst# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2217680Spst# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2317680Spst# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2417680Spst# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25127668Sbms# SUCH DAMAGE.
26214478Srpaulo#
2717680Spst# $FreeBSD: head/usr.sbin/bsdconfig/mouse/port 238438 2012-07-14 03:16:57Z dteske $
2817680Spst#
2956893Sfenner############################################################ INCLUDES
3056893Sfenner
3156893SfennerBSDCFG_LIBE="/usr/libexec/bsdconfig"
3256893Sfenner. $BSDCFG_LIBE/include/common.subr || exit 1
33127668Sbmsf_include $BSDCFG_LIBE/include/dialog.subr
3417680Spstf_include $BSDCFG_LIBE/include/mustberoot.subr
3539297Sfennerf_include $BSDCFG_LIBE/include/sysrc.subr
3639297Sfenner
3739297SfennerAPP_DIR="110.mouse"
3817680Spstf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
3917680Spst
4017680Spstipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
4117680Spst[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
4217680Spst
4317680Spst############################################################ FUNCTIONS
44127668Sbms
45172683Smlaier# dialog_menu_main
4617680Spst#
4717680Spst# Display the dialog(1)-based application main menu.
4817680Spst#
4917680Spstdialog_menu_main()
5017680Spst{
5117680Spst	local menu_list size
5217680Spst	local hline=""
53190207Srpaulo	local prompt="$msg_port_menu_text"
54172683Smlaier
5517680Spst	menu_list="
5617680Spst		'1 $msg_ps2'      '$msg_ps2_desc'
5717680Spst		'2 $msg_com1'     '$msg_com1_desc'
5817680Spst		'3 $msg_com2'     '$msg_com2_desc'
5917680Spst		'4 $msg_com3'     '$msg_com3_desc'
6017680Spst		'5 $msg_com4'     '$msg_com4_desc'
6117680Spst		'6 $msg_busmouse' '$msg_busmouse_desc'
6217680Spst	" # END-QUOTE
6317680Spst
6417680Spst	size=$( eval f_dialog_menu_size \
6517680Spst	        	\"\$DIALOG_TITLE\"     \
6617680Spst	        	\"\$DIALOG_BACKTITLE\" \
6717680Spst	                \"\$prompt\"           \
6817680Spst	        	\"\$hline\"            \
6917680Spst	        	$menu_list             )
7017680Spst
7117680Spst	eval $DIALOG \
7217680Spst		--clear --title \"\$DIALOG_TITLE\" \
7317680Spst		--backtitle \"\$DIALOG_BACKTITLE\" \
7417680Spst		--hline \"\$hline\"                \
7517680Spst		--ok-label \"\$msg_ok\"            \
7617680Spst		--cancel-label \"\$msg_cancel\"    \
7717680Spst		--menu \"\$prompt\" $size          \
7817680Spst		$menu_list                         \
7917680Spst		2> "$DIALOG_TMPDIR/dialog.menu.$$"
8017680Spst}
8117680Spst
8217680Spst############################################################ MAIN
8317680Spst
8417680Spst# Incorporate rc-file if it exists
8517680Spst[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
8617680Spst
8717680Spst#
8817680Spst# Process command-line arguments
8917680Spst#
90127668Sbmswhile getopts hSX flag; do
9117680Spst	case "$flag" in
9217680Spst	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
9317680Spst	esac
9417680Spstdone
9517680Spstshift $(( $OPTIND - 1 ))
9617680Spst
9717680Spst#
9817680Spst# Initialize
9917680Spst#
10017680Spstf_dialog_init
101172683Smlaierf_dialog_title "$msg_select_your_mouse_port_from_the_following_menu"
10217680Spstf_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
103172683Smlaierf_mustberoot_init
104172683Smlaier
105172683Smlaier#
106172683Smlaier# Launch application main menu
10717680Spst#
108172683Smlaierwhile :; do
109172683Smlaier	dialog_menu_main
110127668Sbms	retval=$?
111172683Smlaier	mtag=$( f_dialog_menutag )
112127668Sbms
113127668Sbms	[ $retval -eq 0 ] || f_die
114127668Sbms
115127668Sbms	case "$mtag" in
116127668Sbms	"1 $msg_ps2") # PS/2 style mouse (/dev/psm0)
117127668Sbms		f_sysrc_set moused_port "/dev/psm0" || f_die
118127668Sbms		break ;;
119127668Sbms	"2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0)
120127668Sbms		f_sysrc_set moused_port "/dev/cuau0" || f_die
121127668Sbms		break ;;
12217680Spst	"3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1)
12317680Spst		f_sysrc_set moused_port "/dev/cuau1" || f_die
12417680Spst		break ;;
12517680Spst	"4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2)
12617680Spst		f_sysrc_set moused_port "/dev/cuau2" || f_die
12717680Spst		break ;;
12817680Spst	"5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3)
129127668Sbms		f_sysrc_set moused_port "/dev/cuau3" || f_die
13017680Spst		break ;;
13117680Spst	"6 $msg_busmouse") # Logitech, ATI or MS bus mouse (/dev/mse0)
132190207Srpaulo		f_sysrc_set moused_port "/dev/mse0" || f_die
13317680Spst		break ;;
13417680Spst	esac
135172683Smlaier
136127668Sbmsdone
13717680Spst
13817680Spstexit $SUCCESS
13917680Spst
14017680Spst################################################################################
14117680Spst# END
14217680Spst################################################################################
14317680Spst