daily pastebin goal
22%
SHARE
TWEET

Karl's bluetooth script to reconnect mouse

a guest Aug 18th, 2012 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. me_call="$0"
  4. me_link=`readlink -e "$0"`
  5. me_base_name_call="${me_call##*/}"
  6. me_base_name_link="${me_link##*/}"
  7.  
  8. usage(){
  9. MSG="
  10. $me_base_name_link [help] [start|stop]
  11. daemon script to keep autoconnection for hidd running
  12. if bt mouse disconnects out  of the blue
  13. "
  14. [ "$2" ] && MSG="$MSG
  15. $2"
  16. exit $1
  17. }
  18. [[ "$1" =~ 'help' ]] && usage 0
  19. [[ "$1" =~ '-h' ]] && usage 0
  20.  
  21. [ "`lsmod | grep bluetooth`" ] || { echo "Bluetooth driver probably not loaded.";exit 900; }
  22.  
  23. hciconfig -a | grep 'UP RUNNING' || hciconfig hci0 up
  24. [ $? = 0 ] || exit 899
  25.  
  26. function exit_function(){
  27. exit $?
  28. }
  29. TRAP_SIGNALS=`trap -l|sed 's|\([0-9]*)\)||g;s|SIG||g;s|\t||g' |tr -s ' '`
  30. TRAP_SIGNALS=`echo $TRAP_SIGNALS`
  31. #trap "exit $?" HUP INT QUIT ILL TRAP ABRT BUS FPEKILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS RTMIN .. .. RTMIN+1 RTMIN+2 RTMIN+3 RTMIN+4 RTMIN+5 RTMIN+6 RTMIN+7 RTMIN+8 RTMIN+9 RTMIN+10 RTMIN+11 RTMIN+12 RTMIN+13 RTMIN+14 RTMIN+15 RTMAX-14 RTMAX-13 RTMAX-12 RTMAX-11 RTMAX-10 RTMAX-9 RTMAX-8 RTMAX-7 RTMAX-6 RTMAX-5 RTMAX-4 RTMAX-3 RTMAX-2 RTMAX-1 RTMAX
  32. trap "exit_function" $TRAP_SIGNALS
  33.  
  34. function connect_bt(){
  35. hidd -i hci0 --search
  36. }
  37.  
  38. case $1 in
  39. stop)
  40. ps -C hidd && kill -1 `pidof hidd`
  41. ;;
  42. start|*|'')
  43. while [ running ];do
  44. hcitool con |sed '1 d' |cut -f2- -d:
  45. if test "`hcitool con |sed '1 d' |cut -f2- -d:`" = "" ;then
  46. #aplay /usr/share/audio/2barks.au
  47. aplay /usr/share/audio/leave.wav #same as /usr/share/audio/logout.wav
  48. connect_bt
  49. sleep 2s
  50.  if test "`hcitool con |sed '1 d' |cut -f2- -d:`" != "" ;then
  51.   #/usr/share/audio/join.wav sounding like cat's "Meeow"
  52.   aplay /usr/share/audio/bark.au
  53.  fi
  54. fi
  55. sleep 3s
  56. done
  57. ;;
  58. esac
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top