base-files: move sysctl init after boot
[openwrt.git] / package / base-files / files / etc / init.d / boot
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
3
4 START=10
5 STOP=98
6
7 system_config() {
8         local cfg="$1"
9
10         local hostname conloglevel timezone
11
12         config_get hostname "$cfg" hostname 'OpenWrt'
13         echo "$hostname" > /proc/sys/kernel/hostname
14
15         config_get conloglevel "$cfg" conloglevel
16         config_get buffersize "$cfg" buffersize
17         [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
18
19         config_get timezone "$cfg" timezone 'UTC'
20         echo "$timezone" > /tmp/TZ
21
22         config_get zonename "$cfg" zonename
23         [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && ln -s "/usr/share/zoneinfo/$zonename" /tmp/localtime
24
25         # apply timezone to kernel
26         date -k
27 }
28
29 apply_uci_config() {
30         sh -c '. /lib/functions.sh; include /lib/config; uci_apply_defaults'
31 }
32
33 start() {
34         [ -f /proc/mounts ] || /sbin/mount_root
35         [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
36         [ -f /proc/net/vlan/config ] && vconfig set_name_type DEV_PLUS_VID_NO_PAD
37
38         mkdir -p /var/run
39         mkdir -p /var/log
40         mkdir -p /var/lock
41         mkdir -p /var/state
42         mkdir -p /tmp/.uci
43         chmod 0700 /tmp/.uci
44         touch /var/log/wtmp
45         touch /var/log/lastlog
46         touch /tmp/resolv.conf.auto
47         ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
48         grep -q debugfs /proc/filesystems && mount -o noatime -t debugfs debugfs /sys/kernel/debug
49         [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
50
51         load_modules /etc/modules.d/*
52
53         # allow wifi modules time to settle
54         sleep 1
55
56         /sbin/wifi detect > /tmp/wireless.tmp
57         [ -s /tmp/wireless.tmp ] && {
58                 cat /tmp/wireless.tmp >> /etc/config/wireless
59         }
60         rm -f /tmp/wireless.tmp
61
62         apply_uci_config
63         config_load system
64         config_foreach system_config system
65
66         # create /dev/root if it doesn't exist
67         [ -e /dev/root -o -h /dev/root ] || {
68                 rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline)
69                 [ -n "$rootdev" ] && ln -s "$rootdev" /dev/root
70         }
71
72         # early sysctl to avoid networking races
73         if [ -d /proc/sys/net/ipv6/conf ]; then
74                 for i in /proc/sys/net/ipv6/conf/*/accept_ra; do
75                         echo 0 > $i
76                 done
77         fi
78 }