diff options
Diffstat (limited to 'systemd/magic4linux-start')
| -rwxr-xr-x | systemd/magic4linux-start | 45 | 
1 files changed, 45 insertions, 0 deletions
| 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 | 
