From fe4e35e8460282cac2d7a763302a7631fc21d067 Mon Sep 17 00:00:00 2001 From: tteckster Date: Sun, 16 Jan 2022 02:17:21 -0500 Subject: [PATCH] Update ha_container.sh --- ha_container.sh | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/ha_container.sh b/ha_container.sh index f46bb8a1..1ffee469 100644 --- a/ha_container.sh +++ b/ha_container.sh @@ -8,14 +8,13 @@ while true; do * ) echo "Please answer yes or no.";; esac done - -# Setup script environment -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' +CHECKMARK='\033[0;32m\xE2\x9C\x94\033[0m' trap die ERR trap cleanup EXIT @@ -73,13 +72,10 @@ function load_module() { TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null -# Download setup script wget -qL https://raw.githubusercontent.com/tteck/Proxmox/main/ha_setup.sh -# Detect modules and automatically load at boot load_module overlay -# Select storage location while read -r line; do TAG=$(echo $line | awk '{print $1}') TYPE=$(echo $line | awk '{printf "%-10s", $2}') @@ -105,15 +101,12 @@ else done fi info "Using '$STORAGE' for storage location." - -# Get the next guest VM/LXC ID CTID=$(pvesh get /cluster/nextid) info "Container ID is $CTID." -# Download latest Debian 10 LXC template -msg "Updating LXC template list..." +echo -e "${CHECKMARK} \e[1;92m Updating LXC Template List... \e[0m" pveam update >/dev/null -msg "Downloading LXC template..." +echo -e "${CHECKMARK} \e[1;92m Downloading LXC Template... \e[0m" OSTYPE=debian OSVERSION=${OSTYPE}-11 mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($OSVERSION.*\)/\1/p" | sort -t - -k 2 -V) @@ -121,7 +114,6 @@ TEMPLATE="${TEMPLATES[-1]}" pveam download local $TEMPLATE >/dev/null || die "A problem occured while downloading the LXC template." -# Create variables for container disk STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') case $STORAGE_TYPE in dir|nfs) @@ -136,8 +128,7 @@ esac DISK=${DISK_PREFIX:-vm}-${CTID}-disk-0${DISK_EXT-} ROOTFS=${STORAGE}:${DISK_REF-}${DISK} -# Create LXC -msg "Creating LXC container..." +echo -e "${CHECKMARK} \e[1;92m Creating LXC Container... \e[0m" DISK_SIZE=8G pvesm alloc $STORAGE $CTID $DISK $DISK_SIZE --format ${DISK_FORMAT:-raw} >/dev/null if [ "$STORAGE_TYPE" == "zfspool" ]; then @@ -152,35 +143,26 @@ pct create $CTID $TEMPLATE_STRING -arch $ARCH -features nesting=1 \ -hostname $HOSTNAME -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 -cores 2 -memory 2048 \ -ostype $OSTYPE -rootfs $ROOTFS,size=$DISK_SIZE -storage $STORAGE >/dev/null -# Modify LXC permissions to support Docker LXC_CONFIG=/etc/pve/lxc/${CTID}.conf cat <> $LXC_CONFIG lxc.cgroup2.devices.allow: a lxc.cap.drop: EOF -# Set container description -pct set $CTID -description "Access Portainer interface using the following URL. - -http://:9000" - -# Set container timezone to match host MOUNT=$(pct mount $CTID | cut -d"'" -f 2) ln -fs $(readlink /etc/localtime) ${MOUNT}/etc/localtime pct unmount $CTID && unset MOUNT -# Setup container -msg "Starting LXC container..." +echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m" pct start $CTID pct push $CTID ha_setup.sh /ha_setup.sh -perms 755 pct exec $CTID /ha_setup.sh -# Get network details and show completion message IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -info "Successfully created Home Assistant Container LXC to $CTID." +info "Successfully Created Home Assistant Container LXC to $CTID." msg " -Home Assistant is reachable by going to the following URLs. +Home Assistant should be reachable by going to the following URL. http://${IP}:8123 "