#!/bin/sh

. /usr/share/libubox/jshn.sh

case "$1" in
	list)
		# List method must return the list of methods and parameters that the daemon will accept. Only methods listed here will available to call.
		echo '{ "description": { }, "branch": { }, "revision": { } }'
	;;
	call)
		if [ ! -f /etc/weimarnetz_release ]; then
			exit 1
		fi
		case "$2" in
			description)
				description=$(grep "^WEIMARNETZ_PACKAGES_DESCRIPTION=" /etc/weimarnetz_release | cut -d'=' -f2)
				json_init
				json_add_string "description" "$description"
				json_dump
			;;
			branch)
				branch=$(grep "^WEIMARNETZ_PACKAGES_BRANCH=" /etc/weimarnetz_release | cut -d'=' -f2)
				json_init
				json_add_string "branch" "$branch"
				json_dump
			;;
			revision)
				revision=$(grep "^WEIMARNETZ_PACKAGES_REV=" /etc/weimarnetz_release | cut -d'=' -f2)
				json_init
				json_add_string "revision" "$revision"
				json_dump
			;;
		esac
	;;
esac