chiark / gitweb /
[PATCH] remove the .udev.tdb when installing or uninstalling to be safe.
[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
53         # remove the database if it is there as we always want to start fresh
54         if [ -f $udev_root/.udev.tdb ]; then
55                 rm -f $udev_root/.udev.tdb
56         fi
57
58         # propogate /udev from /sys - we only need this while we do not
59         # have initramfs and an early user-space with which to do early
60         # device bring up
61         action "Creating initial udev device nodes: " /bin/true
62         export ACTION=add
63         run_udev 
64         ;;
65   stop)
66         # be careful
67         action "Removing udev device nodes: " /bin/true
68         export ACTION=remove
69         run_udev 
70         ;;
71   status)
72         if [ -d $udev_root ]; then
73                 echo "the udev device node directory exists"
74         else
75                 echo "the udev device node directory does not exist"
76         fi
77         ;;
78   restart)
79         $0 stop
80         $0 start
81         ;;
82   reload)
83         # nothing to do here
84         ;;
85   *)
86         echo "Usage: $0 {start|stop|status|restart}"
87         exit 1
88 esac
89
90 exit 0