umorpha-boxes/bin/vultr-iso-id

34 lines
785 B
Plaintext
Raw Normal View History

2023-11-03 23:15:57 +00:00
#!/usr/bin/env bash
# Copyright (C) 2023 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euE -o pipefail
main() {
local url
url=$1
{
list_resp=$(bin/vultr-api iso)
id=$(jq -r ".isos[]|select(.filename==\"${url##*/}\").id" <<<"$list_resp")
local status
if [[ -n "$id" ]]; then
status=$(jq -r ".isos[]|select(.id==\"${id}\").status" <<<"$list_resp")
else
local post_resp
post_resp=$(bin/vultr-api iso -XPOST --data "{\"url\":\"${url}\"}")
id=$(jq -r .iso.id <<<"$post_resp")
status=$(jq -r .iso.status <<<"$post_resp")
fi
while [[ "$status" != complete ]]; do
2023-11-04 02:28:14 +00:00
echo "iso status=${status}..."
2023-11-03 23:15:57 +00:00
sleep 1
status=$(bin/vultr-api "iso/${id}" | jq -r .iso.status)
done
2023-11-04 02:28:14 +00:00
echo "iso status=${status}"
2023-11-03 23:15:57 +00:00
} >&2
echo "$id"
}
main "$@"