Guest User

bash script to control amazon fireTV

a guest
Sep 3rd, 2016
648
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash -e
  2.  
  3. #script by wolf on 3.9.2016
  4.  
  5.  
  6. #-config--------------------------------------
  7. ip="192.168.1.26"
  8.  
  9.  
  10.  
  11. #-constants-----------------------------------
  12. cmd_command=(w x a d . b h m p n)
  13. cmd_help=(w x a d . b h m p n SPACE ENTER ESC)
  14. cmd_value=(19 20 21 22 26 4 3 1 88 87)
  15. cmd_name=(up down left right power back home menu previous next play/pause enter exit)
  16.  
  17.  
  18.  
  19.  
  20. #-help------------------------------------------
  21. for ((i=0;i<${#cmd_name[*]};i++))
  22.   do
  23. echo ${cmd_help[i]} = "${cmd_name[i]}"
  24. done
  25.  
  26.  
  27.  
  28. #-connect to firetv----------------------------
  29. echo "starting server... please wait..."
  30. msg=`adb start-server`
  31. echo "$msg"
  32. msg=`adb connect $ip`
  33. echo "$msg"
  34.  
  35. exit_flag=0
  36.  
  37. #-handle user input----------------------------
  38. while [ $exit_flag = 0 ]
  39.   do
  40. #use IFS variable to recognize SPACES with read command
  41. IFS= read -n 1 -s command
  42.  
  43.  
  44. unset msg
  45.  
  46.  
  47. for ((i=0;i<${#cmd_value[*]};i++))
  48.   do
  49.  
  50. if [[ $command = ${cmd_command[$i]} ]]
  51.   then
  52.     msg=`adb shell input keyevent ${cmd_value[$i]}`
  53. fi
  54.  
  55. done    #for
  56.  
  57.  
  58. case "$command" in
  59.          $'\E') echo "exiting..."
  60.          exit_flag=1
  61.             ;;
  62.          "") msg=`adb shell input keyevent 66`
  63.             ;;
  64.          " ") msg=`adb shell input keyevent 85`
  65.             ;;
  66. esac
  67.  
  68.  
  69. done    #while
  70.  
  71.  
  72.  
  73. #-exit gracefully-----------------------
  74.  
  75. msg=`adb disconnect $ip`
  76. echo $msg
  77. msg=`adb kill-server`
  78. echo $msg
  79.  
  80. exit 0
RAW Paste Data