|
31 | 31 | import getopt
|
32 | 32 |
|
33 | 33 | hidden = False
|
| 34 | +unmount = False |
34 | 35 |
|
35 | 36 | args = getopt.getopt(sys.argv[1:], "h")
|
36 | 37 |
|
37 | 38 | # parse cmdline options
|
38 | 39 | for k in args[0]:
|
39 | 40 | if k[0]=='-h':
|
40 | 41 | hidden = True
|
| 42 | +# if k[0]=='-u': |
| 43 | +# unmount = True |
41 | 44 |
|
42 | 45 | if len(args[1]) != 2:
|
43 | 46 | print "Usage: python mount.py [-h] volumepath dmname"
|
|
53 | 56 | PASSWORD = getpass.getpass("Enter password: ")
|
54 | 57 | DMNAME = args[1][1]
|
55 | 58 |
|
| 59 | +#if unmount: |
| 60 | + #todo |
| 61 | + # remove loopback |
| 62 | +# os.system("losetup -d `sudo losetup -a | grep '%s' | cut -d ':' -f 1`" % (FILENAME)) |
| 63 | + |
56 | 64 | #initialise pytruecrypt
|
57 | 65 | tc = PyTruecrypt(FILENAME)
|
58 | 66 |
|
|
63 | 71 |
|
64 | 72 | #if root - mount it
|
65 | 73 | if os.getuid() == 0:
|
66 |
| - #find a free loopback device |
67 |
| - child = Popen("losetup -f", shell=True, stdout=PIPE) |
68 |
| - output, errors = child.communicate(); |
69 |
| - freeLoopback = output.strip() |
70 |
| - |
71 |
| - #setup loopback |
72 |
| - os.system("losetup %s %s" % (freeLoopback, FILENAME)) |
| 74 | + devName = FILENAME |
| 75 | + |
| 76 | + # if not block device - use loopback |
| 77 | + if not stat.S_ISBLK(os.stat(devName).st_mode): |
| 78 | + #find a free loopback device |
| 79 | + child = Popen("losetup -f", shell=True, stdout=PIPE) |
| 80 | + output, errors = child.communicate(); |
| 81 | + devName = output.strip() |
| 82 | + |
| 83 | + #setup loopback |
| 84 | + os.system("losetup %s %s" % (devName, FILENAME)) |
73 | 85 |
|
74 | 86 | #setup linux device mapper so can mount volume
|
75 |
| - dmtable = tc.getDeviceMapperTable(freeLoopback) |
76 |
| - |
| 87 | + dmtable = tc.getDeviceMapperTable(devName) |
77 | 88 |
|
78 | 89 | #create dm target /dev/mapper/tcrypt
|
79 | 90 | # print "Device mapper table"
|
|
0 commit comments