From 5ebd786a63ac36d68e9a342c9ff474993903db94 Mon Sep 17 00:00:00 2001 From: Dmitrii Morozov Date: Wed, 27 Mar 2024 21:05:38 +0100 Subject: Added systemd service descriptor --- systemd/magic4linux-start | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 systemd/magic4linux-start (limited to 'systemd/magic4linux-start') diff --git a/systemd/magic4linux-start b/systemd/magic4linux-start new file mode 100755 index 0000000..971e478 --- /dev/null +++ b/systemd/magic4linux-start @@ -0,0 +1,45 @@ +#! /usr/bin/bash + +ARES_DEVICE_INFO_CMD="$WEBOS_CLI_TV/ares-device-info" +ARES_LAUNCH_CMD="$WEBOS_CLI_TV/ares-launch" +GOPATH=$(/usr/bin/go env GOPATH) + +function ares_available() { + if ! command -v $ARES_DEVICE_INFO_CMD &> /dev/null + then + echo "$ARES_DEVICE_INFO_CMD could not be found" + exit 1 + fi +} + +function wait_ares_connection() { + until $ARES_DEVICE_INFO_CMD > /dev/null + do + echo "Cannot establish connection to ares" + sleep 1 + done + echo "Connection to ares established" +} + +function check_magic4pc_running() { + $ARES_LAUNCH_CMD -r | grep -q 'me.wouterdek.magic4pc' + return $? +} + +function start_magic4pc() { + $ARES_LAUNCH_CMD me.wouterdek.magic4pc + return $? +} + +if ares_available; then + wait_ares_connection + if check_magic4pc_running; then + echo "WebOS Magic4pc application is already running" + else + echo "WebOS Magic4pc application not running, starting.." + start_magic4pc + fi +fi + +echo "Starting magic4linux.." +$GOPATH/bin/magic4linux -- cgit v1.2.3