Debian Codegraph @

scripts/auto.diod.in

raw
1 #!/bin/bash
2 #
3 # auto.diod - executable automounter map for diod file systems
4 #
5 # Input: $1 is "key" (/d/key is accessed)
6 # Output: string of the form "-fstype=diod[,options] server:path" on stdout
7 # Stderr goes to the system logs
8 # See autofs(5)
9 #
10 # Note: sources $DIOD_SYSCONF and uses the following if set
11 # DIOD_SERVERS list of servers to try (space delimited)
12 # Server may be IP, HOST or /path/to/socket.
13 # DIOD_TIMEOUT time (in seconds) to wait for server connect (default 10)
14 # DIOD_MOUNTOPTS Add options to the mount command line
15 #
16 key="$1"
17 [ -n "$key" ] || exit 0
18
19 DIOD_MAP=/d
20 DIOD_SYSCONF=@X_SYSCONFDIR@/sysconfig/auto.diod
21 DIOD_DIODCAT=@X_SBINDIR@/diodcat
22 DIOD_SERVERS=""
23 DIOD_MOUNTOPTS=""
24 DIOD_TIMEOUT=10
25
26 if [ -r $DIOD_SYSCONF ]; then
27 . $DIOD_SYSCONF
28 fi
29 if [ -z "$DIOD_SERVERS" ]; then
30 echo "auto.diod: DIOD_SERVERS is not set" >&2
31 exit 1
32 fi
33 if ! [ -x $DIOD_DIODCAT ]; then
34 echo "auto.diod: could not execute $DIOD_DIODCAT" >&2
35 exit 1
36 fi
37
38 prefix="-fstype=diod${DIOD_MOUNTOPTS:+,$DIOD_MOUNTOPTS}"
39 dcatopts="${DIOD_TIMEOUT:+-t $DIOD_TIMEOUT}"
40
41 for server in $DIOD_SERVERS; do
42 $DIOD_DIODCAT -s $server $dcatopts exports | awk '{print $1}' |\
43 while read path; do
44 if [ "$path" == "/" ]; then
45 if [ "$key" == "ROOT" ]; then
46 echo "$prefix $server:$path"
47 exit 0
48 fi
49 elif [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//./g')" ] \
50 || [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//_/g')" ] \
51 || [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//-/g')" ] \
52 || [ "$key" == "$(basename $path)" ]; then
53 echo "$prefix $server:$path"
54 exit 0
55 fi
56 done
57 done