#!/bin/sh ############################################################################### # # Helper functions # __set_server_ip() { SERVER_IP=$(ip route get "${ROKU_DEV_TARGET}" | sed -n "s/.* src \([\.0-9]*\) .*/\1/p") } __netcat() { if [ "$1" != "" ]; then netcat -t $ROKU_DEV_TARGET $1 else netcat -t $ROKU_DEV_TARGET 23 fi } __app_cmd() { echo "$1 exit" | __netcat 8080 } __device_cmd() { echo "$1; exit" | __netcat } _roku_device_platform() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __device_cmd "echo \$ROKU_PLATFORM" | tail -1 } ############################################################################### # # Run commands on active device # _roku_telnet() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 telnet "$ROKU_DEV_TARGET" $1 } _roku_flash() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __set_server_ip __device_cmd ". /nvram/san; export SERVER_IP=$SERVER_IP; rokuflash $1" } _roku_log() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __device_cmd "setconsole /dev/pts/0" } _roku_reboot() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __device_cmd "reboot" } _roku_san_update() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __set_server_ip __device_cmd "wget -O /nvram/san http://${SERVER_IP}/roku/san/san" } ############################################################################### # # Retrieve audio. # _roku_audcap() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __set_server_ip __app_cmd "audcap record start 00" echo -n "Press Enter to stop capture." read __app_cmd "audcap record stop" __device_cmd "tftp -p -r $1.pcm -l /tmp/audcap_audio.pcm $SERVER_IP" sox -t raw -r 48000 -b 16 -c 2 -e signed-integer $1.pcm $1.wav } ############################################################################### # # Debug app # _roku_debug_attach() { PLATFORM=lockhart [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __device_cmd "/tmp/tools/gdbserver :5555 --attach \$(pgrep Application)" } _roku_debug() { PLATFORM=lockhart [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 # __device_cmd "/tmp/tools/gdbserver :5555 --attach \$(pgrep Application)" & # sleep 2 gdb-multiarch \ -ex "set non-stop off" \ -ex "target remote $ROKU_DEBUG_TARGET:5555" \ -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_TARGET/dist/rootfs" \ -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_TARGET/dist/rootfs" } ############################################################################### # # Work with channels. # _roku_token_install() { [ ! -f "$1" ] && echo "usage: install_auth_toke \n ROKU_DEV_TARGET=${ROKU_DEV_TARGET}" && return 0 [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 curl --data-binary @$1 http://${ROKU_DEV_TARGET}:8060/token/install } _roku_sideload() { [ ! -f "$1" ] && echo "usage: sideload \n ${ROKU_DEV_TARGET}=${ROKU_DEV_TARGET}" && return 0 [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 curl --anyauth --user "rokudev:${DEVPASSWORD}" -F "mysubmit=Install_Netflix" -F "archive=@$1" http://${ROKU_DEV_TARGET}/plugin_install } ############################################################################### # # Logging # LOGDIR="${HOME}/roku/logs" dcapture() { nc minicom "$@" -C $LOGDIR/.log.$(date +%Y-%m-%d--%H-%M-%S) } dfile() { local Nth="-1" if [ $# -gt 0 ]; then Nth="$1" fi echo $(ls -tr -1 ${LOGDIR}/minicom.log.* | tail ${Nth} | head -1) } dless() { less $(lfile "$@") } dcat() { cat $(lfile "$@") } dgrep() { lcat | grep -a --color "$@" } dtail() { if [ $# -gt 0 ]; then tail -f $(lfile) | grep "$@" else tail -f $(lfile) fi } ############################################################################### # # Misc # _roku_wget() { [ -z "$1" ] && echo "usage: roku_wget " && return 0 if [ -z "$ROKU_CORP_PASSWORD" ]; then local USER_PASSWORD="--ask-password" else local USER_PASSWORD="--password=$ROKU_CORP_PASSWORD" fi wget --no-check-certificate --user=vkhachatryan $USER_PASSWORD $1 } ############################################################################### # # Dispatch commands. # help() { echo "Command is not recognised." } FUNC=help if [ "$(type -t _roku_$1)" == "function" ]; then FUNC=_roku_$1 shift elif [ "$(type -t _roku_$1_$2)" == "function" ]; then FUNC=_roku_$1_$2 shift shift fi $FUNC "$@"