mirror of
https://github.com/home-assistant/operating-system.git
synced 2026-09-26 11:33:43 +01:00
The persistent timesyncd configuration is a single bind-mounted file over /etc/systemd/timesyncd.conf. The NTP configuration through OS Agent (home-assistant/os-agent#207) attempted to do atomic updates, but a temporary file cannot be created next to it in the read-only /etc/systemd, and replacing the file in the overlay directly changes the inode, so the bind mount keeps pointing to the old content. Also, a persisted copy of the whole file means changes to the shipped defaults never reach existing installations. Bind-mount the /etc/systemd/timesyncd.conf.d directory from the overlay instead and keep the shipped timesyncd.conf read-only. Configuration is layered as drop-ins, from lowest priority to higher: * 10-ntp.conf (in /run): NTP servers from DHCP * 20-custom.conf: timesyncd.conf imported from the CONFIG partition * 50-os-agent.conf: NTP servers set through the OS Agent D-Bus API On upgrade, settings from the previously persisted timesyncd.conf other than the shipped defaults are moved to 20-custom.conf. This migration can be removed later (with #4986). 50-os-agent.conf should be only managed by OS Agent, so we don't need to care about user's edits. Finally, if needed, drop-ins with higher priorities can be added for complex customizations. Refs home-assistant/supervisor#6278
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
mkdir -p /mnt/overlay/etc/
|
|
|
|
# Network
|
|
mkdir -p /mnt/overlay/etc/NetworkManager/system-connections
|
|
|
|
if [ ! -f /mnt/overlay/etc/hostname ]; then
|
|
cp -fp /etc/hostname /mnt/overlay/etc/hostname
|
|
fi
|
|
|
|
if [ ! -f /mnt/overlay/etc/hosts ]; then
|
|
cp -fp /etc/hosts /mnt/overlay/etc/hosts
|
|
fi
|
|
|
|
# TimeSync
|
|
TIMESYNCD_CONF_DIR=/mnt/overlay/etc/systemd/timesyncd.conf.d
|
|
mkdir -p "${TIMESYNCD_CONF_DIR}"
|
|
|
|
# Move settings from a persisted copy of timesyncd.conf into a drop-in,
|
|
# can be removed in OS 19.0
|
|
if [ -f /mnt/overlay/etc/systemd/timesyncd.conf ]; then
|
|
# Drop the section header, the shipped defaults, comments and blank lines
|
|
SETTINGS=$(grep -Ev '^(\[Time\]|FallbackNTP=time\.cloudflare\.com|ConnectionRetrySec=10|[[:space:]]*#.*|[[:space:]]*)$' \
|
|
/mnt/overlay/etc/systemd/timesyncd.conf)
|
|
if [ -n "${SETTINGS}" ] && [ ! -f "${TIMESYNCD_CONF_DIR}/20-custom.conf" ]; then
|
|
printf '[Time]\n%s\n' "${SETTINGS}" > "${TIMESYNCD_CONF_DIR}/20-custom.conf"
|
|
fi
|
|
rm -f /mnt/overlay/etc/systemd/timesyncd.conf
|
|
fi
|
|
|
|
if [ ! -L /mnt/overlay/etc/localtime ]; then
|
|
ln -sf /usr/share/zoneinfo/Etc/UTC /mnt/overlay/etc/localtime
|
|
fi
|
|
|
|
# Console
|
|
if [ ! -f /mnt/overlay/etc/vconsole.conf ]; then
|
|
echo "KEYMAP=us" > /mnt/overlay/etc/vconsole.conf
|
|
fi
|