12 Commits

Author SHA1 Message Date
bradley.richins
e8dcd77065 Using a hack to get better sleep deay times
use read command insted of sleep
2021-03-21 19:19:50 -06:00
Bradley Richins
79ed3e4048 Update README.md 2020-05-19 18:01:43 +00:00
Bradley Richins
74946d1258 Added help info for scan function
added decription for -s|--scan argument usage
2020-05-18 14:51:52 -06:00
Bradley Richins
746e896b3e rokuc minor change 2020-05-18 12:41:11 -06:00
Bradley Richins
a4ad0bcb8b README.md minor change 2020-05-18 12:40:06 -06:00
Bradley Richins
8cc64d9cc0 README.md update 2020-05-18 11:57:51 -06:00
Bradley Richins
c2281de32a Updated for new function
Added new flags
   -i|--version
   -s|--scan

Added new example for -s|--scan flags
2020-05-18 03:53:56 -06:00
Bradley Richins
de2406057e Various Changes:
Added:
   Roku Search:
      function scan4dev:
         Uses nmap to scan network for Rokus ECP port (8060)
      check for nmap
      lanCIDR var for subnetmask
   function versionInfo:
      Displays version info
   vernum var for vserion number

Modified:
   function helpme:
      added version number
      added respective function flag info
      added URL gitlab repo
   Modified while loop responsible for managing flags:
      added -s|--scan
      added -i|--version
      Modified flag order (stand alone flags are now processed first)
2020-05-18 03:23:36 -06:00
Bradley Richins
e7c12c1012 Updated README.md 2020-05-16 19:45:19 -06:00
Bradley Richins
300a5c0f3e Updated README.md 2020-05-16 19:44:06 -06:00
Bradley Richins
2adec6a70d Updated README.md 2020-05-16 19:42:24 -06:00
Bradley Richins
239e918369 Merge branch 'bradley.richins-master-patch-66037' into 'master'
Update README.md

See merge request bradley.richins/rokuc!1
2020-05-17 01:40:20 +00:00
2 changed files with 134 additions and 58 deletions

View File

@@ -4,14 +4,20 @@
This bash script leverages cURL and roku's External Control Protocol ([ECP](https://developer.roku.com/docs/developer-program/debugging/external-control-api.md)), to aid in home automation.
Send simple remote commands to Roku devices using curl to interact with Rokus ECP (External Control Protocal) server on port 8060.
## Usage :
```
Usage: rokuc [[-a [ADDRESS]] [-s [IP SUBNET]]] [[-h] [-v] [-c [ARGS]] [-l [ARGS]]]
-a | --address IP address of roku device ** REQUIRED **
-c | --command Send remote commands to device
-l | --launch Launch Channel/Application on device
-v | --verbose Enable verbose mode
-h | --help Display this message
-i | --version Display version info and exit
-s | --scan Scan LAN for active Roku devices
Args for [-c|--command] flag
play | pause | | | p Pause and Play
@@ -44,6 +50,10 @@ Args for [-l|--launch] flag
hdmi4 Launch HDMI4
av1 Launch AV1
Argument for [-s|--scan [IP SUBNET]] flag
Input your LAN subnet
i.e. 192.168.11.0, 10.0.0.0, 192.168.0.0, etc...
```
### Usage Examples
@@ -68,7 +78,13 @@ $> ./rokuc -a 192.168.1.142 -c "# v- v-"
Launch plex, wait 5 seconds, move right, select:
```bash
$> /rokuc -a 192.168.11.142 -l plex -c "s5 > ."
$> ./rokuc -a 192.168.11.142 -l plex -c "s5 > ."
```
Scan network for devices
```bash
$> ./rokuc -s 192.168.0.0
```

174
rokuc
View File

