]> git.pld-linux.org Git - packages/autofs.git/blob - autofs.init
- minimal hack to make it works. autofs5 has totally different syntax.
[packages/autofs.git] / autofs.init
1 #!/bin/sh
2 #
3 # autofs        automatically mounts filesystems when you use them,
4 #               and unmounts them later when you are not using them.
5 #
6 # chkconfig:    2345 72 08
7 #
8 # description:  Script for automount using a Sun-style "master map". \
9 #               We first look for a local /etc/autofs/auto.master, then a YP \
10 #               map with that name
11 #
12 # processname:  autofs
13 # config:       /etc/autofs/auto.master
14
15
16 # Source function library
17 . /etc/rc.d/init.d/functions
18
19 # Get network config
20 . /etc/sysconfig/network
21
22 # Demon specified configuration.
23 [ -f /etc/sysconfig/autofs ] && . /etc/sysconfig/autofs
24
25 # Check that networking is up.
26 if is_yes "${NETWORKING}"; then
27         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
28                 msg_network_down automounter
29                 exit 1
30         fi
31 else
32         exit 0
33 fi
34
35 DAEMON=/usr/sbin/automount
36
37 #
38 #       This function will build a list of automount commands to execute in
39 #       order # to activate all the mount points. It is used to figure out
40 #       the difference of automount points in case of a reload
41 #
42 getmounts()
43 {
44 #
45 # Check for local maps to be loaded
46 #
47 if [ -f /etc/autofs/auto.master ]; then
48         cat /etc/autofs/auto.master | sed -e '/^#/d' -e '/^$/d'| (
49         while read dir map options; do
50                 if [ ! -z "$dir" -a ! -z "$map" \
51                    -a x`echo "$map" | cut -c1` != 'x-' ]; then
52                         maptype=`echo $map | cut -f1 -d:`
53                         if [ "$maptype" = "$map" ]; then
54                         map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
55                         options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
56                         if [ -x $map ]; then
57                                 echo "$DAEMON --timeout ${TIMEOUT} ${OPTIONS} $dir program $map $options"
58                         elif [ -f $map ]; then
59                                 echo "$DAEMON --timeout ${TIMEOUT} ${OPTIONS} $dir file $map $options"
60                         else
61                                 echo "$DAEMON --timeout ${TIMEOUT} ${OPTIONS} $dir `basename $map` $options"
62                         fi
63                         else
64                                 map=`echo $map | cut -f2- -d:`
65                                 if [ ! -z "$map" ]; then
66                                         if [ "$maptype" = "file" ]; then
67                                                 map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
68                                         fi
69                                         echo "$DAEMON --timeout $TIMEOUT ${OPTIONS} $dir $maptype $map $options"
70                                 fi
71                         fi
72                 fi
73         done
74         )
75 fi
76
77 #
78 # Check for YellowPage maps to be loaded
79 #
80 if is_yes $USE_YP; then
81         if [ -e /usr/bin/ypcat ] && \
82            [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]; then
83                 ypcat -k auto.master | (
84                 while read dir map options; do
85                         if [ ! -z "$dir" -a ! -z "$map" \
86                            -a x`echo "$map" | cut -c1` != 'x-' ]; then
87                                 map=`echo "$map" | sed -e 's/^auto_/auto./'`
88                                 if echo $options | \
89                                    grep -- '-t' >/dev/null 2>&1; then
90                                         mountoptions="--timeout $(echo $options | \
91                                           sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
92                                 fi
93                                 options=`echo "$options" | sed -e '
94                                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
95                                   s/\(^\|[ \t]\)-/\1/g'`
96                                 echo "$DAEMON --timeout $TIMEOUT ${OPTIONS} $mountoptions \
97                                   $dir yp $map $options"
98                         fi
99                 done
100                 )
101         fi
102 fi
103 }
104
105 start() {
106         # Check if the service is already running?
107         if [ ! -f /var/lock/subsys/autofs ]; then
108                 msg_starting automounter
109                 busy
110 #               getmounts | sh
111                 $DAEMON --timeout $TIMEOUT /etc/autofs/auto.master
112                 RETVAL=$?
113                 [ $RETVAL -eq 0 ] && ok || fail
114                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/autofs
115         else
116                 msg_already_running automounter
117         fi
118 }
119
120 stop() {
121         if [ -f /var/lock/subsys/autofs ]; then
122                 msg_stopping automounter
123                 killproc automount
124                 rm -f /var/lock/subsys/autofs >/dev/null 2>&1
125         else
126                 msg_not_running automounter
127         fi
128 }
129
130 RETVAL=0
131 # See how we were called.
132 case "$1" in
133   start)
134         start
135         ;;
136   stop)
137         stop
138         ;;
139   restart|force-reload)
140         stop
141         start
142         ;;
143 #  status)
144 #       nls "Configured Mount Points:"
145 #       getmounts
146 #       echo ""
147 #       nls "Active Mount Points:"
148 #       ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
149 #               while read pid tt stat time command; do echo $command; done
150 #       )
151 #       ;;
152   *)
153         msg_usage "$0 {start|stop|restart|force-reload|status}"
154         exit 3
155 esac
156
157 exit $RETVAL
This page took 0.033526 seconds and 3 git commands to generate.