[go: up one dir, main page]

File: auto.diod.in

package info (click to toggle)
diod 1.0.13-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 29,952 kB
  • sloc: ansic: 31,694; sh: 15,368; makefile: 347; perl: 80
file content (57 lines) | stat: -rwxr-xr-x 1,755 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#
# auto.diod - executable automounter map for diod file systems
#
# Input: $1 is "key" (/d/key is accessed)
# Output: string of the form "-fstype=diod[,options] server:path" on stdout
# Stderr goes to the system logs
# See autofs(5)
#
# Note: sources $DIOD_SYSCONF and uses the following if set
#   DIOD_SERVERS     list of servers to try (space delimited)
#                    Server may be IP, HOST or /path/to/socket.
#   DIOD_TIMEOUT     time (in seconds) to wait for server connect (default 10)
#   DIOD_MOUNTOPTS   Add options to the mount command line
#
key="$1"
[ -n "$key" ] || exit 0

DIOD_MAP=/d
DIOD_SYSCONF=@X_SYSCONFDIR@/sysconfig/auto.diod
DIOD_DIODCAT=@X_SBINDIR@/diodcat
DIOD_SERVERS=""
DIOD_MOUNTOPTS=""
DIOD_TIMEOUT=10

if [ -r $DIOD_SYSCONF ]; then
    . $DIOD_SYSCONF
fi
if [ -z "$DIOD_SERVERS" ]; then
    echo "auto.diod: DIOD_SERVERS is not set" >&2
    exit 1
fi
if ! [ -x $DIOD_DIODCAT ]; then
    echo "auto.diod: could not execute $DIOD_DIODCAT" >&2
    exit 1
fi

prefix="-fstype=diod${DIOD_MOUNTOPTS:+,$DIOD_MOUNTOPTS}"
dcatopts="${DIOD_TIMEOUT:+-t $DIOD_TIMEOUT}"

for server in $DIOD_SERVERS; do
    $DIOD_DIODCAT -s $server $dcatopts exports | awk '{print $1}' |\
    while read path; do
        if [ "$path" == "/" ]; then
            if [ "$key" == "ROOT" ]; then
                echo "$prefix $server:$path"
                exit 0
            fi
        elif [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//./g')" ] \
          || [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//_/g')" ] \
          || [ "$key" == "$(echo $path|sed -e's/^\///' -e's/\//-/g')" ] \
          || [ "$key" == "$(basename $path)" ]; then
            echo "$prefix $server:$path"
            exit 0
        fi
    done
done