aboutsummaryrefslogtreecommitdiffstats
path: root/bin/lib4a-tools.sh
blob: 4029046242782f1bb6c4bca9db361735e6455c32 (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
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=$(grep -sr X-AFM-http /var/local/lib/systemd/system/afm-service-agl-service-audio-4a*.service | cut -f2 -d'=')

	debug "Detected 4A service on port $port"
	afb-client-demo -H "localhost:$port/api?token=HELLO&uuid=magic" "$@"
}

function 4a-roles() {
	4a-client ahl-4a get_roles "" | tail -n +2 | jq '.response|.[]'
}