aboutsummaryrefslogtreecommitdiff
path: root/util/mount.fuse
blob: 4ec140919afdae9ee9473b2a2acc096add123fcf (plain)
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
#!/usr/bin/env python
#@+leo-ver=4
#@+node:@file mount.fuse
#@@first #!/usr/bin/env python

"""
This utility allows FUSE filesystems to be mounted with the regular *nix
'mount' command, or even be listed in /etc/fstab

To enable this, you need to:
 1. set execute-permission on this script
 2. symlink this script into /sbin/mount.fuse

Usage:

 You can use this in 3 ways:
     1.  mount -t fuse /path/to/script/or/program /path/of/mount/point [options]
     2.  mount -t fuse none /path/of/mount/point -o fs=/path/to/script/or/prog[,opt=val...]
     3.  in /etc/fstab, add:
           /path/to/script/or/prog /path/of/mount/point fuse noauto[,...]
"""

import sys, os, time

progname = sys.argv[0]

def usage(ret):
    print "Usage: %s /path/to/fuse/fs /path/of/mountpoint [-o options]" % progname
    print "or:    %s none /path/of/mountpoint [-o fs=/path/to/fuse/fs[,...]]" % progname
    sys.exit(ret)

def main():

    # initial sanity check
    argc = len(sys.argv)
    if argc < 3 or sys.argv[3] != "-o":
        usage(1)

    dev = sys.argv[1]
    mountpoint = sys.argv[2]

    # grab options, if any
    optdict = {}
    optlist = []
    if argc > 4:
        odata = sys.argv[4]
        opts = odata.split(",")
        #print opts
        for o in opts:
            try:
                k, v = o.split("=", 1)
                optdict[k] = v
            except:
                optlist.append(o)
    else:
        odata = ""

    #print sys.argv
    if dev == 'none':
        if not optdict.has_key("fs"):
            print "%s: Must specify python file with 'fs' option\n" % progname
            usage(1)
        pyfile = optdict['fs']
    else:
        pyfile = dev

    if not os.path.isfile(pyfile):
        print "%s: file %s doesn't exist, or is not a file" % (progname, pyfile)
        sys.exit(1)
    pypath = os.path.abspath(pyfile)

    #print optdict, optlist

    # all seems ok - run our fuse fs as a child
    if os.fork() == 0:
        os.system("fusermount -c -x %s %s %s %s" % (mountpoint, pypath, mountpoint, odata))
    else:
        #print "parent exiting..."
        pass

if __name__ == '__main__':
    main()

#@-node:@file mount.fuse
#@-leo