diff --git a/tools/developer-setup/download-qcow2-image.sh b/tools/developer-setup/download-qcow2-image.sh index 01b7c32..550255f 100644 --- a/tools/developer-setup/download-qcow2-image.sh +++ b/tools/developer-setup/download-qcow2-image.sh @@ -1,11 +1,9 @@ #!/bin/bash - -if [ -z "$TAG" ]; then - echo "" - echo "TAG environment variable is required" - echo "e.g. export TAG=v1.0.0" +if [ -z "$VM_NAME" ] || [ -z "$TAG" ]; then echo "" + [ -z "$VM_NAME" ] && echo "VM_NAME environment variable is required" && echo "e.g. export VM_NAME=dinosaur-cat" && echo "" + [ -z "$TAG" ] && echo "TAG environment variable is required" && echo "e.g. export TAG=v1.0.0" && echo "" exit 1 fi @@ -13,37 +11,38 @@ fi owner="GlueOps" repo="codespaces" -if [ -f "$TAG.qcow2" ]; then - echo "File $TAG.qcow2.tar already exists. Skipping download." - echo "Cleaning up any files" - rm -rf $TAG.qcow2.tar* -else - # Capture the start time - start_time=$(date +%s) +# Capture the start time +start_time=$(date +%s) - # Get the release ID for the specified tag - release_id=$(curl -s "https://api.github.com/repos/$owner/$repo/releases/tags/$TAG" | jq -r '.id') +# Get the release ID for the specified tag +release_id=$(curl -s "https://api.github.com/repos/$owner/$repo/releases/tags/$TAG" | jq -r '.id') - # Get the asset download URLs - asset_urls=$(curl -s "https://api.github.com/repos/$owner/$repo/releases/$release_id/assets" | jq -r '.[].browser_download_url') +# Get the asset download URLs +asset_urls=$(curl -s "https://api.github.com/repos/$owner/$repo/releases/$release_id/assets" | jq -r '.[].browser_download_url') - # Download each asset in parallel - for url in $asset_urls; do - echo "Downloading $url" - curl -L -O "$url" & - done +# Download each asset in parallel +for url in $asset_urls; do + filename=$(basename "$url") + echo "Downloading $url" + mkdir -p "/tmp/$VM_NAME" + curl -L -o "/tmp/$VM_NAME/$filename" "$url" & +done - # Wait for all background jobs to complete - wait +# Wait for all background jobs to complete +wait - # Calculate and display elapsed time - end_time=$(date +%s) - elapsed_time=$((end_time - start_time)) - echo "Total time taken: $elapsed_time seconds" +# Calculate and display elapsed time +end_time=$(date +%s) +elapsed_time=$((end_time - start_time)) +echo "Total time taken: $elapsed_time seconds" + + +cat /tmp/$VM_NAME/*.qcow2.tar.part_* > /tmp/$VM_NAME/$VM_NAME.qcow2.tar +tar -xvf /tmp/$VM_NAME/$VM_NAME.qcow2.tar -C /tmp/$VM_NAME +mv /tmp/$VM_NAME/*.qcow2 /var/lib/libvirt/images/$VM_NAME.qcow2 +echo "Deleting /tmp/$VM_NAME/" +rm -rf /tmp/$VM_NAME/ +echo "resizing /var/lib/libvirt/images/$VM_NAME.qcow2" +qemu-img resize /var/lib/libvirt/images/$VM_NAME.qcow2 120G - cat $TAG.qcow2.tar.part_* > $TAG.qcow2.tar - tar -xvf $TAG.qcow2.tar - echo "Deleting downloaded .tar files" - rm -rf $TAG.qcow2.tar* -fi