Skip to content

Commit

Permalink
Add support for multiple file compressions (whiskerz007#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
whiskerz007 committed Jan 4, 2021
1 parent b49feaa commit f681605
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ info "Container ID is $VMID."

# Get latest Home Assistant disk image archive URL
msg "Getting URL for latest Home Assistant disk image..."
RELEASE_EXT=vmdk.gz
RELEASE_TYPE=vmdk
URL=$(cat<<EOF | python3
import requests
url = "https://api.github.com/repos/home-assistant/operating-system/releases"
Expand All @@ -92,7 +92,7 @@ for release in r:
if release["prerelease"]:
continue
for asset in release["assets"]:
if asset["name"].endswith("$RELEASE_EXT"):
if asset["name"].find("$RELEASE_TYPE") != -1:
image_url = asset["browser_download_url"]
print(image_url)
exit()
Expand All @@ -110,7 +110,11 @@ FILE=$(basename $URL)

# Extract Home Assistant disk image
msg "Extracting disk image..."
gunzip -f $FILE
case $FILE in
*"gz") gunzip -f $FILE;;
*"xz") xz -d $FILE;;
*) die "Unable to handle file extension '${FILE##*.}'.";;
esac

# Create variables for container disk
STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
Expand All @@ -127,11 +131,11 @@ done

# Create VM
msg "Creating VM..."
VM_NAME=$(sed -e "s/\_//g" -e "s/.${RELEASE_EXT}//" <<< $FILE)
VM_NAME=$(sed -e "s/\_//g" -e "s/.${RELEASE_TYPE}.*$//" <<< $FILE)
qm create $VMID -agent 1 -bios ovmf -name $VM_NAME -net0 virtio,bridge=vmbr0 \
-onboot 1 -ostype l26 -scsihw virtio-scsi-pci
pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null
qm importdisk $VMID ${FILE%".gz"} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null
qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null
qm set $VMID \
-efidisk0 ${DISK0_REF},size=128K \
-sata0 ${DISK1_REF},size=6G > /dev/null
Expand Down

0 comments on commit f681605

Please sign in to comment.