@@ -4,18 +4,41 @@ if ! hash curl 2>/dev/null; then
echo "curl is not installed"
exit
fi
if ! hash nmap 2>/dev/null; then
devscan=0
else
devscan=1
fi
# Default subnet mask
lanCIDR=24
script=`basename "$0"`
vernum="1.1"
function versionInfo()
{
echo -e "rokuc (Roku CLI Remote) ${vernum}"
echo -e ''' Copyright (C) 2020 Bradley Richins II
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
'''
exit
}
function helpme()
{
echo -e "rokuc ver. ${vernum}"
echo "Send simple remote commands to Roku devices using curl to interact with Rokus ECP (External Control Protocal) server on port 8060."
echo "Usage: ${script} -a [ADDRESS] [ [-h] [-v] [-c [ARGS]] [-l [ARGS]] ]"
echo "Usage: ${script} [[-a [ADDRESS]] [-s [IP SUBNET]]] [[-h] [-v] [-c [ARGS]] [-l [ARGS]]]"
echo -e ''' -a | --address\tIP address of roku device ** REQUIRED **
-c | --command\tSend remote commands to device
-c | --command\tSend remote commands to device.
-l | --launch \tLaunch Channel/Application on device
-v | --verbose \tEnable verbose mode
-h | --help \tDisplay this message
-h | --help \tDisplay this message and exit
-i | --version\tDisplay version info and exit
-s | --scan \tScan LAN for active Roku devices
Args for [-c|--command] flag
play | pause | | | p \t Pause and Play
@@ -47,13 +70,50 @@ Args for [-l|--launch] flag
hdmi3 \t Launch HDMI3
hdmi4 \t Launch HDMI4
av1 \t Launch AV1
'''
echo -e "Examples:\nLaunch Netflix\n\t./${script} -a 192.168.11.142 -l netflix\n"
echo -e "Pause Roku \n\t./${script} -a 192.168.11.142 -c pause\n"
echo -e "Go Home & turn down volume\n\t./${script} -a 192.168.11.142 -c \"# v- v-\"\n"
echo -e "Launch plex, wait 5 seconds, move right, select \n\t./${script} -a 192.168.11.142 -l plex -c \"s5 > .\""
echo -e "ECP documentation:\n\thttps://developer.roku.com/docs/developer-program/debugging/external-control-api.md"
Argument for [-s|--scan [IP SUBNET]] flag
Input your LAN subnet
i.e. 192.168.11.0, 10.0.0.0, 192.168.0.0, etc...
'''
echo -e "Examples:\nLaunch Netflix\n\t${script} -a 192.168.11.142 -l netflix\n"
echo -e "Pause Roku \n\t${script} -a 192.168.11.142 -c pause\n"
echo -e "Go Home & turn down volume\n\t${script} -a 192.168.11.142 -c \"# v- v-\"\n"
echo -e "Launch plex, wait 5 seconds, move right, select \n\t${script} -a 192.168.11.142 -l plex -c \"s5 > .\""
echo -e "ECP documentation:\n\thttps://developer.roku.com/docs/developer-program/debugging/external-control-api.md"
echo -e "\nCheck for updates at https://gitlab.com/bradley.richins/rokuc"
exit
}
# IP address validation
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
function scan4dev()
{
if valid_ip $1; then
nmap -p8060 -Pn $1/$lanCIDR -oG - | grep 8060/open
else
echo -e "Invalid address: $1"
fi
}
function delay()
{
read -p "" -t $1
}
VERBOS=0
@@ -62,6 +122,26 @@ while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-s|--scan)
SUBNET="$2"
if [[ $devscan == 1 ]]; then
scan4dev $SUBNET
exit
else
echo "Scaning requires nmap, please install nmap to continue"
exit
fi
shift
shift
;;
-h|--help)
helpme
shift
;;
-i|--version)
versionInfo
shift
;;
-a|--address)
ADDRESS="$2"
shift
@@ -82,10 +162,7 @@ do
shift
shift
;;
-h|--help)
helpme
shift
;;
*)
POSITIONAL+=($1)
shift
@@ -101,23 +178,6 @@ if [[ $VERBOS == 1 ]]; then
echo -e " positional args\t${POSITIONAL[@]}"
fi
# IP address validation
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
# kill script if args are invalid
if [[ -n $1 ]]; then
if (( $VERBOS == 1 )); then
@@ -145,61 +205,61 @@ if [[ $LAUNCH == "plex" ]]; then
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/13535"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "netflix" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/12"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/12"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "youtube" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/837"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/837"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "hulu" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/2285"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/2285"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "hdmi1" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi1"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi1"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "hdmi2" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi2"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi2"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "hdmi3" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi3"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi3"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "hdmi4" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi4"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.hdmi4"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "av1" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.av1"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.av1"'
fi
sleep 4
delay 4
elif [[ $LAUNCH == "tv" ]]; then
curl -d "" "http://${ADDRESS}:8060/launch/tvinput.dtv"
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/tvinput.dtv"'
fi
sleep 4
delay 4
fi
# Command handler [-c|--command] args
@@ -211,7 +271,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Play"'
fi
sleep .5
delay .5
shift
;;
home|"#")
@@ -219,7 +279,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Home"'
fi
sleep .5
delay .5
shift
;;
select|ok|".")
@@ -227,7 +287,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Select"'
fi
sleep .5
delay .5
shift
;;
vol+|v+|vup|"+")
@@ -235,7 +295,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/VolumeUp"'
fi
sleep .5
delay .5
shift
;;
vol-|v-|vdown|"-")
@@ -243,7 +303,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/VolumeDown"'
fi
sleep .5
delay .5
shift
;;
mute|m)
@@ -251,7 +311,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/VolumeMute"'
fi
sleep .5
delay .5
shift
;;
off|power-off|shutdown|O)
@@ -259,7 +319,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/PowerOff"'
fi
sleep .5
delay .5
shift
;;
on|power-on|startup|I)
@@ -267,7 +327,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/PowerOn"'
fi
sleep .5
delay .5
shift
;;
back|k)
@@ -275,7 +335,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Back"'
fi
sleep .5
delay .5
shift
;;
u|up|^)
@@ -283,7 +343,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Up"'
fi
sleep .5
delay .5
shift
;;
d|down|v)
@@ -291,7 +351,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Down"'
fi
sleep .5
delay .5
shift
;;
l|left|"<")
@@ -299,7 +359,7 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Left"'
fi
sleep .5
delay .5
shift
;;
r|right|">")
@@ -307,35 +367,35 @@ for key in $com; do
if (( $VERBOS == 1 )); then
echo 'curl -d "" "http://${ADDRESS}:8060/launch/keypress/Right"'
fi
sleep .5
delay .5
shift
;;
s.5)
if (( $VERBOS == 1 )); then
echo 'wait 0.5 seconds'
fi
sleep .5
delay .5
shift
;;
s1)
if (( $VERBOS == 1 )); then
echo 'wait 1 second'
fi
sleep 1
delay 1
shift
;;
s2)
if (( $VERBOS == 1 )); then
echo 'wait 2 seconds'
fi
sleep 2
delay 2
shift
;;
s5)
if (( $VERBOS == 1 )); then
echo 'wait 5 seconds'
fi
sleep 5
delay 5
shift
;;
esac