chiark / gitweb /
[PATCH] Make udev/udevstart be one binary
[elogind.git] / etc / init.d / udev.debian
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 # 2003-12-23: - some tweaks to run silently on a debian system
9 # 2003-12-30: - manage creation (and deletion) of /proc/self/fd->fd and 
10 #               fd/[0,1,2]->std[in,out,err] links
11 #             - creation and deletion of /proc/kcore->core link 
12 #             - creation and deletion of /proc/asound/oss/sndstat->sndstat link 
13
14
15
16 udev_dir=/udev
17 sysfs_dir=/sys
18 bin=/sbin/udev
19
20 action () {
21         if test $2 ; then
22                 echo $1
23         else
24                 echo "Assertion $2 failed"
25                 echo "Aborting"
26                 exit 1
27         fi
28 }
29
30 run_udev () {
31         # handle block devices and their partitions
32         for i in ${sysfs_dir}/block/*; do
33                 # add each drive
34                 export DEVPATH=${i#${sysfs_dir}}
35                 $bin block &
36
37                 # add each partition, on each device
38                 for j in $i/*; do
39                         if [ -f $j/dev ]; then
40                                 export DEVPATH=${j#${sysfs_dir}}
41                                 $bin block &
42                         fi
43                 done
44         done
45         # all other device classes
46         for i in ${sysfs_dir}/class/*; do
47                 for j in $i/*; do
48                         if [ -f $j/dev ]; then
49                                 export DEVPATH=${j#${sysfs_dir}}
50                                 CLASS=`echo ${i#${sysfs_dir}} | \
51                                         cut --delimiter='/' --fields=3-`
52                                 $bin $CLASS &
53                         fi
54                 done
55         done
56 }
57
58
59 case "$1" in
60   start)
61         if [ ! -d $udev_dir ]; then
62                 mkdir $udev_dir
63         fi
64         # don't use udev if sysfs is not mounted
65         if [ ! -d $sysfs_dir/block ]; then
66                 exit 1
67         fi
68         # propogate /udev from /sys - we only need this while we do not
69         # have initramfs and an early user-space with which to do early
70         # device bring up
71         action "Creating initial udev device nodes: " /bin/true
72         export ACTION=add
73         run_udev 
74
75         # hack to create stdin node
76         cd $udev_dir && ln -s /proc/self/fd fd
77         cd $udev_dir && ln -s fd/0 stdin
78         cd $udev_dir && ln -s fd/1 stdout
79         cd $udev_dir && ln -s fd/2 stderr
80         cd $udev_dir && ln -s /proc/kcore core
81         cd $udev_dir && ln -s /proc/asound/oss/sndstat sndstat
82         ;;
83   stop)
84         # be careful
85         action "Removing udev device nodes: " /bin/true
86         export ACTION=remove
87         run_udev 
88         rm -f $udev_dir/sndstat
89         rm -f $udev_dir/core
90         rm -f $udev_dir/stderr
91         rm -f $udev_dir/stdout
92         rm -f $udev_dir/stdin
93         rm -f $udev_dir/fd
94         ;;
95   status)
96         if [ -d $udev_dir ]; then
97                 echo "the udev device node directory exists"
98         else
99                 echo "the udev device node directory does not exist"
100         fi
101         ;;
102   restart)
103         $0 stop
104         $0 start
105         ;;
106   reload)
107         # nothing to do here
108         ;;
109   *)
110         echo "Usage: $0 {start|stop|status|restart}"
111         exit 1
112 esac
113
114 exit 0