recipes: tde/avahi_tqt: added pending recipe for build (requires avahi)
[dragora.git] / archive / dragora-tools / dragora-mouse
blob0276573fb07bcae92fc3ac886e38eeca2414ddcd
1 #! /bin/sh -
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
20 set -e
22 PROGRAM="${0##*/}"
23 TMPDIR="${TMPDIR:-$HOME}"
24 TMPFILE="${TMPDIR}/.${PROGRAM}.${RANDOM-0}$$"
25 LOCKFILE=/tmp/dragora-mouse.lockfile
27 chkstatus_or_exit()
29 status=$?
31 # Clean up temporary files
32 rm -f -- "$TMPFILE" "$LOCKFILE"
34 if test $status -ne 0
35 then
36 printf "%s\n" "" "Return status = $status" 1>&2
37 exit 2;
40 unset status
43 # Sanity checks
45 if test ! -d "$TMPDIR"
46 then
47 echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
48 exit 1;
50 if test ! -w "$TMPDIR"
51 then
52 echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
53 exit 1;
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
64 then
65 true
66 else
67 if test -e "$LOCKFILE"
68 then
69 echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
70 exit 1;
71 else
72 echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
73 exit 2;
77 dialog --colors \
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" \
106 2> $TMPFILE
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
115 case $REPLY in
116 ps2 | imps2 | exps2 | ncr | netmouse)
117 DEVICE=psaux
119 usb)
120 REPLY=imps2
121 DEVICE=input/mice
123 acecad | bare | genitizer | logi* | twid | wacom | mman | ms* | pnp | wp)
124 dialog --colors \
125 --backtitle "\Zb${PROGRAM} - Serial Port" \
126 --title "MOUSE DEVICE" \
127 --no-cancel --menu \
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" \
134 2> $TMPFILE
135 echo "" >> $TMPFILE; # Append new line for reading.
136 IFS= read -r DEVICE < $TMPFILE || exit 2;
139 DEVICE=js0
141 esac
143 # The temporary file is not needed anymore
144 rm -f -- "$TMPFILE"
146 umask 022; # Remove write permission for group and other.
148 printf "%s\n" \
149 "#! /bin/sh -" \
150 "# Stop/Start gpm(8) the mouse server." \
151 "# Automatically generated by dragora-mouse(8)." \
152 "" \
153 "if pidof gpm > /dev/null" \
154 "then" \
155 " echo \"Stopping running gpm instance: gpm -k\"" \
156 " if ! gpm -k" \
157 " then" \
158 " echo \"Sending the TERM signal to gpm\"" \
159 " killall -TERM gpm" \
160 " fi" \
161 " sleep 1" \
162 "fi" \
163 "" \
164 "echo \"(Startup) Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY\"" \
165 "gpm -m /dev/${DEVICE} -t $REPLY" \
166 "" \
167 > /etc/rc.d/rc.gpm-sample
168 chmod 755 /etc/rc.d/rc.gpm-sample
170 dialog --colors \
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
178 dialog --colors \
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 \
183 hand\Zb!\Zn\n\n\
184 Would you like to run it now?" 9 58 &&
186 echo ""
187 echo "Stopping any running gpm instance"
188 gpm -k 2> /dev/null || killall gpm 2> /dev/null || true;
189 sleep 1
191 echo ""
192 echo "Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY"
193 gpm -m /dev/${DEVICE} -t $REPLY
194 } || { printf "%s\n" "" "Okay!" ; exit 1 ; }