Check-in [c0f939a115]
Overview
Comment:Added a simple API client
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c0f939a1153a1242c19bd90fbe5236929a470df8
User & Date: rkeene on 2019-02-28 08:55:39
Other Links: manifest | tags
Context
2019-02-28
08:55
Better formatting of results check-in: 5445a8ff26 user: rkeene tags: trunk
08:55
Added a simple API client check-in: c0f939a115 user: rkeene tags: trunk
07:41
Better handling to the kit_url check-in: 01ff48e506 user: rkeene tags: trunk
Changes

Added build/utils/download-api-client version [5f112c56ea].









































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env bash

# Define endpoint
endpoint_url="https://kitcreator.rkeene.org/kitcreator"

# Set arguments
declare -A jsonArgs
jsonArgs["platform"]="$(uname -s)-$(uname -m)"

nextArg=''
kit_filename=''
for arg in "$@"; do
	if [ -n "${nextArg}" ]; then
		jsonArgs["${nextArg}"]="${arg}"
		nextArg=''
		continue
	fi

	case "${arg}" in
		--platform|--tcl-version|--kitcreator-version)
			nextArg="${arg:2}"
			nextArg="${nextArg//-/_}"
			;;
	esac
done

# Convert arguments into a request
jqArgs=()
jqSettings=''
for jsonArg in "${!jsonArgs[@]}"; do
	jqArgs+=(--arg "${jsonArg}" "${jsonArgs[${jsonArg}]}")
	jqSettings="${jqSettings} | .${jsonArg} = \$${jsonArg}"
done
jqArgs+=("${jqSettings:3}")

jsonRequest="$(jq -crM "${jqArgs[@]}" <<<'{"action":"build"}')"

# Make the request
results="$(curl -sSL -d "json=${jsonRequest}" "${endpoint_url}")"
url="$(jq -crM .url <<<"${results}")"
while true; do
	info="$(curl -sSL "${url}")"
	terminal="$(jq -crM .terminal <<<"${info}")"

	if [ "${terminal}" = 'true' ]; then
		break
	fi

	sleep 30
done

status="$(jq -crM .status <<<"${info}")"
if [ "${status}" != "complete" ]; then
	echo "failed: ${status}" >&2

	exit 1
fi

kit_url="$(jq -crM .kit_url <<<"${info}")"
if [ -z "${kit_filename}" ]; then
	kit_filename="${kit_url//*\//}"
fi

curl -sSL "${kit_url}" > "${kit_filename}"
chmod 755 "${kit_filename}"

echo "Wrote: ${kit_filename}"
exit 0