summaryrefslogtreecommitdiffhomepage
path: root/protocols/luci-proto-yggdrasil/root/usr/libexec/rpcd/luci.yggdrasil-jumper
blob: 62c35b0e282a60884d6e520759a54c5ab4f87292 (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
36
37
38
39
40
41
42
43
44
#!/bin/sh

. /usr/share/libubox/jshn.sh

isInstalled() {
	[ -f /usr/sbin/yggdrasil-jumper ]
}

case "$1" in
	list)
		json_init
		json_add_object "isInstalled"
		json_close_object
		json_add_object "validateConfig"
		json_add_string "config"
		json_close_object
		json_dump
	;;
	call)
		case "$2" in
			isInstalled)
				json_init
				json_add_boolean "isInstalled" "$(isInstalled && echo 1 || echo 0)"
				json_dump
			;;
			validateConfig)
				read -r input
				json_load "$input"
				json_get_vars config

				output="Can't locate `yggdrasil-jumper`"
				isInstalled && \
					output="$(echo "$config" \
						| yggdrasil-jumper --validate --config - 2&>1 \
						| sed -E 's/(.{100}[^ ]*) /\1\n/g')"

				json_init
				json_add_string output "$output"
				json_dump
			;;
		esac
	;;
esac