mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-07-27 15:06:29 +00:00
OS: Config importer support now also boot partition (#212)
* OS: Config importer support now also boot partition * Update configuration.md * Cleanup config after import * Update hassos-config
This commit is contained in:
parent
295a05e5a0
commit
e297324a0d
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
## Automatic
|
## Automatic
|
||||||
|
|
||||||
You can use a USB drive with HassOS to configure network options, ssh access to the host, and to install updates.
|
You can use an USB drive with HassOS to configure network options, SSH access to the host and to install updates.
|
||||||
Format a USB stick with FAT32/EXT4/NTFS and name it `CONFIG`. Use the following directory structure within the USB drive:
|
Format a USB stick with FAT32/EXT4/NTFS and name it `CONFIG`. Alternative you can create a `CONFIG` folder inside boot partition. Use the following directory structure within the USB drive:
|
||||||
|
|
||||||
```
|
```
|
||||||
network/
|
network/
|
||||||
|
@ -1,69 +1,88 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if ! findfs LABEL="CONFIG" > /dev/null; then
|
BOOT_CONFIG="/mnt/boot/CONFIG"
|
||||||
|
USB_CONFIG="/mnt/config"
|
||||||
|
CONFIG_DIR=""
|
||||||
|
USE_USB=0
|
||||||
|
|
||||||
|
# Check and mount usb CONFIG to folder
|
||||||
|
if findfs LABEL="CONFIG" > /dev/null 2>&1; then
|
||||||
|
echo "[Info] Use USB stick for import CONFIG"
|
||||||
|
|
||||||
|
systemctl start mnt-config.mount
|
||||||
|
if ! systemctl -q is-active mnt-config.mount; then
|
||||||
|
echo "[Error] Can't mount config partition"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
USE_USB=1
|
||||||
|
CONFIG_DIR=${USB_CONFIG}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use boot CONFIG folder
|
||||||
|
if [ ${USE_USB} = 0 ] && [ -d ${BOOT_CONFIG} ]; then
|
||||||
|
echo "[Info] Use boot partition for import CONFIG"
|
||||||
|
CONFIG_DIR=${BOOT_CONFIG}
|
||||||
|
elif [ ${USE_USB} = 0 ]; then
|
||||||
echo "[Warning] No config partition found"
|
echo "[Warning] No config partition found"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mount config folder
|
|
||||||
systemctl start mnt-config.mount
|
|
||||||
if ! systemctl -q is-active mnt-config.mount; then
|
|
||||||
echo "[Error] Can't mount config partition"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# NetworkManager
|
# NetworkManager
|
||||||
if [ -d /mnt/config/network ]; then
|
if [ -d "${CONFIG_DIR}/network" ]; then
|
||||||
echo "[Info] Update NetworkManager connections!"
|
echo "[Info] Update NetworkManager connections!"
|
||||||
|
|
||||||
rm -rf /etc/NetworkManager/system-connections/*
|
rm -rf /etc/NetworkManager/system-connections/*
|
||||||
cp -f /mnt/config/network/* /etc/NetworkManager/system-connections/
|
cp -f ${CONFIG_DIR}/network/* /etc/NetworkManager/system-connections/
|
||||||
chmod 600 /etc/NetworkManager/system-connections/*
|
chmod 600 /etc/NetworkManager/system-connections/*
|
||||||
|
|
||||||
nmcli con reload
|
nmcli con reload > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##
|
##
|
||||||
# Modules
|
# Modules
|
||||||
if [ -d /mnt/config/modules ]; then
|
if [ -d "${CONFIG_DIR}/modules" ]; then
|
||||||
echo "[Info] Update Modules configuration!"
|
echo "[Info] Update Modules configuration!"
|
||||||
|
|
||||||
rm -rf /etc/modules-load.d/*
|
rm -rf /etc/modules-load.d/*
|
||||||
cp -f /mnt/config/modules/* /etc/modules-load.d/*
|
cp -f ${CONFIG_DIR}/modules/* /etc/modules-load.d/*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##
|
##
|
||||||
# Udev
|
# Udev
|
||||||
if [ -d /mnt/config/udev ]; then
|
if [ -d "${CONFIG_DIR}/udev" ]; then
|
||||||
echo "[Info] Update Udev configuration!"
|
echo "[Info] Update Udev configuration!"
|
||||||
|
|
||||||
rm -rf /etc/udev/rules.d/*
|
rm -rf /etc/udev/rules.d/*
|
||||||
cp -f /mnt/config/udev/* /etc/udev/rules.d/*
|
cp -f ${CONFIG_DIR}/udev/* /etc/udev/rules.d/*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##
|
##
|
||||||
# SSH know hosts
|
# SSH know hosts
|
||||||
if [ -f /mnt/config/authorized_keys ]; then
|
if [ -f "${CONFIG_DIR}/authorized_keys" ]; then
|
||||||
echo "[Info] Update SSH authorized_keys!"
|
echo "[Info] Update SSH authorized_keys!"
|
||||||
|
|
||||||
cp -f /mnt/config/authorized_keys /root/.ssh/authorized_keys
|
cp -f ${CONFIG_DIR}/authorized_keys /root/.ssh/authorized_keys
|
||||||
chmod 600 /root/.ssh/authorized_keys
|
chmod 600 /root/.ssh/authorized_keys
|
||||||
|
|
||||||
systemctl start dropbear
|
systemctl start dropbear > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
|
echo "[Info] Stop SSH debug access"
|
||||||
|
|
||||||
rm -f /root/.ssh/authorized_keys
|
rm -f /root/.ssh/authorized_keys
|
||||||
systemctl stop dropbear
|
systemctl stop dropbear > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##
|
##
|
||||||
# Firmware update
|
# Firmware update / Only USB
|
||||||
UPTIME=$(awk '{printf "%0.f", $1}' /proc/uptime)
|
UPTIME=$(awk '{printf "%0.f", $1}' /proc/uptime)
|
||||||
if ls /mnt/config/*.raucb > /dev/null && [ ${UPTIME} -ge 180 ]; then
|
if ls ${USB_CONFIG}/*.raucb > /dev/null 2>&1 && [ ${UPTIME} -ge 180 ]; then
|
||||||
echo "[Info] Performe a firmware update"
|
echo "[Info] Performe a firmware update"
|
||||||
|
|
||||||
rauc_filename=$(ls /mnt/config/*.raucb | head -n 1)
|
rauc_filename=$(ls ${USB_CONFIG}/*.raucb | head -n 1)
|
||||||
if rauc install ${rauc_filename}; then
|
if rauc install "${rauc_filename}"; then
|
||||||
echo "[Info] Firmware update success"
|
echo "[Info] Firmware update success"
|
||||||
systemctl reboot
|
systemctl reboot
|
||||||
else
|
else
|
||||||
@ -72,4 +91,8 @@ if ls /mnt/config/*.raucb > /dev/null && [ ${UPTIME} -ge 180 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup config partition
|
# Cleanup config partition
|
||||||
systemctl stop mnt-config.mount
|
if [ ${USE_USB} = 1 ]; then
|
||||||
|
systemctl stop mnt-config.mount
|
||||||
|
else
|
||||||
|
rm -rf ${BOOT_CONFIG}
|
||||||
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user