summaryrefslogtreecommitdiff
path: root/systemd/magic4linux-start
blob: 971e47848cd6a7c723623bb701f7587a057eb686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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