chiark / gitweb /
[PATCH] LSB init script and other stuff
[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 . /etc/udev/udev.conf
11
12 sysfs_dir=/sys
13 bin=/sbin/udev
14
15 run_udev () {
16         # handle block devices and their partitions
17         for i in ${sysfs_dir}/block/*; do
18                 # add each drive
19                 export DEVPATH=${i#${sysfs_dir}}
20                 $bin block &
21
22                 # add each partition, on each device
23                 for j in $i/*; do
24                         if [ -f $j/dev ]; then
25                                 export DEVPATH=${j#${sysfs_dir}}
26                                 $bin block &
27                         fi
28                 done
29         done
30         # all other device classes
31         for i in ${sysfs_dir}/class/*; do
32                 for j in $i/*; do
33                         if [ -f $j/dev ]; then
34                                 export DEVPATH=${j#${sysfs_dir}}
35                                 CLASS=`echo ${i#${sysfs_dir}} | \
36                                         cut --delimiter='/' --fields=3-`
37                                 $bin $CLASS &
38                         fi
39                 done
40         done
41 }
42
43
44 case "$1" in
45   start)
46         if [ ! -d $sysfs_dir ]; then
47                 exit 1
48         fi
49         if [ ! -d $udev_root ]; then
50                 mkdir $udev_root
51         fi
52         # propogate /udev from /sys - we only need this while we do not
53         # have initramfs and an early user-space with which to do early
54         # device bring up
55         action "Creating initial udev device nodes: " /bin/true
56         export ACTION=add
57         run_udev 
58         ;;
59   stop)
60         # be careful
61         action "Removing udev device nodes: " /bin/true
62         export ACTION=remove
63         run_udev 
64         ;;
65   status)
66         if [ -d $udev_root ]; then
67                 echo "the udev device node directory exists"
68         else
69                 echo "the udev device node directory does not exist"
70         fi
71         ;;
72   restart)
73         $0 stop
74         $0 start
75         ;;
76   reload)
77         # nothing to do here
78         ;;
79   *)
80         echo "Usage: $0 {start|stop|status|restart}"
81         exit 1
82 esac
83
84 exit 0