1 |
#!/usr/bin/env python |
2 |
#@+leo-ver=4 |
3 |
#@+node:@file mount.fuse |
4 |
#@@first #!/usr/bin/env python |
5 |
|
6 |
""" |
7 |
This utility allows FUSE filesystems to be mounted with the regular *nix |
8 |
'mount' command, or even be listed in /etc/fstab |
9 |
|
10 |
To enable this, you need to: |
11 |
1. set execute-permission on this script |
12 |
2. symlink this script into /sbin/mount.fuse |
13 |
|
14 |
Usage: |
15 |
|
16 |
You can use this in 3 ways: |
17 |
1. mount -t fuse /path/to/script/or/program /path/of/mount/point [options] |
18 |
2. mount -t fuse none /path/of/mount/point -o fs=/path/to/script/or/prog[,opt=val...] |
19 |
3. in /etc/fstab, add: |
20 |
/path/to/script/or/prog /path/of/mount/point fuse noauto[,...] |
21 |
""" |
22 |
|
23 |
import sys, os, time |
24 |
|
25 |
progname = sys.argv[0] |
26 |
|
27 |
def usage(ret): |
28 |
print "Usage: %s /path/to/fuse/fs /path/of/mountpoint [-o options]" % progname |
29 |
print "or: %s none /path/of/mountpoint [-o fs=/path/to/fuse/fs[,...]]" % progname |
30 |
sys.exit(ret) |
31 |
|
32 |
def main(): |
33 |
|
34 |
# initial sanity check |
35 |
argc = len(sys.argv) |
36 |
if argc < 3 or sys.argv[3] != "-o": |
37 |
usage(1) |
38 |
|
39 |
dev = sys.argv[1] |
40 |
mountpoint = sys.argv[2] |
41 |
|
42 |
# grab options, if any |
43 |
optdict = {} |
44 |
optlist = [] |
45 |
if argc > 4: |
46 |
odata = sys.argv[4] |
47 |
opts = odata.split(",") |
48 |
#print opts |
49 |
for o in opts: |
50 |
try: |
51 |
k, v = o.split("=", 1) |
52 |
optdict[k] = v |
53 |
except: |
54 |
optlist.append(o) |
55 |
else: |
56 |
odata = "" |
57 |
|
58 |
#print sys.argv |
59 |
if dev == 'none': |
60 |
if not optdict.has_key("fs"): |
61 |
print "%s: Must specify python file with 'fs' option\n" % progname |
62 |
usage(1) |
63 |
pyfile = optdict['fs'] |
64 |
else: |
65 |
pyfile = dev |
66 |
|
67 |
if not os.path.isfile(pyfile): |
68 |
print "%s: file %s doesn't exist, or is not a file" % (progname, pyfile) |
69 |
sys.exit(1) |
70 |
pypath = os.path.abspath(pyfile) |
71 |
|
72 |
#print optdict, optlist |
73 |
|
74 |
# all seems ok - run our fuse fs as a child |
75 |
if os.fork() == 0: |
76 |
os.system("fusermount -c -x %s %s %s %s" % (mountpoint, pypath, mountpoint, odata)) |
77 |
else: |
78 |
#print "parent exiting..." |
79 |
pass |
80 |
|
81 |
if __name__ == '__main__': |
82 |
main() |
83 |
|
84 |
#@-node:@file mount.fuse |
85 |
#@-leo |