From 4626d09e0572f0390c3bbf75a683c43050489331 Mon Sep 17 00:00:00 2001 From: James Hodgkinson Date: Mon, 25 Jan 2021 13:34:16 +1000 Subject: [PATCH] adding batch mode --- installer.sh | 98 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/installer.sh b/installer.sh index e0757d4..2c856b0 100644 --- a/installer.sh +++ b/installer.sh @@ -7,15 +7,57 @@ function info { echo -e "\e[32m[info] $*\e[39m"; } function warn { echo -e "\e[33m[warn] $*\e[39m"; } function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; } +BATCH_MODE=0 +# Parse command line parameters +while [[ $# -gt 0 ]]; do + arg="$1" + + case $arg in + -m|--machine) + MACHINE=$2 + shift + ;; + -d|--data-share) + DATA_SHARE=$2 + shift + ;; + -p|--prefix) + PREFIX=$2 + shift + ;; + -s|--sysconfdir) + SYSCONFDIR=$2 + shift + ;; + -b|--batch) + BATCH_MODE=1 + ;; + *) + error "Unrecognized option $1" + ;; + esac + shift +done + +PREFIX=${PREFIX:-/usr} +SYSCONFDIR=${SYSCONFDIR:-/etc} +DATA_SHARE=${DATA_SHARE:-$PREFIX/share/hassio} +CONFIG=$SYSCONFDIR/hassio.json + + warn "" warn "If you want more control over your own system, run" warn "Home Assistant as a VM or run Home Assistant Core" warn "via a Docker container." warn "" -warn "If you want to abort, hit ctrl+c within 10 seconds..." -warn "" +if [ $BATCH_MODE -eq 0 ]; then + warn "If you want to abort, hit ctrl+c within 10 seconds..." + warn "" -sleep 10 + sleep 10 +else + warn "Batch mode enabled, continuing..." +fi ARCH=$(uname -m) @@ -102,52 +144,24 @@ if [ ! -f "$FILE_NM_CONNECTION" ]; then fi warn "Changes are needed to the /etc/network/interfaces file" -info "If you have modified the network on the host manualy, those can now be overwritten" -info "If you do not overwrite this now you need to manually adjust it later" -info "Do you want to proceed with overwriting the /etc/network/interfaces file? [N/y] " -read answer < /dev/tty +if [ $BATCH_MODE -eq 0 ]; then + info "If you have modified the network on the host manualy, those can now be overwritten" + info "If you do not overwrite this now you need to manually adjust it later" + info "Do you want to proceed with overwriting the /etc/network/interfaces file? [N/y] " + read answer < /dev/tty -if [[ "$answer" =~ "y" ]] || [[ "$answer" =~ "Y" ]]; then - info "Replacing /etc/network/interfaces" + if [[ "$answer" =~ "y" ]] || [[ "$answer" =~ "Y" ]]; then + info "Replacing /etc/network/interfaces" + curl -sL "${URL_INTERFACES}" > "${FILE_INTERFACES}"; + fi +else + info "Batch mode enabled, replacing /etc/network/interfaces" curl -sL "${URL_INTERFACES}" > "${FILE_INTERFACES}"; fi info "Restarting NetworkManager" systemctl restart "${SERVICE_NM}" -# Parse command line parameters -while [[ $# -gt 0 ]]; do - arg="$1" - - case $arg in - -m|--machine) - MACHINE=$2 - shift - ;; - -d|--data-share) - DATA_SHARE=$2 - shift - ;; - -p|--prefix) - PREFIX=$2 - shift - ;; - -s|--sysconfdir) - SYSCONFDIR=$2 - shift - ;; - *) - error "Unrecognized option $1" - ;; - esac - shift -done - -PREFIX=${PREFIX:-/usr} -SYSCONFDIR=${SYSCONFDIR:-/etc} -DATA_SHARE=${DATA_SHARE:-$PREFIX/share/hassio} -CONFIG=$SYSCONFDIR/hassio.json - # Generate hardware options case $ARCH in "i386" | "i686")