proxmox_hassos_install/install.sh

59 lines
2.1 KiB
Bash
Raw Normal View History

2019-02-18 15:10:47 +01:00
#!/bin/bash
VMID=$(cat<<EOF | python3
import json
with open('/etc/pve/.vmlist') as vmlist:
vmids = json.load(vmlist)
2019-02-19 07:32:24 +01:00
if 'ids' not in vmids:
print(100)
else:
last_vm = sorted(vmids['ids'].keys())[-1:][0]
print(int(last_vm)+1)
2019-02-18 15:10:47 +01:00
EOF
) && \
echo -e "\n\n\n" \
"********************************\n" \
"* Getting latest HassOS Info *\n" \
"********************************\n" && \
URL=$(cat<<EOF | python3
import requests
url = 'https://api.github.com/repos/home-assistant/hassos/releases/latest'
r = requests.get(url).json()
if 'message' in r:
exit()
for asset in r['assets']:
if asset['name'].endswith('vdi.gz'):
print(asset['browser_download_url'])
EOF
) && \
if [ -z "$URL" ]; then
echo "Github has returned an error. A rate limit may have been applied to your connection. Please wait a while, then try again."
exit 1
fi && \
echo -e "\n\n\n" \
"********************************\n" \
"* Downloading HassOS *\n" \
"********************************\n" && \
wget -q $URL && \
FILE=$(basename $URL) && \
echo -e "\n\n\n" \
"********************************\n" \
"* Extracting HassOS *\n" \
"********************************\n" && \
gunzip -f $FILE && \
echo -e "\n\n\n" \
"********************************\n" \
"* Creating new VM *\n" \
"********************************\n" && \
qm create $VMID -bios ovmf -bootdisk sata0 -efidisk0 local-lvm:vm-${VMID}-disk-0,size=128K \
-name $(sed -e "s/\_//g" -e "s/.vdi.gz//" <<< $FILE) -net0 virtio,bridge=vmbr0 \
-onboot 1 -ostype l26 -sata0 local-lvm:vm-${VMID}-disk-1,size=6G \
-scsihw virtio-scsi-pci && \
2019-02-18 15:20:49 +01:00
pvesm alloc local-lvm $VMID vm-${VMID}-disk-0 128 1>&/dev/null && \
qm importdisk $VMID ${FILE%".gz"} local-lvm 1>&/dev/null && \
2019-02-18 15:10:47 +01:00
echo -e "\n\n\n" \
"********************************\n" \
"* Completed Successfully *\n" \
"* New VM ID is $VMID *\n" \
"********************************\n"