#!/bin/bash send() { afb-client-demo -H -d unix:@afm_platform_rundir@/apis/ws/afm-main "$1" "$2" | awk '$1=="ON-REPLY" && $3!="success"{$1="ERROR:";$2="";print > "/dev/stderr";exit 1;}NR>1' } getall() { case "$1" in -a|--all) echo -n '{"all":true}';; *) echo -n true;; esac } case "$1" in list|runnables) send runnables $(getall $2) ;; add|install) f=$(realpath $2) r=true if [[ "$(basename $0)" = "afm-install" ]]; then r=false; fi send install '{"wgt":"'"$f"'","force":true,"reload":'"$r"'}' ;; remove|uninstall) i=$2 send uninstall "\"$i\"" ;; info|detail) i=$2 send detail "\"$i\"" ;; ps|runners) send runners $(getall $2) ;; run|start) i=$2 send start "\"$i\"" ;; run-remote|start-remote) i=$2 send start '{"id":"'"$i"'","mode":"remote"}' ;; once) i=$2 send once "\"$i\"" ;; terminate|kill) i=$2 send terminate "$i" ;; state|status) i=$2 send state "$i" ;; -h|--help|help) cat << EOC usage: $(basename $0) command [arg] The commands are: list runnables list the runnable widgets installed option -a or --all for all instances add wgt install wgt install the wgt file remove id uninstall id remove the installed widget of id info id detail id print detail about the installed widget of id ps runners list the running instance option -a or --all for all instances run id start id start an instance of the widget of id once id run once an instance of the widget of id kill rid terminate rid terminate the running instance rid status rid state rid get status of the running instance rid EOC ;; *) echo "unknown command $1" >&2 exit 1 ;; esac