chiark / gitweb /
[PATCH] fix udev init.d script to handle all class devices in sysfs.
[elogind.git] / etc / init.d / udev
1 #! /bin/bash
2 #
3 # random        init script to setup /udev
4 #
5 # chkconfig: 2345 20 80
6 # description: manage user-space device nodes in /udev
7
8 . /etc/rc.d/init.d/functions
9
10 udev_dir=/udev
11 sysfs_dir=/sys
12 bin=/sbin/udev
13
14 case "$1" in
15   start)
16         if [ ! -d $udev_dir ]; then
17                 mkdir $udev_dir
18         fi
19         if [ ! -d $sysfs_dir ]; then
20                 exit 1
21         fi
22         # propogate /udev from /sys - we only need this while we do not
23         # have initramfs and an early user-space with which to do early
24         # device bring up
25         action "Creating initial udev device nodes: " /bin/true
26         export ACTION=add
27         # add block devices and their partitions
28         for i in ${sysfs_dir}/block/*; do
29                 # add each drive
30                 export DEVPATH=${i#${sysfs_dir}}
31                 $bin block
32
33                 # add each partition, on each device
34                 for j in $i/*; do
35                         if [ -f $j/dev ]; then
36                                 export DEVPATH=${j#${sysfs_dir}}
37                                 $bin block
38                         fi
39                 done
40         done
41         # all other device classes
42         for i in ${sysfs_dir}/class/*; do
43                 for j in $i/*; do
44                         if [ -f $j/dev ]; then
45                                 export DEVPATH=${j#${sysfs_dir}}
46                                 CLASS=`echo ${i#${sysfs_dir}} | \
47                                         cut --delimiter='/' --fields=3-`
48                                 $bin $CLASS
49                         fi
50                 done
51         done
52         ;;
53   stop)
54         # be careful
55         if [ $udev_dir -a "$udev_dir" != "/" ]; then
56                 # clear out /udev
57                 rm -rf ${udev_dir}/*
58         fi
59         ;;
60   status)
61         if [ -d $udev_dir ]; then
62                 echo "the udev device node directory exists"
63         else
64                 echo "the udev device node directory does not exist"
65         fi
66         ;;
67   restart|reload)
68         # nothing to do here
69         ;;
70   *)
71         echo "Usage: $0 {start|stop|status}"
72         exit 1
73 esac
74
75 exit 0