chiark / gitweb /
c7383690813f877e159a1a54cf0b420c6b1bf461
[elogind.git] / etc / init.d / udev.init.lfs
1 #!/bin/sh
2 #
3 # LinuxFromScratch udev init script
4 #  derived from original RedHat udev init script
5 #  2003, 2004 by Michael Buesch <mbuesch@freenet.de>
6 #
7
8 source /etc/sysconfig/rc
9 source $rc_functions
10 source /etc/udev/udev.conf
11
12 sysfs_dir="/sys"
13 bin="/sbin/udev"
14
15
16 run_udev ()
17 {
18         # handle block devices and their partitions
19         for i in ${sysfs_dir}/block/*; do
20                 # add each drive
21                 export DEVPATH=${i#${sysfs_dir}}
22                 $bin block &
23
24                 # add each partition, on each device
25                 for j in $i/*; do
26                         if [ -f $j/dev ]; then
27                                 export DEVPATH=${j#${sysfs_dir}}
28                                 $bin block &
29                         fi
30                 done
31         done
32         # all other device classes
33         for i in ${sysfs_dir}/class/*; do
34                 for j in $i/*; do
35                         if [ -f $j/dev ]; then
36                                 export DEVPATH=${j#${sysfs_dir}}
37                                 CLASS=`echo ${i#${sysfs_dir}} | \
38                                         cut --delimiter='/' --fields=3-`
39                                 $bin $CLASS &
40                         fi
41                 done
42         done
43         return 0
44 }
45
46 case "$1" in
47         start)
48                 echo "Creating initial udev device nodes ..."
49                 if [ ! -d $sysfs_dir ]; then
50                         echo "sysfs_dir $sysfs_dir does not exist!"
51                         print_status failure
52                         exit 1
53                 fi
54                 if [ ! -d $udev_root ]; then
55                         mkdir $udev_root
56                         if [ $? -ne 0 ]; then
57                                 print_status failure
58                                 exit 1
59                         fi
60                 fi
61
62                 # propogate /udev from /sys - we only need this while we do not
63                 # have initramfs and an early user-space with which to do early
64                 # device bring up
65                 export ACTION=add
66                 run_udev
67                 evaluate_retval
68                 ;;
69         stop)
70                 echo "Removing udev device nodes ..."
71                 export ACTION=remove
72                 run_udev
73                 evaluate_retval
74                 ;;
75         reload)
76                 # nothing to do here
77                 ;;
78         restart)
79                 $0 stop
80                 sleep 1
81                 $0 start
82                 ;;
83         status)
84                 if [ -d $udev_dir ]; then
85                         echo "the udev device node directory exists"
86                 else
87                         echo "the udev device node directory does not exist"
88                 fi
89                 ;;
90         *)
91                 echo "Usage: $0 {start|stop|restart|status}"
92                 exit 1
93                 ;;
94 esac
95 exit 0