umorpha-boxes/bin/vultr-iso-id

41 lines
959 B
Plaintext
Raw Permalink 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
2023-11-09 08:20:55 +00:00
local n
n=$(jq '.isos|length' <<<"$list_resp")
if [[ "$n" -ge 2 ]]; then
id=$(jq -r '.isos[0].id' <<<"$list_resp")
bin/vultr-api "iso/${id}" -XDELETE
fi
2023-11-03 23:15:57 +00:00
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 "$@"