Bash script interface for the roku web interface.

Roku's free SDK allows developers to build channels and applications and publish them to the Roku Channel Store. Register for the Developer Program at http://www.roku.com/developer

Moderators: RokuDouglas, RokuKen, RokuRyan, RokuJamesL, RokuChris, RokuJoel

Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 1:53 pm

Edit: Added rekey function due to popular demand!
Edit Added lazy replace function

With these scripts you should not have to touch the web interface ever again.
The only function I left out was replace. Edit Added lazy replace function
Replace is just deleting then uploading so I did not see a need to implement it.
If someone needs a replace script just say so and I will crank one out.
Here are the funcitons.
uproku: uploads zip file to roku
delroku: deletes the zip file on the roku.
packageroku: takes a already uploaded zip file and turns it into a package and downloads it.
inspectroku: uploads and inspects a package from your harddrive and gives you relevant info on it.
rekeyroku: uploads a package and load its key

Code: Select all
#this is all the current functions.

#this uploads a zip file to the roku

uproku ()
{
if [ "$1" ] && [ "$2" ]; then
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
curl --silent --show-error --user-agent "$uagent" --form archive=@$1 --form "mysubmit=Replace" "http://$2/plugin_install" |grep "Application Received:"|tr '>' '\n'|tail -n 1 ;
echo "size on disk is $(ls -alb $1 |awk '{ print $5 }') bytes ";
else
  echo -e "this willupload a zip to a roku, you inputed too few arguments format is\nuproku zipname IPaddress_of_ROKU "; 
fi
}


#this deletes a zip file from the roku

delroku ()
{
if [ "$1" ]; then
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
curl --silent --show-error --user-agent "$uagent" --form "archive=" --form 'mysubmit=Delete' "http://$1/plugin_install" |grep Delete|tr '>' '\n'|tail -n 1 ;
else
  echo -e "this program will delete a zip from the roku, you inputed two few arguments format is\nuproku zipname IPaddress_of_ROKU "; 
fi
}

#lazy replace function uses same parameters as uproku in the same order.
replaceroku ()
{
delroku "$2" ;
uproku "$1" "$2" ;
}

#this takes an already uploaded zip file on the roku and converts it into a package then downloads the package to the current directory.

