#!/bin/sh # Download and install the latest cloud-hypervisor + ch-remote static binaries. set -eu API="https://api.github.com/repos/cloud-hypervisor/cloud-hypervisor/releases/latest" # Pick the asset matching this architecture. case "$(uname -m)" in x86_64|amd64) ch_asset="cloud-hypervisor-static" chremote_asset="ch-remote-static" ;; aarch64|arm64) ch_asset="cloud-hypervisor-static-aarch64" chremote_asset="ch-remote-static-aarch64" ;; *) echo "unsupported architecture: $(uname -m)" >&2 exit 1 ;; esac echo "fetching latest cloud-hypervisor release metadata" if ! RESPONSE=$(curl -fsSL "$API"); then echo "FAILED TO QUERY CLOUD-HYPERVISOR RELEASES API" >&2 exit 1 fi HYPERVISOR_URL=$(printf '%s' "$RESPONSE" | jq -r --arg n "$ch_asset" \ '.assets[] | select(.name == $n) | .browser_download_url') CH_REMOTE_URL=$(printf '%s' "$RESPONSE" | jq -r --arg n "$chremote_asset" \ '.assets[] | select(.name == $n) | .browser_download_url') if [ -z "$HYPERVISOR_URL" ] || [ "$HYPERVISOR_URL" = "null" ] \ || [ -z "$CH_REMOTE_URL" ] || [ "$CH_REMOTE_URL" = "null" ]; then echo "FAILED TO RESOLVE DOWNLOAD URLS (asset missing for $(uname -m)?)" >&2 exit 1 fi # install_bin install_bin() { _url="$1"; _dest="$2" echo "downloading $_url" if ! curl -fsSL -o "$_dest" "$_url"; then echo "FAILED TO DOWNLOAD $_url" >&2 exit 1 fi chmod +x "$_dest" } install_bin "$HYPERVISOR_URL" /usr/bin/cloud-hypervisor install_bin "$CH_REMOTE_URL" /usr/bin/ch-remote # Sanity-check the binaries actually run on this platform. if ! /usr/bin/cloud-hypervisor --version >/dev/null 2>&1; then echo "cloud-hypervisor is not executable (wrong arch?)" >&2 exit 1 fi if ! /usr/bin/ch-remote --version >/dev/null 2>&1; then echo "ch-remote is not executable (wrong arch?)" >&2 exit 1 fi echo "cloud-hypervisor installed"