53c16be8790e4ef94c583fad693f0ec73be93712
[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 if [ -x /sbin/syslogd ]; then
29 local args log_ip log_size log_port log_type log_file
30 config_get log_ip "$cfg" log_ip
31 config_get log_size "$cfg" log_size 16
32 config_get log_port "$cfg" log_port 514
33 config_get log_type "$cfg" log_type circular
34 config_get log_file "$cfg" log_file "/var/log/messages"
35 args="${log_ip:+-L -R ${log_ip}:${log_port}} ${conloglevel:+-l $conloglevel}"
36 if [ "$log_type" = "file" ]; then
37 args="$args -s $log_size -O $log_file -S"
38 else
39 args="$args -C${log_size}"
40 fi
41 service_start /sbin/syslogd $args
42 fi
43 if [ -x /sbin/klogd ]; then
44 config_get klogconloglevel "$cfg" klogconloglevel
45 args="${klogconloglevel:+-c $klogconloglevel}"
46 service_start /sbin/klogd $args
47 fi
48 }
49
50 apply_uci_config() {
51 sh -c '. /etc/functions.sh; include /lib/config; uci_apply_defaults'
52 }
53
54 start() {
55 [ -f /proc/mounts ] || /sbin/mount_root
56 [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
57 [ -f /proc/net/vlan/config ] && vconfig set_name_type DEV_PLUS_VID_NO_PAD
58
59 mkdir -p /var/run
60 mkdir -p /var/log
61 mkdir -p /var/lock
62 mkdir -p /var/state
63 mkdir -p /tmp/.uci
64 chmod 0700 /tmp/.uci
65 touch /var/log/wtmp
66 touch /var/log/lastlog
67 touch /tmp/resolv.conf.auto
68 ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
69 grep -q debugfs /proc/filesystems && mount -t debugfs debugfs /sys/kernel/debug
70 [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
71
72 load_modules /etc/modules.d/*
73
74 /sbin/wifi detect > /tmp/wireless.tmp
75 [ -s /tmp/wireless.tmp ] && {
76 cat /tmp/wireless.tmp >> /etc/config/wireless
77 }
78 rm -f /tmp/wireless.tmp
79
80 apply_uci_config
81 config_load system
82 config_foreach system_config system
83
84 killall -q hotplug2
85 [ -x /sbin/hotplug2 ] && /sbin/hotplug2 --override --persistent \
86 --set-rules-file /etc/hotplug2.rules \
87 --max-children 1 >/dev/null 2>&1 &
88
89 # the coldplugging of network interfaces needs to happen later, so we do it manually here
90 for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do
91 /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug-call net
92 done
93
94 # create /dev/root if it doesn't exist
95 [ -e /dev/root -o -h /dev/root ] || {
96 rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline)
97 [ -n "$rootdev" ] && ln -s "$rootdev" /dev/root
98 }
99
100 # another round of USB coldplugging to kick devices into operation which lacked drivers before
101 for dev in /sys/bus/usb/devices/*/uevent; do
102 [ -e "$dev" ] && echo -n add > "$dev"
103 done
104 }
105
106 stop() {
107 service_stop /sbin/klogd
108 service_stop /sbin/syslogd
109 }
This page took 0.056087 seconds and 3 git commands to generate.