diff options
author | Thierry Bultel <thierry.bultel@iot.bzh> | 2019-04-24 14:28:01 +0200 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2019-04-24 12:34:31 +0000 |
commit | 224f667013ae930b3698eb896889edbf1c0cf2c5 (patch) | |
tree | efabd608de839e6493b4a8148b958d79184c9c53 /bin/lib4a-tools.sh | |
parent | 76c7d5f13902ee2a58a05c0de01394650bcb4613 (diff) | |
parent | 4d67fb6cfb56d0abd8ec1c9149b88efd4828935d (diff) |
Merge branch 'sandbox/tbultel/avirt'
This migrates all the commits that were on the now-deprecated
iot.bzh github.
Bug-AGL: SPEC-2259
Change-Id: I98820a409cd02ee977e0383c1be227dc22344099
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'bin/lib4a-tools.sh')
-rw-r--r-- | bin/lib4a-tools.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/lib4a-tools.sh b/bin/lib4a-tools.sh new file mode 100644 index 0000000..f799cc2 --- /dev/null +++ b/bin/lib4a-tools.sh @@ -0,0 +1,54 @@ +stdout_in_terminal=0 +[[ -t 1 ]] && stdout_in_terminal=1 +function color { + [[ $stdout_in_terminal == 0 ]] && return + for k in $*; do + case $k in + bold) tput bold 2>/dev/null;; + none) tput sgr0 2>/dev/null;; + *) tput setaf $k 2>/dev/null;; + esac + done +} +color_green=$(color bold 2) +color_yellow=$(color bold 3) +color_red=$(color bold 1) +color_blue=$(color bold 4) +color_none=$(color none) + +function error() { echo "${color_red}$@${color_none}" >&2; } +function warning() { echo "${color_yellow}$@${color_none}" >&2; } +function info() { echo "${color_green}$@${color_none}" >&2; } +function log() { echo "$@" >&2; } +function debug() { [[ "$DEBUG" == 1 ]] && echo "${color_blue}DEBUG:" "$@" "${color_none}" >&2; } + +function 4a-client() { + # get port for audio service + local port="" + local token="HELLO" + local unitfile=$( ls /var/local/lib/systemd/system/afm-service-agl-service-audio-4a*.service ) + + if [ -f "$unitfile" ]; then + log "Detected systemd unit file!" + port=$( grep -sr X-AFM-http /var/local/lib/systemd/system/afm-service-agl-service-audio-4a*.service | cut -f2 -d'=' ) + log "Port detected: $port" + else + log "No systemd unit file detected, assuming running on host, please set 'API_4A_PORT' and 'API_4A_TOKEN' environment variables to correct values!" + port=${API_4A_PORT:-1234} + token=${API_4A_TOKEN:-"HELLO"} + log "Port: $port, token: $token" + fi + + afb-client-demo -H "localhost:$port/api?token=$token&uuid=magic" "$@" +} + +function 4a-roles() { + 4a-client ahl-4a get_roles "" | tail -n +2 | jq '.response|.[]' +} + +function mediascanner-client() { + afb-client-demo -H -d unix:/run/user/0/apis/ws/mediascanner "$@" +} +function mediaplayer-client() { + afb-client-demo -H -d unix:/run/user/0/apis/ws/mediaplayer "$@" +} |