enable revision 238438
1219820Sjeff#!/bin/sh 2219820Sjeff#- 3219820Sjeff# Copyright (c) 2012 Devin Teske 4219820Sjeff# All Rights Reserved. 5219820Sjeff# 6219820Sjeff# Redistribution and use in source and binary forms, with or without 7219820Sjeff# modification, are permitted provided that the following conditions 8219820Sjeff# are met: 9219820Sjeff# 1. Redistributions of source code must retain the above copyright 10219820Sjeff# notice, this list of conditions and the following disclaimer. 11219820Sjeff# 2. Redistributions in binary form must reproduce the above copyright 12219820Sjeff# notice, this list of conditions and the following disclaimer in the 13219820Sjeff# documentation and/or other materials provided with the distribution. 14219820Sjeff# 15219820Sjeff# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16219820Sjeff# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17219820Sjeff# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18219820Sjeff# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19219820Sjeff# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20219820Sjeff# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21219820Sjeff# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22219820Sjeff# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23219820Sjeff# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24219820Sjeff# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25219820Sjeff# SUCH DAMAGE. 26219820Sjeff# 27219820Sjeff# $FreeBSD: head/usr.sbin/bsdconfig/mouse/enable 238438 2012-07-14 03:16:57Z dteske $ 28219820Sjeff# 29219820Sjeff############################################################ INCLUDES 30219820Sjeff 31219820SjeffBSDCFG_LIBE="/usr/libexec/bsdconfig" 32219820Sjeff. $BSDCFG_LIBE/include/common.subr || exit 1 33219820Sjefff_include $BSDCFG_LIBE/include/dialog.subr 34219820Sjefff_include $BSDCFG_LIBE/include/mustberoot.subr 35219820Sjefff_include $BSDCFG_LIBE/include/sysrc.subr 36219820Sjeff 37219820SjeffAPP_DIR="110.mouse" 38219820Sjefff_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 39219820Sjeff 40219820Sjeffipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 41219820Sjeff[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 42219820Sjeff 43219820Sjeff############################################################ CONFIGURATION 44219820Sjeff 45219820Sjeff# 46219820Sjeff# Location of moused(8) pidfile 47219820Sjeff# 48219820SjeffMOUSED_PIDFILE=/var/run/moused.pid 49219820Sjeff 50219820Sjeff############################################################ MAIN 51219820Sjeff 52219820Sjeff# Incorporate rc-file if it exists 53219820Sjeff[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 54219820Sjeff 55219820Sjeff# 56219820Sjeff# Process command-line arguments 57219820Sjeff# 58219820Sjeffwhile getopts hSX flag; do 59219820Sjeff case "$flag" in 60219820Sjeff h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 61219820Sjeff esac 62219820Sjeffdone 63219820Sjeffshift $(( $OPTIND - 1 )) 64219820Sjeff 65219820Sjeff# 66219820Sjeff# Initialize 67219820Sjeff# 68219820Sjefff_dialog_init 69219820Sjefff_dialog_title "$msg_mouse_enable" 70219820Sjefff_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 71219820Sjefff_mustberoot_init 72219820Sjeff 73219820Sjeff# 74219820Sjeff# Get the type, port, and flags 75219820Sjeff# 76219820Sjefftype=$( f_sysrc_get moused_type ) 77219820Sjeffcase "$type" in 78219820Sjeff[Nn][Oo]|"") f_die 1 "$msg_please_select_protocol_and_port_first" ;; 79219820Sjeffesac 80219820Sjeffport=$( f_sysrc_get moused_port ) 81219820Sjeff[ "$port" ] || f_die 1 "$msg_please_select_protocol_and_port_first" 82219820Sjeffflags=$( f_sysrc_get moused_flags ) 83219820Sjeff 84219820Sjeff# 85219820Sjeff# Start the mouse daemon 86219820Sjeff# 87219820Sjefff_dialog_info "$msg_trying_to_start_the_mouse_daemon" 88219820Sjeff[ -r "$MOUSED_PIDFILE" ] && 89219820Sjeff f_quietly kill "$( cat "$MOUSED_PIDFILE" 2> /dev/null )" 90219820Sjefff_quietly vidcontrol -m on 91219820Sjefff_quietly moused -t "$type" -p "$port" $flags 92219820Sjeff 93219820Sjeff# 94219820Sjeff# Confirm with the user that the mouse is working 95219820Sjeff# 96219820Sjefff_dialog_title "$msg_user_confirmation_requested" 97219820Sjefff_dialog_yesno "$msg_now_move_the_mouse" 98219820Sjeffretval=$? 99219820Sjefff_dialog_title_restore 100219820Sjeff 101219820Sjeff# 102219820Sjeff# Stop the mouse daemon 103219820Sjeff# 104219820Sjefff_quietly vidcontrol -m off 105219820Sjeffif [ $retval -eq $SUCCESS ]; then 106219820Sjeff f_sysrc_set moused_enable "YES" || f_die 107219820Sjeff ln -fs /dev/sysmouse /dev/mouse || f_die # backwards compat 108219820Sjeffelse 109219820Sjeff [ -r "$MOUSED_PIDFILE" ] && 110219820Sjeff f_quietly kill "$( cat "$MOUSED_PIDFILE" )" 111219820Sjeff f_sysrc_set moused_enable "NO" || f_die 112219820Sjefffi 113219820Sjeff 114219820Sjeffexit $SUCCESS 115219820Sjeff 116219820Sjeff################################################################################ 117219820Sjeff# END 118219820Sjeff################################################################################ 119219820Sjeff