Add info function and improve script output
This commit is contained in:
parent
f8a261da39
commit
02895331e3
34
install.sh
34
install.sh
@ -18,6 +18,11 @@ function error_exit() {
|
||||
msg "$FLAG $REASON"
|
||||
exit $EXIT
|
||||
}
|
||||
function info() {
|
||||
local REASON="$1"
|
||||
local FLAG="\e[36m[INFO]\e[39m"
|
||||
msg "$FLAG $REASON"
|
||||
}
|
||||
function msg() {
|
||||
local TEXT="$1"
|
||||
echo -e "$TEXT"
|
||||
@ -36,6 +41,7 @@ pvesm list $STORAGE >& /dev/null ||
|
||||
pvesm status -content images -storage $STORAGE >&/dev/null ||
|
||||
die "'$STORAGE' does not allow 'Disk image' to be stored."
|
||||
STORAGE_TYPE=`pvesm status -storage $STORAGE | awk 'NR>1 {print $2}'`
|
||||
info "Using '$STORAGE' for storage location."
|
||||
|
||||
# Get the next guest VM/LXC ID
|
||||
VMID=$(cat<<EOF | python3
|
||||
@ -49,12 +55,10 @@ else:
|
||||
print(int(last_vm)+1)
|
||||
EOF
|
||||
)
|
||||
info "Container ID is $VMID."
|
||||
|
||||
# Get latest Home Assistant disk image archive URL
|
||||
msg "
|
||||
********************************
|
||||
* Getting latest HassOS Info *
|
||||
********************************"
|
||||
msg "Getting URL for latest Home Assistant disk image..."
|
||||
RELEASE_EXT=vmdk.gz
|
||||
URL=$(cat<<EOF | python3
|
||||
import requests
|
||||
@ -72,24 +76,15 @@ if [ -z "$URL" ]; then
|
||||
fi
|
||||
|
||||
# Download Home Assistant disk image archive
|
||||
msg "\n\n\n
|
||||
********************************
|
||||
* Downloading HassOS *
|
||||
********************************"
|
||||
msg "Downloading disk image..."
|
||||
wget -q --show-progress $URL
|
||||
msg "\e[1A\e[0K\e[1A" #Overwrite output from wget
|
||||
FILE=$(basename $URL)
|
||||
|
||||
# Extract Home Assistant disk image
|
||||
msg "\n\n\n
|
||||
********************************
|
||||
* Extracting HassOS *
|
||||
********************************"
|
||||
msg "Extracting disk image..."
|
||||
gunzip -f $FILE
|
||||
|
||||
msg "\n\n\n
|
||||
********************************
|
||||
* Creating new VM *
|
||||
********************************"
|
||||
# Create variables for container disk
|
||||
if [ "$STORAGE_TYPE" = "dir" ]; then
|
||||
DISK_EXT=".qcow2"
|
||||
@ -103,6 +98,7 @@ for i in {0,1}; do
|
||||
done
|
||||
|
||||
# Create VM
|
||||
msg "Creating VM..."
|
||||
qm create $VMID -bios ovmf -name $(sed -e "s/\_//g" -e "s/.${RELEASE_EXT}//" <<< $FILE) \
|
||||
-net0 virtio,bridge=vmbr0 -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
|
||||
pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null
|
||||
@ -110,8 +106,4 @@ qm importdisk $VMID ${FILE%".gz"} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null
|
||||
qm set $VMID -bootdisk sata0 -efidisk0 ${DISK0_REF},size=128K \
|
||||
-sata0 ${DISK1_REF},size=6G > /dev/null
|
||||
|
||||
msg "\n\n\n
|
||||
********************************
|
||||
* Completed Successfully *
|
||||
* New VM ID is \e[1m$VMID\e[0m *
|
||||
********************************"
|
||||
info "Completed Successfully! New VM ID is \e[1m$VMID\e[0m."
|
||||
|
Loading…
Reference in New Issue
Block a user