#!/bin/sh

printf "Content-Type: application/json\n\n"

if  ! jq . /tmp/hub_ready_apps.json > /dev/null
then
printf "[]" > /tmp/hub_ready_apps.json
fi

eval $(echo ${QUERY_STRING//&/;})

if [ ! "${appName}" = "" ]
then

ADD=$(jq ". + [\"${appName}\"] | unique" /tmp/hub_ready_apps.json)

printf "%s" "$ADD" > /tmp/hub_ready_apps.json

start-stop-daemon -K -q -s SIGUSR2 -x "/home/hubclient/bin/hub"

fi

printf "{}"
exit 0
