rc.cwiid.new 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # RC script for cwiid's wminput daemon, part of the SBo cwiid package.
  3. # Where's the config file for this script? This is the only variable that can't
  4. # be overridden in the config file.
  5. RC_CONF=/etc/rc.d/rc.cwiid.conf
  6. ####
  7. # Override this stuff in $RC_CONF if you see a need to:
  8. # Default config file for wminput instances
  9. WMINPUT_DEFAULT_CONF=default
  10. # full path to wminput binary:
  11. WMINPUT_BIN=/usr/bin/wminput
  12. # probably nobody will ever need to increase this:
  13. MAX_WIIMOTES=9
  14. ####
  15. start_cwiid() {
  16. local cwiid_conf
  17. local cwiid_addr
  18. local cmd
  19. local daemons
  20. echo "Starting cwiid wminput daemon(s)..."
  21. # Guarantee the uinput module gets loaded, don't complain if not
  22. # (it may not be modular in the running kernel)
  23. /sbin/modprobe uinput &>/dev/null
  24. # WIIMOTE is a bash array, will be populated by config file or default conf
  25. unset WIIMOTE
  26. if [ -r "$RC_CONF" ]; then
  27. source $RC_CONF
  28. else
  29. echo -e "$RC_CONF missing, using defaults:\\n\\tWIIMOTE[0]='auto'\\n\\tWIIMOTE_CONF[0]='$WMINPUT_DEFAULT_CONF'" 1>&2
  30. WIIMOTE[0]=auto
  31. fi
  32. i=0
  33. daemons=0
  34. while [ $i -le $MAX_WIIMOTES ]; do
  35. if [ -n "${WIIMOTE[$i]}" ]; then
  36. cwiid_conf="${WIIMOTE_CONF[$i]:-$WMINPUT_DEFAULT_CONF}"
  37. cwiid_addr=${WIIMOTE[$i]}
  38. if [ "$cwiid_addr" = "auto" ]; then
  39. cwiid_addr=""
  40. fi
  41. cmd="$WMINPUT_BIN -d -c $cwiid_conf $cwiid_addr"
  42. echo " Starting daemon: $cmd"
  43. $cmd &
  44. daemons=$((daemons+1))
  45. fi
  46. i=$((i+1))
  47. done
  48. echo "cwiid startup done, $daemons daemons started"
  49. }
  50. stop_cwiid() {
  51. echo -n "Stopping cwiid wminput daemon(s)..."
  52. killall wminput &>/dev/null
  53. sleep 2
  54. killall -9 wminput &>/dev/null
  55. echo "done"
  56. }
  57. case "$1" in
  58. start) start_cwiid ;;
  59. stop) stop_cwiid ;;
  60. restart)
  61. stop_cwiid
  62. sleep 1
  63. start_cwiid
  64. ;;
  65. *)
  66. echo "Usage: $0 start|stop|restart" 1>&2
  67. exit 1
  68. ;;
  69. esac
  70. exit 0