dragora-mouse 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #! /bin/sh -
  2. #
  3. # A mouse configuration tool for gpm(8)
  4. #
  5. # Copyright (c) 2018-2021 Matias Fonzo, <selk@dragora.org>.
  6. #
  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
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  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.
  18. # Exit immediately on any error
  19. set -e
  20. PROGRAM="${0##*/}"
  21. TMPDIR="${TMPDIR:-$HOME}"
  22. TMPFILE="${TMPDIR}/.${PROGRAM}.${RANDOM-0}$$"
  23. LOCKFILE=/var/lock/dragora-mouse.lockfile
  24. chkstatus_or_exit()
  25. {
  26. status=$?
  27. # Clean up temporary files
  28. rm -f -- "$TMPFILE" "$LOCKFILE"
  29. if test $status -ne 0
  30. then
  31. printf '%s\n' "" "Return status = $status" 1>&2
  32. exit 2;
  33. fi
  34. unset -v status
  35. }
  36. # Sanity checks
  37. if test ! -d "$TMPDIR"
  38. then
  39. echo "${PROGRAM}: \`${TMPDIR}' is not a qualified temporary directory" 1>&2
  40. exit 1;
  41. fi
  42. if test ! -w "$TMPDIR"
  43. then
  44. echo "${PROGRAM}: \`${TMPDIR}' is not a writable temporary directory" 1>&2
  45. exit 1;
  46. fi
  47. trap 'chkstatus_or_exit' EXIT HUP INT QUIT ABRT TERM
  48. umask 077; # Remove access for all but user.
  49. # Unfortunately, gpm(8) is limited to the superuser;
  50. # we set a lock to allow only one instance of the script.
  51. if ( set -C ; echo ": $PROGRAM - locked" > $LOCKFILE ) 2> /dev/null
  52. then
  53. true
  54. else
  55. if test -e "$LOCKFILE"
  56. then
  57. echo "Only one instance of \`${PROGRAM}' is allowed." 1>&2
  58. exit 1;
  59. else
  60. echo "${PROGRAM}: \`${LOCKFILE}' lock failed." 1>&2
  61. exit 2;
  62. fi
  63. fi
  64. dialog --colors \
  65. --backtitle "\\Zb${PROGRAM} - Mouse Configuration" \
  66. --title "MAIN MENU" --menu \
  67. "Welcome to \\Z3${PROGRAM}\\Zn!\\n\
  68. A configuration tool for the mouse selection.\\n\\n\
  69. The following list is ordered by mouse type and brief description.\\n\
  70. \\Zbp\\Zns2 is the most common model for laptops. Otherwise, you can\\n\
  71. select the \\Zbu\\Znsb model from the list below.\\n\\n\
  72. Select a mouse type:" 20 71 6 \
  73. "ps2" "Common protocol for PS2 mice" \
  74. "usb" "Common protocol for USB mice" \
  75. "bare" "Microsoft compatible, 2 buttons" \
  76. "exps2" "IntelliMouse Explorer, 3 buttons" \
  77. "imps2" "Microsoft Intellimouse, 2 or 3 buttons" \
  78. "js" "Mouse emulation with a Joystick" \
  79. "logi" "Logitech devices" \
  80. "logim" "Logitech into Mouse-Systems compatible" \
  81. "mman" "The MouseMan and similar devices" \
  82. "ms" "Microsoft-compatible, 3 buttons" \
  83. "ms3" "Microsoft Intellimouse, 3 buttons" \
  84. "msc" "Mouse-Systems compatible, most 3-button mice" \
  85. "ncr" "Ncr3125pen found on some laptops" \
  86. "netmouse" "Genius NetMouse, 4 buttons" \
  87. "pnp" "Plug and Play mice, does not work with 'ms'" \
  88. "twid" "Twidddler keyboard" \
  89. "acecad" "Acecad tablet, in absolute mode" \
  90. "genitizer" "Genitizer tablet, in relative mode" \
  91. "wacom" "Wacom Protocol IV tablets" \
  92. "wp" "Genius WizardPad tablet" \
  93. 2> "$TMPFILE"
  94. # Read answer from 'TMPFILE'
  95. echo "" >> "$TMPFILE"; # Append new line for reading.
  96. IFS= read -r REPLY < "$TMPFILE" || exit 2;
  97. # Check cases to determine the corresponding device name
  98. case $REPLY in
  99. ps2 | imps2 | exps2 | ncr | netmouse)
  100. DEVICE=psaux
  101. ;;
  102. usb)
  103. REPLY=imps2
  104. DEVICE=input/mice
  105. ;;
  106. acecad | bare | genitizer | logi* | twid | wacom | mman | ms* | pnp | wp)
  107. dialog --colors \
  108. --backtitle "\\Zb${PROGRAM} - Serial Port" \
  109. --title "MOUSE DEVICE" \
  110. --no-cancel --menu \
  111. "The protocol \\Zb\\Z1${REPLY}\\Zn requires a serial port.\\n\\n\
  112. Which device name would you like to use?" 13 52 4 \
  113. "ttyS0" "Serial port 0, COM1 under DOS" \
  114. "ttyS1" "Serial port 1, COM2 under DOS" \
  115. "ttyS2" "Serial port 2, COM3 under DOS" \
  116. "ttyS3" "Serial port 3, COM4 under DOS" \
  117. 2> "$TMPFILE"
  118. echo "" >> "$TMPFILE"; # Append new line for reading.
  119. IFS= read -r DEVICE < "$TMPFILE" || exit 2;
  120. ;;
  121. js)
  122. DEVICE=js0
  123. ;;
  124. esac
  125. # Temporary file is not needed anymore
  126. rm -f -- "$TMPFILE"
  127. umask 022; # Remove write permission for group and other.
  128. printf '%s\n' \
  129. "#! /bin/sh -" \
  130. "# Stop/Start gpm(8) the mouse server." \
  131. "# Automatically generated by dragora-mouse(8)." \
  132. "" \
  133. "if pidof gpm > /dev/null" \
  134. "then" \
  135. " echo \"Stopping running gpm instance: gpm -k\"" \
  136. " if ! gpm -k" \
  137. " then" \
  138. " echo \"Sending the TERM signal to gpm\"" \
  139. " killall -TERM gpm" \
  140. " fi" \
  141. " sleep 1" \
  142. "fi" \
  143. "" \
  144. "echo \"(Startup) Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY\"" \
  145. "gpm -m /dev/${DEVICE} -t $REPLY" \
  146. "" \
  147. > /etc/rc.d/rc.gpm-sample
  148. chmod 755 /etc/rc.d/rc.gpm-sample
  149. dialog --colors \
  150. --backtitle "\\Zb${PROGRAM} - Startup File" \
  151. --title "RUN CONTROL" --yesno \
  152. "A run control file could be created to load your settings\\n\
  153. at boot time. The file will be saved as \\Z1/etc/rc.d/rc.gpm\\Zn\\n\\n\
  154. Would you like to load this file at boot time?" 8 63 && \
  155. mv -f -- /etc/rc.d/rc.gpm-sample /etc/rc.d/rc.gpm
  156. dialog --colors \
  157. --backtitle "\\Zb${PROGRAM} - Mouse Session" \
  158. --title "MOUSE SESSION" --yesno \
  159. "\\ZbGPM\\Zn is a cut and paste utility and mouse server for \
  160. virtual consoles. It is useful to avoid typing everything by \
  161. hand\\Zb!\\Zn\\n\\n\
  162. Would you like to run it now?" 9 58
  163. echo ""
  164. echo "Stopping any running gpm instance"
  165. gpm -k 2> /dev/null || killall gpm 2> /dev/null || true;
  166. sleep 1
  167. echo ""
  168. echo "Starting gpm: gpm -m /dev/${DEVICE} -t $REPLY"
  169. gpm -m /dev/${DEVICE} -t $REPLY