#!/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 echo "iso status=${status}..." sleep 1 status=$(bin/vultr-api "iso/${id}" | jq -r .iso.status) done echo "iso status=${status}" } >&2 echo "$id" } main "$@"