packageroku ()
{
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
ftime=$(($(date +'%s')*1000)) ;
if [ "$1" ] && [ "$2" ] && [ "$3" ] && [  ${#1} -lt 32 ]; then
  purl=$(curl --silent --show-error --user-agent "$uagent" --form "app_name=$1" --form "passwd=$2" --form "pkg_time=$ftime" --form "mysubmit=Package" "http://$3/plugin_package" |grep "href"|grep -v "plugin_inspect\|plugin_install"|awk -F 'href="' '{ print $2 }'|tr '"' '\n'|head -n1 ;) ;
  wget http://$3/$purl ;
else
  echo -e "this will take an existing zip file on the roku and turn it into a package, either app name too large or you inputed two few arguments format is\npackageroku appname dev_password IPaddress_of_ROKU "; 
fi
}

#this will inspect a already packaged package, it will show various pieces of  information about the package.

inspectroku ()
{
if [ "$1" ] && [ "$2" ] && [ "$3" ]; then
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
output=$(curl --silent --show-error --user-agent "$uagent" --form archive=@$1 --form "passwd=$2" --form "mysubmit=Inspect" "http://$3/plugin_inspect") ;
pdate=$(date --date "Jan 1, 1970 00:00:00 +0000 + $(( $(echo $output|awk -F 'Date\\(' '{ print $2 }'| awk -F '\\)' '{ print $1 }')/1000 )) seconds");
echo $output|html2text|tail -n5|sed "s/Creation Date:/Creation Date: $pdate/g" ;
else
  echo -e "this program will upload a package and incpect it, you inputed too few arguments format is\ninspectroku packagename dev_password IPaddress_of_ROKU "; 
fi
}

#this will upload a package and load its key.
rekeyroku ()
{
if [ "$1" ] && [ "$2" ] && [ "$3" ]; then
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
output=$(curl --silent --show-error --user-agent "$uagent" --form archive=@$1 --form "passwd=$2" --form "mysubmit=Rekey" "http://$3/plugin_inspect") ;
echo $output |awk -F '<font color="red">' '{ print $2 }'|tr '<' '\n'|head -n 1 ;
else
  echo -e "this program will upload a package and load its key, you inputed too few arguments format is\nrekeyroku packagename dev_password IPaddress_of_ROKU "; 
fi
}



Code: Select all
$delroku roku01.local
Delete Succeeded.
$uproku videoplayer.zip roku01.local
Application Received: 127030 bytes stored.
size on disk is 127030 bytes
$packageroku 'sample video player' 'your_dev_password' roku01.local
--2011-04-29 13:50:24--  http://roku01.local/pkgs/somepackage.pkg
Resolving roku01.local... 192.168.0.24
Connecting to roku01.local|192.168.0.24|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 130000 (127K) [text/plain]
Saving to: `somepackage.pkg'

100%[==========================================================================================>] 130,000     --.-K/s   in 0.02s   

2011-04-29 13:50:24 (5.25 MB/s) - `somepackage.pkg' saved [130000/130000]

$ inspectroku somepackage.pkg devpassword roku01.local
App Name: video player
Dev ID: SOME_DEV_ID
Creation Date: Fri Apr 29 16:24:37 EDT 2011
$ rekeyroku somepackage.pkg dev_password roku01.local
Success.





If you make your own private channels, these scripts will allow you to upload your channel from the linux command line or delete the channel from the command line.
I am working towards a kate script to use make to "make" the roku zip package.
and then use uproku to upload the zip file to my roku automatically.
Kate is a KDE text editor I use for modifying brightscript. hopefully they will add brightscript highlighting soon.

These are bash functions, either you can cut and paste them into your current shell or place them in your bashrc.
or you can make a file per function called the name of the function.
for instance to make uproku into a standalone program create a file called uproku and populate it with text below.
Code: Select all
#/bin/bash
uproku ()
{
if [ "$1" ] && [ "$2" ]; then
uagent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
curl --silent --show-error --user-agent "$uagent" --form archive=@$1 --form "mysubmit=Replace" "http://$2/plugin_install" |grep "Application Received:"|tr '>' '\n'|tail -n 1 ;
echo "size on disk is $(ls -alb $1 |awk '{ print $5 }') bytes ";
else
  echo -e "this willupload a zip to a roku, you inputed too few arguments format is\nuproku zipname IPaddress_of_ROKU "; 
fi
}
uproku "$1" "$2";

in the example above you will notice that the function has the same name as the filename of the script. this works because the function will get executed before the local file(except the first time you run the file when the function is not defined yet)..

also you will notice he last line uproku "$1" "$2"; if you were doing a script with three parameters like packageroku the last line would be.
packageroku "$1" "$2" "$3";
or for delroku since it only has one parameter.
delroku "$1";
Last edited by manoflinux on Sat Apr 30, 2011 5:40 am, edited 10 times in total.
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm

Re: Bash script interface for the roku web interface.

Postby RokuChris » Fri Apr 29, 2011 3:25 pm

manoflinux wrote:I dont see a use for rekey


I use rekey daily for a few reasons...

The dev key used to package a channel controls what registry space the channel has access to, so you need to be sure new versions of a channel are packaged using the same key as the old version or else the new version will not have access to data that was stored in the registry by the old version.

It's also good practice to use a different dev key for each channel you build to avoid registry conflicts.

And, unless this changed recently, if you deploy multiple screensavers packaged with the same dev key, weird things will happen (viewtopic.php?f=34&t=30176&p=184319#p184468)
Last edited by RokuChris on Fri Apr 29, 2011 3:33 pm, edited 2 times in total.
RokuChris
 
Posts: 1036
Joined: Mon Aug 30, 2010 1:45 pm

Re: Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 3:32 pm

RokuChris wrote:
manoflinux wrote:I dont see a use for rekey


I use rekey daily for a few reasons...

The dev key used to package a channel controls what registry space the channel has access to, so you need to be sure new versions of a channel are packaged using the same key as the old version or else the new version will not have access to data that was stored in the registry by the old version.

It's also good practice to use a different dev key for each channel you build to avoid registry conflicts.

And, unless this changed recently, if you deploy multiple screensavers packaged with the same dev key, weird things will happen (viewtopic.php?f=34&t=30176&p=184319#p184468)


Ok now it makes more sense. give me a minute and I will add rekey.
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm

Re: Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 3:52 pm

so does this mean I should do a telnet roku01.local 8080 and do a genkey for every app?
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm

Re: Bash script interface for the roku web interface.

Postby RokuChris » Fri Apr 29, 2011 4:08 pm

manoflinux wrote:so does this mean I should do a telnet roku01.local 8080 and do a genkey for every app?


Yes, recommended practice is to use a unique dev key for each channel you build. The exception being the case where you have multiple channels that need access to the same registry space. In that case, those channels would have to be signed with the same key.
RokuChris
 
Posts: 1036
Joined: Mon Aug 30, 2010 1:45 pm

Re: Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 6:05 pm

RokuChris wrote:
manoflinux wrote:so does this mean I should do a telnet roku01.local 8080 and do a genkey for every app?


Yes, recommended practice is to use a unique dev key for each channel you build. The exception being the case where you have multiple channels that need access to the same registry space. In that case, those channels would have to be signed with the same key.

whats the difference between telnet roku01.local 8080 with a genkey and the rekey button in the interface?
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm

Re: Bash script interface for the roku web interface.

Postby RokuChris » Fri Apr 29, 2011 7:05 pm

manoflinux wrote:whats the difference between telnet roku01.local 8080 with a genkey and the rekey button in the interface?


genkey generates a brand new key
rekey is for reinstalling an existing key
RokuChris
 
Posts: 1036
Joined: Mon Aug 30, 2010 1:45 pm

Re: Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 9:42 pm

RokuChris wrote:
manoflinux wrote:whats the difference between telnet roku01.local 8080 with a genkey and the rekey button in the interface?


genkey generates a brand new key
rekey is for reinstalling an existing key

but where does it get the key from?
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm

Re: Bash script interface for the roku web interface.

Postby destruk » Fri Apr 29, 2011 9:45 pm

It gets the key for a rekey operation from the current sideloaded package. So, if you have channelA that was packaged by a team member, and channelB was created by yourself, you can load packageA, rekey your roku box with that one, and then load yours (channelB) as a zipped source file and re-sign it with channelA's key.
destruk
 
Posts: 1785
Joined: Sat Dec 18, 2010 4:58 pm

Re: Bash script interface for the roku web interface.

Postby manoflinux » Fri Apr 29, 2011 9:59 pm

ahhh. makes sense now, its just not obvious. thanks
manoflinux
 
Posts: 147
Joined: Sun Mar 20, 2011 8:53 pm


Return to Roku Developer Program

Who is online

Users browsing this forum: BrooklynOlivia and 1 guest