hassio-supervised-installer/homeassistant-supervised/DEBIAN/preinst
yayg 415a371bb2
Leave resolving configuration to the system
While installing debian comes with a configuration for resolving and
resolved is not necessary and causing problems in some cases (no IPv6,
custom network setup, etc...)
Thus it might be better to leave this configuration to the system
administrator while installing the supervised way.
2024-05-02 11:56:08 +02:00

80 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
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; }
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 ""
# Check if we are running on a supported OS
BYPASS_OS_CHECK=${BYPASS_OS_CHECK:-false}
supported_os=("Debian GNU/Linux 11 (bullseye)" "Debian GNU/Linux 12 (bookworm)")
CURRENT_OS=$(lsb_release -d | awk -F"\t" '{print $2}')
os_supported=false
for os in "${supported_os[@]}"; do
if [[ $os == "$CURRENT_OS" ]]; then
os_supported=true
break
fi
done
if [[ $os_supported == false ]]; then
if [[ $BYPASS_OS_CHECK != "true" ]]; then
error "${CURRENT_OS} is not supported!"
fi
warn "Bypassing OS check..."
warn "${CURRENT_OS} is not supported!"
warn "Please DO NOT report issues regarding this OS!"
fi
# Check if we are running on a supported architecture
ARCH=$(uname -m)
if [[ ! "i386|i686|x86_64|arm|armv6l|armv7l|aarch64" == *"$ARCH"* ]]; then
error "${ARCH} is not supported!"
fi
# Check if Modem Manager is enabled
if systemctl is-enabled ModemManager.service &> /dev/null; then
warn "ModemManager service is enabled. This might cause issue when using serial devices."
fi
# Check dmesg access
if [[ "$(sysctl --values kernel.dmesg_restrict)" != "0" ]]; then
info "Fix kernel dmesg restriction"
echo 0 > /proc/sys/kernel/dmesg_restrict
echo "kernel.dmesg_restrict=0" >> /etc/sysctl.conf
fi
# If the hassio_supervisor service is running or exists, stop it
if [[ "$(systemctl is-active hassio-supervisor.service)" == "active" ]]; then
info "Stopping hassio_supervisor service"
systemctl stop hassio-supervisor.service
fi
# If the hassio_apparmor service is running or exists, stop it
if [[ "$(systemctl is-active hassio-apparmor.service)" == "active" ]]; then
info "Stopping hassio_apparmor service"
systemctl stop hassio-apparmor.service
fi
# Check for existing hassio_supervisor container and destroy it
if [[ "$(docker ps -aq -f name=hassio_supervisor)" ]]; then
# ensure the hassio_supervisor service is stopped
info "Removing existing hassio_supervisor container"
docker container rm --force hassio_supervisor > /dev/null
fi
dpkg-divert --package homeassistant-supervised --add --rename \
--divert /etc/NetworkManager/NetworkManager.conf.real /etc/NetworkManager/NetworkManager.conf
dpkg-divert --package homeassistant-supervised --add --rename \
--divert /etc/NetworkManager/system-connections/default.real /etc/NetworkManager/system-connections/default
dpkg-divert --package homeassistant-supervised --add --rename \
--divert /etc/docker/daemon.json.real /etc/docker/daemon.json