Add option to run the installer unattended

Added an option so the installer script doesn't ask for input. Required for automated installations
This commit is contained in:
iuri aranda 2020-12-18 22:23:10 +01:00
parent e2a66e35d3
commit 1910ccbb86
2 changed files with 58 additions and 47 deletions

View file

@ -20,8 +20,10 @@ bash installer.sh
``` ```
### Command line arguments ### Command line arguments
| argument | default | description | | argument | default | description |
|--------------------|----------------------|--------------------------------------------------------| | ------------------ | -------------------- | -------------------------------------------------------------------------- |
| -a \| --auto | | Don't ask for input, assume yes to all questions. For automated installers |
| -m \| --machine | | On a special platform they need set a machine type use | | -m \| --machine | | On a special platform they need set a machine type use |
| -d \| --data-share | $PREFIX/share/hassio | data folder for hass.io installation | | -d \| --data-share | $PREFIX/share/hassio | data folder for hass.io installation |
| -p \| --prefix | /usr | Binary prefix for hass.io installation | | -p \| --prefix | /usr | Binary prefix for hass.io installation |

View file

@ -7,6 +7,38 @@ function info { echo -e "\e[32m[info] $*\e[39m"; }
function warn { echo -e "\e[33m[warn] $*\e[39m"; } function warn { echo -e "\e[33m[warn] $*\e[39m"; }
function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; } function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; }
# 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
;;
-a|--auto)
AUTO=1
;;
*)
error "Unrecognized option $1"
;;
esac
shift
done
if [ -z "$AUTO" ]; then
warn "" warn ""
warn "If you want more control over your own system, run" warn "If you want more control over your own system, run"
warn "Home Assistant as a VM or run Home Assistant Core" warn "Home Assistant as a VM or run Home Assistant Core"
@ -16,6 +48,7 @@ warn "If you want to abort, hit ctrl+c within 10 seconds..."
warn "" warn ""
sleep 10 sleep 10
fi
ARCH=$(uname -m) ARCH=$(uname -m)
@ -101,11 +134,15 @@ if [ ! -f "$FILE_NM_CONNECTION" ]; then
curl -sL "${URL_NM_CONNECTION}" > "${FILE_NM_CONNECTION}" curl -sL "${URL_NM_CONNECTION}" > "${FILE_NM_CONNECTION}"
fi fi
if [ -z "$AUTO" ]; then
warn "Changes are needed to the /etc/network/interfaces file" 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 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 "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] " info "Do you want to proceed with overwriting the /etc/network/interfaces file? [N/y] "
read answer < /dev/tty read answer < /dev/tty
else
answer="y"
fi
if [[ "$answer" =~ "y" ]] || [[ "$answer" =~ "Y" ]]; then if [[ "$answer" =~ "y" ]] || [[ "$answer" =~ "Y" ]]; then
info "Replacing /etc/network/interfaces" info "Replacing /etc/network/interfaces"
@ -115,34 +152,6 @@ fi
info "Restarting NetworkManager" info "Restarting NetworkManager"
systemctl restart "${SERVICE_NM}" 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} PREFIX=${PREFIX:-/usr}
SYSCONFDIR=${SYSCONFDIR:-/etc} SYSCONFDIR=${SYSCONFDIR:-/etc}
DATA_SHARE=${DATA_SHARE:-$PREFIX/share/hassio} DATA_SHARE=${DATA_SHARE:-$PREFIX/share/hassio}