enable revision 256281
1210284Sjmallett#!/bin/sh 2232812Sjmallett#- 3215990Sjmallett# Copyright (c) 2012-2013 Devin Teske 4210284Sjmallett# All rights reserved. 5210284Sjmallett# 6215990Sjmallett# Redistribution and use in source and binary forms, with or without 7215990Sjmallett# modification, are permitted provided that the following conditions 8215990Sjmallett# are met: 9210284Sjmallett# 1. Redistributions of source code must retain the above copyright 10215990Sjmallett# notice, this list of conditions and the following disclaimer. 11215990Sjmallett# 2. Redistributions in binary form must reproduce the above copyright 12210284Sjmallett# notice, this list of conditions and the following disclaimer in the 13215990Sjmallett# documentation and/or other materials provided with the distribution. 14215990Sjmallett# 15215990Sjmallett# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16215990Sjmallett# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17210284Sjmallett# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18232812Sjmallett# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19215990Sjmallett# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20215990Sjmallett# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21215990Sjmallett# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22210284Sjmallett# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23215990Sjmallett# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24215990Sjmallett# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25215990Sjmallett# SUCH DAMAGE. 26215990Sjmallett# 27210284Sjmallett# $FreeBSD: stable/10/usr.sbin/bsdconfig/mouse/enable 256181 2013-10-09 08:12:26Z dteske $ 28215990Sjmallett# 29232812Sjmallett############################################################ INCLUDES 30215990Sjmallett 31215990SjmallettBSDCFG_SHARE="/usr/share/bsdconfig" 32215990Sjmallett. $BSDCFG_SHARE/common.subr || exit 1 33215990Sjmallettf_dprintf "%s: loading includes..." "$0" 34215990Sjmallettf_include $BSDCFG_SHARE/dialog.subr 35215990Sjmallettf_include $BSDCFG_SHARE/mustberoot.subr 36215990Sjmallettf_include $BSDCFG_SHARE/sysrc.subr 37215990Sjmallett 38215990SjmallettBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="110.mouse" 39210284Sjmallettf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 40210284Sjmallett 41210284Sjmallettipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 42210284Sjmallett[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 43210284Sjmallett 44210284Sjmallett############################################################ CONFIGURATION 45210284Sjmallett 46232812Sjmallett# 47210284Sjmallett# Location of moused(8) pidfile 48210284Sjmallett# 49210284SjmallettMOUSED_PIDFILE=/var/run/moused.pid 50210284Sjmallett 51210284Sjmallett############################################################ MAIN 52210284Sjmallett 53215990Sjmallett# Incorporate rc-file if it exists 54215990Sjmallett[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 55215990Sjmallett 56215990Sjmallett# 57215990Sjmallett# Process command-line arguments 58215990Sjmallett# 59210284Sjmallettwhile getopts h$GETOPTS_STDARGS flag; do 60210284Sjmallett case "$flag" in 61210284Sjmallett h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;; 62210284Sjmallett esac 63210284Sjmallettdone 64210284Sjmallettshift $(( $OPTIND - 1 )) 65210284Sjmallett 66210284Sjmallett# 67210284Sjmallett# Initialize 68210284Sjmallett# 69210284Sjmallettf_dialog_title "$msg_mouse_enable" 70210284Sjmallettf_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 71210284Sjmallettf_mustberoot_init 72210284Sjmallett 73210284Sjmallett# 74210284Sjmallett# Get the type, port, and flags 75210284Sjmallett# 76210284Sjmalletttype=$( f_sysrc_get moused_type ) 77210284Sjmallettcase "$type" in 78210284Sjmallett[Nn][Oo]|"") f_die 1 "$msg_please_select_protocol_and_port_first" ;; 79210284Sjmallettesac 80210284Sjmallettport=$( f_sysrc_get moused_port ) 81210284Sjmallett[ "$port" ] || f_die 1 "$msg_please_select_protocol_and_port_first" 82210284Sjmallettflags=$( f_sysrc_get moused_flags ) 83210284Sjmallett 84210284Sjmallett# 85210284Sjmallett# Start the mouse daemon 86210284Sjmallett# 87210284Sjmallettf_dialog_info "$msg_trying_to_start_the_mouse_daemon" 88210284Sjmallett[ -r "$MOUSED_PIDFILE" ] && 89210284Sjmallett f_quietly kill "$( cat "$MOUSED_PIDFILE" 2> /dev/null )" 90210284Sjmallettf_quietly vidcontrol -m on 91210284Sjmallettf_quietly moused -t "$type" -p "$port" $flags 92210284Sjmallett 93210284Sjmallett# 94210284Sjmallett# Confirm with the user that the mouse is working 95210284Sjmallett# 96210284Sjmallettf_dialog_title "$msg_user_confirmation_requested" 97210284Sjmallettf_dialog_yesno "$msg_now_move_the_mouse" 98215990Sjmallettretval=$? 99210284Sjmallettf_dialog_title_restore 100210284Sjmallett 101210284Sjmallett# 102210284Sjmallett# Stop the mouse daemon 103210284Sjmallett# 104210284Sjmallettf_quietly vidcontrol -m off 105210284Sjmallettif [ $retval -eq $DIALOG_OK ]; then 106210284Sjmallett f_sysrc_set moused_enable "YES" || f_die 107210284Sjmallett ln -fs /dev/sysmouse /dev/mouse || f_die # backwards compat 108210284Sjmallettelse 109210284Sjmallett [ -r "$MOUSED_PIDFILE" ] && 110210284Sjmallett f_quietly kill "$( cat "$MOUSED_PIDFILE" )" 111210284Sjmallett f_sysrc_set moused_enable "NO" || f_die 112210284Sjmallettfi 113210284Sjmallett 114210284Sjmallettexit $SUCCESS 115210284Sjmallett 116210284Sjmallett################################################################################ 117210284Sjmallett# END 118210284Sjmallett################################################################################ 119210284Sjmallett