3 # A mouse configuration tool for gpm(8)
5 # Copyright (c) 2018-2019 Matias Fonzo, <selk@dragora.org>.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # Exit immediately on any error
23 TMPDIR
="${TMPDIR:-$HOME}"
24 TMPFILE
="${TMPDIR}/.${PROGRAM}.${RANDOM-0}$$"
25 LOCKFILE
=/tmp
/dragora-mouse.lockfile
31 # Clean up temporary files
32 rm -f -- "$TMPFILE" "$LOCKFILE"
36 printf "%s\n" "" "Return status = $status" 1>&2
45 if test ! -d "$TMPDIR"
47 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
50 if test ! -w "$TMPDIR"
52 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
56 trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
58 umask 077; # Remove access for all but user.
60 # Unfortunately, gpm(8) is limited to the superuser;
61 # we set a lock to allow only one instance of the script.
63 if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev
/null
67 if test -e "$LOCKFILE"
69 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
72 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
78 --backtitle "\Zb${PROGRAM} - Mouse Configuration" \
79 --title "MAIN MENU" --menu \
80 "Welcome to \Z3${PROGRAM}\Zn!\n\
81 A configuration tool for the mouse selection.\n\n\
82 The following list is ordered by mouse type and brief description.\n\
83 \Zbp\Zns2 is the most common model for laptops. Otherwise, you can\n\
84 select the \Zbu\Znsb model from the list below.\n\n\
85 Select a mouse type:" 20 71 6 \
86 "ps2" "Common protocol for PS2 mice" \
87 "usb" "Common protocol for USB mice" \
88 "bare" "Microsoft compatible, 2 buttons" \
89 "exps2" "IntelliMouse Explorer, 3 buttons" \
90 "imps2" "Microsoft Intellimouse, 2 or 3 buttons" \
91 "js" "Mouse emulation with a Joystick" \
92 "logi" "Logitech devices" \
93 "logim" "Logitech into Mouse-Systems compatible" \
94 "mman" "The MouseMan and similar devices" \
95 "ms" "Microsoft-compatible, 3 buttons" \
96 "ms3" "Microsoft Intellimouse, 3 buttons" \
97 "msc" "Mouse-Systems compatible, most 3-button mice" \
98 "ncr" "Ncr3125pen found on some laptops" \
99 "netmouse" "Genius NetMouse, 4 buttons" \
100 "pnp" "Plug and Play mice, does not work with 'ms'" \
101 "twid" "Twidddler keyboard" \
102 "acecad" "Acecad tablet, in absolute mode" \
103 "genitizer" "Genitizer tablet, in relative mode" \
104 "wacom" "Wacom Protocol IV tablets" \
105 "wp" "Genius WizardPad tablet" \
108 # Read answer from 'TMPFILE'
110 echo "" >> $TMPFILE; # Append new line for reading.
111 IFS
= read -r REPLY
< $TMPFILE ||
exit 2;
113 # Check cases to determine the corresponding device name
116 ps2 | imps2 | exps2 | ncr | netmouse
)
123 acecad | bare | genitizer | logi
* | twid | wacom | mman | ms
* | pnp | wp
)
125 --backtitle "\Zb${PROGRAM} - Serial Port" \
126 --title "MOUSE DEVICE" \
128 "The protocol \Zb\Z1${REPLY}\Zn requires a serial port.\n\n\
129 Which device name would you like to use?" 13 52 4 \
130 "ttyS0" "Serial port 0, COM1 under DOS" \
131 "ttyS1" "Serial port 1, COM2 under DOS" \
132 "ttyS2" "Serial port 2, COM3 under DOS" \
133 "ttyS3" "Serial port 3, COM4 under DOS" \
135 echo "" >> $TMPFILE; # Append new line for reading.
136 IFS
= read -r DEVICE
< $TMPFILE ||
exit 2;
143 # The temporary file is not needed anymore
146 umask 022; # Remove write permission for group and other.
150 "# Stop/Start gpm(8) the mouse server." \
151 "# Automatically generated by dragora-mouse(8)." \
153 "if pidof gpm > /dev/null" \
155 " echo \"Stopping running gpm instance: gpm -k\"" \
158 " echo \"Sending the TERM signal to gpm\"" \
159 " killall -TERM gpm" \
164 "echo \"(Startup) Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY\"" \
165 "gpm -m /dev/${DEVICE} -t $REPLY" \
167 > /etc
/rc.d
/rc.gpm-sample
168 chmod 755 /etc
/rc.d
/rc.gpm-sample
171 --backtitle "\Zb${PROGRAM} - Startup File" \
172 --title "RUN CONTROL" --yesno \
173 "A run control file could be created to load your settings\n\
174 at boot time. The file will be saved as \Z1/etc/rc.d/rc.gpm\Zn\n\n\
175 Would you like to load this file at boot time?" 8 63 && \
176 mv -f -- /etc
/rc.d
/rc.gpm-sample
/etc
/rc.d
/rc.gpm
179 --backtitle "\Zb${PROGRAM} - Mouse Session" \
180 --title "MOUSE SESSION" --yesno \
181 "\ZbGPM\Zn is a cut and paste utility and mouse server for \
182 virtual consoles. It is useful to avoid typing everything by \
184 Would you like to run it now?" 9 58 &&
187 echo "Stopping any running gpm instance"
188 gpm
-k 2> /dev
/null || killall gpm
2> /dev
/null || true
;
192 echo "Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY"
193 gpm
-m /dev
/${DEVICE} -t $REPLY
194 } ||
{ printf "%s\n" "" "Okay!" ; exit 1 ; }