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