openwrt/package/base-files/files/etc/init.d/system
Rosen Penev 8af62ede18 base-files: fix zoneinfo support
The system init script currently sets /tmp/localinfo when zoneinfo is
populated. However, zoneinfo has spaces in it whereas the actual files
have _ instead of spaces. This made the if condition never return true.

Example failure when removing the if condition:

/tmp/localtime -> /usr/share/zoneinfo/America/Los Angeles

This file does not exist. America/Los_Angeles does.

Ran through shfmt -w -ci -bn -sr -s

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-06-23 14:10:27 -10:00

49 lines
1.0 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (C) 2014 OpenWrt.org
START=10
USE_PROCD=1
validate_system_section() {
uci_load_validate system system "$1" "$2" \
'hostname:string:OpenWrt' \
'conloglevel:uinteger' \
'buffersize:uinteger' \
'timezone:string:UTC' \
'zonename:string'
}
system_config() {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
echo "$hostname" > /proc/sys/kernel/hostname
[ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
rm -f /tmp/TZ
if [ -n "$zonename" ]; then
local zname=$(echo "$zonename" | tr ' ' _)
[ -f "/usr/share/zoneinfo/$zname" ] && ln -sf "/usr/share/zoneinfo/$zname" /tmp/localtime
else
echo "$timezone" > /tmp/TZ
fi
# apply timezone to kernel
hwclock -u --systz
}
reload_service() {
config_load system
config_foreach validate_system_section system system_config
}
service_triggers() {
procd_add_reload_trigger "system"
procd_add_validation validate_system_section
}
start_service() {
reload_service
}