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