From e5699e079fea663044859b12ef715c7a3059ea37 Mon Sep 17 00:00:00 2001 From: tteckster Date: Sun, 16 Jan 2022 02:10:17 -0500 Subject: [PATCH] Update ha_setup.sh --- ha_setup.sh | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/ha_setup.sh b/ha_setup.sh index 660918f9..88841149 100644 --- a/ha_setup.sh +++ b/ha_setup.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -# 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 'die "Script interrupted."' INT @@ -23,25 +23,22 @@ function msg() { echo -e "$TEXT" } -# Prepare container OS -msg "Setting up container OS..." +echo -e "${CHECKMARK} \e[1;92m Setting up Container OS... \e[0m" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null apt-get -y purge openssh-{client,server} >/dev/null apt-get autoremove >/dev/null -# Update container OS -msg "Updating container OS..." +echo -e "${CHECKMARK} \e[1;92m Updating Container OS... \e[0m" apt update &>/dev/null apt-get -qqy upgrade &>/dev/null -# Install prerequisites -msg "Installing prerequisites..." +echo -e "${CHECKMARK} \e[1;92m Installing Dependencies... \e[0m" apt-get -qqy install \ - curl &>/dev/null - -# Customize Docker configuration -msg "Customizing Docker..." + curl \ + wget &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Customizing Docker... \e[0m" DOCKER_CONFIG_PATH='/etc/docker/daemon.json' mkdir -p $(dirname $DOCKER_CONFIG_PATH) cat >$DOCKER_CONFIG_PATH <<'EOF' @@ -50,12 +47,10 @@ cat >$DOCKER_CONFIG_PATH <<'EOF' } EOF -# Install Docker -msg "Installing Docker..." -sh <(curl -sSL https://get.docker.com) &>/dev/null +echo -e "${CHECKMARK} \e[1;92m Installing Docker.io... \e[0m" +apt-get install -y docker.io &>/dev/null -# Install Portainer -msg "Installing Portainer..." +echo -e "${CHECKMARK} \e[1;92m Installing Portainer... \e[0m" docker volume create portainer_data >/dev/null docker run -d \ -p 8000:8000 \ @@ -66,8 +61,7 @@ docker run -d \ -v portainer_data:/data \ portainer/portainer-ce:latest &>/dev/null -# Install Home Assistant -msg "Installing Home Assistant..." +echo -e "${CHECKMARK} \e[1;92m Installing Home Assistant... \e[0m" docker volume create hass_config >/dev/null docker run -d \ --name homeassistant \ @@ -80,11 +74,10 @@ docker run -d \ --net=host \ homeassistant/home-assistant:stable &>/dev/null -# Customize container -msg "Customizing container..." -rm /etc/motd # Remove message of the day after login -rm /etc/update-motd.d/10-uname # Remove kernel information after login -touch ~/.hushlogin # Remove 'Last login: ' and mail notification after login +echo -e "${CHECKMARK} \e[1;92m Customizing Container... \e[0m" +rm /etc/motd +rm /etc/update-motd.d/10-uname +touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) cat << EOF > $GETTY_OVERRIDE @@ -95,6 +88,5 @@ EOF systemctl daemon-reload systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') -# Cleanup container -msg "Cleanup..." +echo -e "${CHECKMARK} \e[1;92m Cleanup... \e[0m" rm -rf /ha_setup.sh /var/{cache,log}/* /var/lib/apt/lists/*