procd: Add wrapper for uci_validate_section()
[openwrt/staging/lynxis.git] / package / base-files / files / etc / init.d / system
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2014 OpenWrt.org
3
4 START=10
5 USE_PROCD=1
6
7 validate_system_section()
8 {
9 uci_load_validate system system "$1" "$2" \
10 'hostname:string:OpenWrt' \
11 'conloglevel:uinteger' \
12 'buffersize:uinteger' \
13 'timezone:string:UTC' \
14 'zonename:string'
15 }
16
17 system_config() {
18 [ "$2" = 0 ] || {
19 echo "validation failed"
20 return 1
21 }
22
23 echo "$hostname" > /proc/sys/kernel/hostname
24 [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
25 echo "$timezone" > /tmp/TZ
26 [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && \
27 ln -sf "/usr/share/zoneinfo/$zonename" /tmp/localtime && rm -f /tmp/TZ
28
29 # apply timezone to kernel
30 date -k
31 }
32
33 reload_service() {
34 config_load system
35 config_foreach validate_system_section system system_config
36 }
37
38 service_triggers()
39 {
40 procd_add_reload_trigger "system"
41 procd_add_validation validate_system_section
42 }
43
44 start_service() {
45 reload_service
46 }