#!/bin/sh

if ! command -v obuspa >/dev/null 2>&1; then
	exit 0
fi

USP_PATH="/tmp/sulu/"

log() {
	logger -t sulu_watcher "$*"
}

wait_for_obuspa() {
	while true; do
		ENDPOINTID="$(obuspa -c get Device.LocalAgent.EndpointID |grep Device.|awk '{print $3}')"
		sleep 2
		if [ -n "${ENDPOINTID}" ]; then
			break;
		fi
	done
}

mark_usp_ready() {
	mkdir -p "${USP_PATH}"
	touch ${USP_PATH}/ready
}

wait_for_obuspa
mark_usp_ready
