Files
san/_roku.sh
2023-06-08 19:15:21 +01:00

239 lines
5.7 KiB
Bash
Executable File

#!/bin/bash
source _roku_shared.sh
###############################################################################
#
# Helper functions
#
__set_master_ip()
{
MASTER_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 | tr -d '\r\n'
}
###############################################################################
#
# 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_master_ip
__device_cmd ". /nvram/san; export MASTER_IP=$MASTER_IP; rokuflash $1"
}
# 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()
{
[ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0
__device_cmd "setconsole /dev/pts/0"
}
_roku_loglog()
{
[ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0
__netcat $1
}
_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_master_ip
__device_cmd "wget -O /nvram/san http://${MASTER_IP}/roku/san/san; source /nvram/san; setup_san"
}
###############################################################################
#
# Retrieve audio.
#
_roku_audcap()
{
[ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0
__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()
{
[ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0
__device_cmd "/nvram/tools/gdbserver :5555 --attach \$(pgrep Application)"
}
_roku_gdb()
{
echo $ROKU_DEV_PLATFORM >> test.txt
[ -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 "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()
{
[ ! -f "$1" ] && echo "usage: install_auth_toke <auth token file> \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 <file> \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 <url>" && 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 "$@"
}
# _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 "$@"