summaryrefslogtreecommitdiffstats
path: root/sysutils/hal/files/mount-fuse
blob: a0ea8536e3a530ec958dbb04729e4156f5cdc734 (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
# Wrapper script for FreeBSD and PC-BSD, which takes calls from HAL
# for running mount_ntfs, and performs it with a given FUSE helper.
###################################################################

## Modify this next variable to point to the correct FUSE helper.
FUSE_HELPER="ntfs-3g"
## DO NOT modify anything below this.

FUSEDB="/tmp"
if [ -n "${TMPDIR}" ]
then
   FUSEDB=${TMPDIR}
fi

FUSEDB="${FUSEDB}/.fuse-mnts"
MNTSTRING=""
OPTIONS=""
FOUNDOPT="0"
FOUNDU="0"
FOUNDG="0"
FOUNDBADARG="0"
HWDEV=""
FOUNDDEV="0"

for i in $@
do
    if [ "$FOUNDOPT" = "1" ]
    then
        OPTIONS="${OPTIONS} -o ${i}"
    elif [ "${FOUNDU}" = "1" ]
    then
        OPTIONS="${OPTIONS} -o uid=${i}"
    elif [ "${FOUNDG}" = "1" ]
    then
        OPTIONS="${OPTIONS} -o gid=${i}"
    elif [ "${FOUNDBADARG}" = "1" ]
    then
        # We have an invalid argument flag, so ignore it and following argument
        FOUNDBADARG="0"
    else

       if [ "${FOUNDDEV}" = "1" ]
       then
         # Save the mount-point, will be used later
         MNTPOINT="${i}"
         FOUNDDEV="2"
       fi

        echo ${i}| grep -q "/dev" 2>/dev/null
        if [ "$?" = "0" -a "${FOUNDDEV}" = "0" ]
        then
            FOUNDDEV="1"
            # Lets check if we were given a fuse[] device
            # or a real device name
            echo "${i}" | grep -q "fuse" 2>/dev/null
            if [ "$?" = "0" ]
            then
             # Lets save the old fuse device name we had saved
             OLDFUSE="${i}"

             # Lets get the *real* device name for FUSE helper
             REALHWDEV="`cat ${FUSEDB} | grep ${i} | cut -d '=' -f 2`"

             # Now lets change the string we will be saving
             i="${REALHWDEV}"
            else
             # We are doing a first time mount of this device

             # Set the real device name for mounting
             REALHWDEV="${i}"
            fi
        fi

        # Add the value to our mount string if it isn't any invalid flag
        if [ "${i}" != "-o" -a "${i}" != "-u" -a "${i}" != "-C" -a "${i}" != "-g" -a "${i}" != "-m" -a "${i}" != "-a" -a "${i}" != "-i" -a "${i}" -a "-W" ]
        then
          MNTSTRING="${MNTSTRING} ${i}"
        fi

    fi

    # Check if we are on a -u user id flag now
    if [ "${i}" = "-u" ]
    then
       FOUNDU="1"
    else
       FOUNDU="0"
    fi

    # Check if we are on a -g group id flag now
    if [ "${i}" = "-g" ]
    then
       FOUNDG="1"
    else
       FOUNDG="0"
    fi

    # Check if we are on a -o option
    if [ "${i}" = "-o" ]
    then
       FOUNDOPT="1"
    else
       FOUNDOPT="0"
    fi

    # Check if we are on some other invalid flag
    if [ "${i}" = "-C" -o "${i}" = "-m" -o "${i}" = "-W" ]
    then
       FOUNDBADARG="1"
    else
       FOUNDBADARG="0"
    fi
done

# Save our final string which our FUSE helper will use
FINALSTRING="${MNTSTRING} ${OPTIONS}"

# Check that fuse.ko is loaded
kldstat | grep -q fuse 2>/dev/null
if [ "$?" != "0" ]
then
  kldload /usr/local/modules/fuse.ko
fi

# Run the FUSE helper command now, with the options in the right order
${FUSE_HELPER} ${FINALSTRING}

# If we have an OLDFUSE variable, lets clear it from the list
if [ ! -z "${OLDFUSE}" -a -e ${FUSEDB} ]
then
   cat ${FUSEDB} | grep -v "${OLDFUSE}=" > /tmp/.newfuse
   mv /tmp/.newfuse ${FUSEDB}
fi

# Now lets figure out which fuse device was used and save it to DB
NEWFUSE="`mount | tr -s ' ' |  grep \" ${MNTPOINT} \" | cut -d ' ' -f 1`"

# Make sure we don't already have this fuse device listed
if [ -e ${FUSEDB} ]
then
   cat ${FUSEDB} | grep -v "${NEWFUSE}=" > /tmp/.newfuse
   mv /tmp/.newfuse ${FUSEDB}
else
   touch ${FUSEDB}
fi

# Save the fuse device to our DB
echo "${NEWFUSE}=${REALHWDEV}" >> ${FUSEDB}


# Finished!
exit 0