Files
operating-system/buildroot-external/rootfs-overlay/usr/sbin/hassos-config
2018-07-02 23:53:07 +02:00

67 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
if ! findfs LABEL="CONFIG" > /dev/null; then
echo "[Warning] No config partition found"
exit 0
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
if [ -d /mnt/config/network ]; then
echo "[Info] Update NetworkManager connections!"
rm -rf /etc/NetworkManager/system-connections/*
cp -f /mnt/config/network/* /etc/NetworkManager/system-connections/
chmod 600 /etc/NetworkManager/system-connections/*
nmcli con reload
fi
##
# Modules
if [ -d /mnt/config/modules ]; then
echo "[Info] Update Modules configuration!"
rm -rf /etc/modules-load.d/*
cp -f /mnt/config/modules/* /etc/modules-load.d/*
fi
##
# SSH know hosts
if [ -f /mnt/config/authorized_keys ]; then
echo "[Info] Update SSH authorized_keys!"
cp -f /mnt/config/authorized_keys /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
systemctl start dropbear
else
rm -f /root/.ssh/authorized_keys
systemctl stop dropbear
fi
##
# Firmware update
UPTIME=$(awk '{printf "%0.f", $1}' /proc/uptime)
if ls /mnt/config/*.raucb > /dev/null && [ ${UPTIME} -ge 180 ]; then
echo "[Info] Performe a firmware update"
rauc_filename=$(ls /mnt/config/*.raucb | head -n 1)
if rauc install ${rauc_filename}; then
echo "[Info] Firmware update success"
systemctl reboot
else
echo "[Error] Firmware update fails"
fi
fi
# Cleanup config partition
systemctl stop mnt-config.mount