1238438Sdteske#!/bin/sh 2238438Sdteske#- 3249746Sdteske# Copyright (c) 2012-2013 Devin Teske 4252980Sdteske# All rights reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD: releng/11.0/usr.sbin/bsdconfig/mouse/enable 259054 2013-12-07 00:31:01Z dteske $ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33244675Sdteskef_dprintf "%s: loading includes..." "$0" 34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr 36240684Sdteskef_include $BSDCFG_SHARE/sysrc.subr 37238438Sdteske 38240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse" 39238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40238438Sdteske 41259054Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm && 42259054Sdteske pgm="${ipgm:-$pgm}" 43238438Sdteske 44238438Sdteske############################################################ CONFIGURATION 45238438Sdteske 46238438Sdteske# 47238438Sdteske# Location of moused(8) pidfile 48238438Sdteske# 49238438SdteskeMOUSED_PIDFILE=/var/run/moused.pid 50238438Sdteske 51238438Sdteske############################################################ MAIN 52238438Sdteske 53238438Sdteske# Incorporate rc-file if it exists 54238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 55238438Sdteske 56238438Sdteske# 57238438Sdteske# Process command-line arguments 58238438Sdteske# 59250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do 60238438Sdteske case "$flag" in 61252178Sdteske h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 62238438Sdteske esac 63238438Sdteskedone 64238438Sdteskeshift $(( $OPTIND - 1 )) 65238438Sdteske 66238438Sdteske# 67238438Sdteske# Initialize 68238438Sdteske# 69238438Sdteskef_dialog_title "$msg_mouse_enable" 70238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 71238438Sdteskef_mustberoot_init 72238438Sdteske 73238438Sdteske# 74238438Sdteske# Get the type, port, and flags 75238438Sdteske# 76238438Sdtesketype=$( f_sysrc_get moused_type ) 77238438Sdteskecase "$type" in 78238438Sdteske[Nn][Oo]|"") f_die 1 "$msg_please_select_protocol_and_port_first" ;; 79238438Sdteskeesac 80238438Sdteskeport=$( f_sysrc_get moused_port ) 81238438Sdteske[ "$port" ] || f_die 1 "$msg_please_select_protocol_and_port_first" 82238438Sdteskeflags=$( f_sysrc_get moused_flags ) 83238438Sdteske 84238438Sdteske# 85238438Sdteske# Start the mouse daemon 86238438Sdteske# 87238438Sdteskef_dialog_info "$msg_trying_to_start_the_mouse_daemon" 88259054Sdteskeif [ -r "$MOUSED_PIDFILE" ]; then 89259054Sdteske f_eval_catch -dk pid "$0" cat 'cat "%s"' "$MOUSED_PIDFILE" && 90259054Sdteske f_isinteger "$pid" && 91259054Sdteske [ $pid -gt 0 ] && 92259054Sdteske f_eval_catch -d "$0" kill 'kill %s' $pid 93259054Sdteskefi 94259054Sdteskef_eval_catch -d "$0" vidcontrol 'vidcontrol -m on' 95259054Sdteskef_eval_catch -d "$0" moused \ 96259054Sdteske 'moused -t "%s" -p "%s" %s' "$type" "$port" "$flags" 97238438Sdteske 98238438Sdteske# 99238438Sdteske# Confirm with the user that the mouse is working 100238438Sdteske# 101238438Sdteskef_dialog_title "$msg_user_confirmation_requested" 102238438Sdteskef_dialog_yesno "$msg_now_move_the_mouse" 103238438Sdteskeretval=$? 104238438Sdteskef_dialog_title_restore 105238438Sdteske 106238438Sdteske# 107238438Sdteske# Stop the mouse daemon 108238438Sdteske# 109259054Sdteskef_eval_catch -d "$0" vidcontrol 'vidcontrol -m off' 110256181Sdteskeif [ $retval -eq $DIALOG_OK ]; then 111259054Sdteske f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_enable YES' || f_die 112259054Sdteske f_eval_catch "$0" ln \ 113259054Sdteske 'ln -fs /dev/sysmouse /dev/mouse' || f_die # backwards compat 114238438Sdteskeelse 115259054Sdteske if [ -r "$MOUSED_PIDFILE" ]; then 116259054Sdteske f_eval_catch -dk pid "$0" cat 'cat "%s"' "$MOUSED_PIDFILE" && 117259054Sdteske f_isinteger "$pid" && 118259054Sdteske [ $pid -gt 0 ] && 119259054Sdteske f_eval_catch -d "$0" kill 'kill %s' $pid 120259054Sdteske fi 121259054Sdteske f_eval_catch "$0" f_sysrc_set 'f_sysrc_set moused_enable NO' || f_die 122238438Sdteskefi 123238438Sdteske 124238438Sdteskeexit $SUCCESS 125238438Sdteske 126238438Sdteske################################################################################ 127238438Sdteske# END 128238438Sdteske################################################################################ 129