#!/bin/bash if [ -z "$_ROKU_SHELL_DIR" ]; then _ROKU_SHELL_DIR=$(dirname $(realpath $(readlink -f "${BASH_SOURCE[0]}" ))) fi source $_ROKU_SHELL_DIR/_roku_shared.sh source $_ROKU_SHELL_DIR/_roku_lt.sh source $_ROKU_SHELL_DIR/_roku_build.sh ############################################################################### # # Web server related # _roku_webserver_ip() { ip route get "$1" | sed -n "s/.* src \([\.0-9]*\) .*/\1/p" } _roku_webserver_relative_path() { [ -z "$ROKU_WEB_DIR" ] && echo "ROKU_WEB_DIR must be defined" >&2 && exit 1 realpath --relative-to="$ROKU_WEB_DIR" "$1" } ############################################################################### # # Helper functions # __set_master_ip() { MASTER_IP=$(_roku_webserver_ip $ROKU_DEV_TARGET) } __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" >&2 && exit 1 __device_cmd "echo \$ROKU_PLATFORM" | tail -1 | tr -d '\r\n' } _check_roku_env() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined. Run 'roku device' to setup." >&2 && exit 1 [ -z "$ROKU_DEV_PLATFORM" ] && echo "ROKU_DEV_PLATFORM must be defined. Run 'roku device' to setup." >&2 && exit 1 } ############################################################################### # # Run commands on active device # _roku_telnet() { _check_roku_env telnet "$ROKU_DEV_TARGET" $1 } _roku_flash() { _check_roku_env [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" >&2 && exit 1 [ -z "$ROKU_DEV_PLATFORM" ] && echo "ROKU_DEV_PLATFORM must be defined. Run 'roku device' to setup." >&2 && exit 1 local ACRAMFS_WEB_PATH=$1 local WEBSERVER_IP=$(_roku_webserver_ip $ROKU_DEV_TARGET) if [ -z "$ACRAMFS_WEB_PATH" ]; then local REPO_ROOT=$(_roku_repo_root .) local ACRAMFS=$(_roku_repo_acramfs_location $REPO_ROOT $ROKU_DEV_PLATFORM) [ ! -f "$ACRAMFS" ] && echo "No acramfs found: $ACRAMFS" >&2 && exit 1 ACRAMFS_WEB_PATH=$(_roku_webserver_relative_path $ACRAMFS) [ -z "$ACRAMFS_WEB_PATH" ] && exit 1 fi echo "Flashing $ACRAMFS_WEB_PATH" __device_cmd ". /nvram/san; export MASTER_IP=$WEBSERVER_IP; rokuflash $ACRAMFS_WEB_PATH" } # Side loaded applications: # 8085 dev_ui_console # 8086 dev_background_console # 8087 dev_screensaver_console # 8088 dev_getcontent_console # 8089 dev_voice_adapter_console # # Server loaded applications: # 8885 ui_console # 8886 background_console (including NDK) # 8887 screensaver_console # 8888 getcontent_console (eg, for 54383, DFP Ad Service) # 8889 voice_adapter_console _roku_log() { _check_roku_env __device_cmd "setconsole /dev/pts/0" } _roku_loglog() { _check_roku_env __netcat $1 } _roku_reboot() { _check_roku_env __device_cmd "reboot" } _roku_san_update() { _check_roku_env [ -z "$ROKU_WEB_PREFIX" ] && echo "ROKU_WEB_PREFIX must be defined." >&2 && exit 1 local SAN_LOCATION=$_ROKU_SHELL_DIR/san [ ! -f "$SAN_LOCATION" ] && echo "SAN script is not found: $SAN_LOCATION" >&2 && exit 1 local WEBSERVER_IP=$(_roku_webserver_ip $ROKU_DEV_TARGET) local SAN_URL="http://$WEBSERVER_IP/$ROKU_WEB_PREFIX/$(_roku_webserver_relative_path $SAN_LOCATION)" __device_cmd "wget -O /nvram/san $SAN_URL; source /nvram/san; setup_san" } ############################################################################### # # Retrieve audio. # _roku_audcap() { _check_roku_env [ -z "$1" ] && echo "Syntax: roku audcap " >&2 && exit 1 __set_master_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 $MASTER_IP" sox -t raw -r 48000 -b 16 -c 2 -e signed-integer $1.pcm $1.wav } ############################################################################### # # Debug app # _roku_gdb_attach() { _check_roku_env __device_cmd "/nvram/tools/gdbserver :5555 --attach \$(pgrep Application)" } _roku_gdb() { _check_roku_env # __device_cmd "/tmp/tools/gdbserver :5555 --attach \$(pgrep Application)" & # sleep 2 gdb-multiarch \ -ex "set non-stop off" \ -ex "set pagination off" \ -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ -ex "set substitute-path . $PWD" \ -ex "target remote $ROKU_DEV_TARGET:5555" # -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ # -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" } ############################################################################### # # Work with channels. # _roku_token_install() { _check_roku_env [ ! -f "$1" ] && echo "usage: install_auth_toke \n ROKU_DEV_TARGET=${ROKU_DEV_TARGET}" && return 0 curl --data-binary @$1 http://${ROKU_DEV_TARGET}:8060/token/install } _roku_sideload() { _check_roku_env [ ! -f "$1" ] && echo "usage: sideload \n ${ROKU_DEV_TARGET}=${ROKU_DEV_TARGET}" && return 0 curl --anyauth --user "rokudev:${DEVPASSWORD}" -F "mysubmit=Install_Netflix" -F "archive=@$1" http://${ROKU_DEV_TARGET}/plugin_install } ############################################################################### # # Misc # _roku_wget() { [ -z "$1" ] && echo "usage: roku_wget " && return 0 if [ -z "$ROKU_CORP_PASSWORD" ]; then local USER_PASSWORD="--ask-password" echo "NOTE: run 'roku wget pass' to set password." else local USER_PASSWORD="--password=$ROKU_CORP_PASSWORD" fi # wget --no-check-certificate --user=vkhachatryan $USER_PASSWORD "$@" wget --user=vkhachatryan $USER_PASSWORD "$@" } # _roku_wget_pass() sets corp password. It is defined in the # _roku_shaed.sh as it need to set env on the shell level. ############################################################################### # # Dispatch commands. # _roku_help() { echo "Command is not recognised." } _ROKU_DEFAULT_DISPATCH_FUNC=_roku_help _roku_dispatch "$@"