summaryrefslogtreecommitdiff
path: root/cmount.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmount.py')
-rwxr-xr-xcmount.py52
1 files changed, 37 insertions, 15 deletions
diff --git a/cmount.py b/cmount.py
index 587c02f..f980dc9 100755
--- a/cmount.py
+++ b/cmount.py
@@ -20,21 +20,43 @@ def main():
20 config_dict = json.load(fp) 20 config_dict = json.load(fp)
21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) 21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1])
22 data = config_dict[sys.argv[1]] 22 data = config_dict[sys.argv[1]]
23 if data.get('type') == 'efile': 23 if data.get('type') == 'lvm':
24 cstm_error = 'Unable to create loop device' 24 if not isinstance(data.get('pv_sources'), dict):
25 data['device'] = subprocess.check_output(['/usr/sbin/losetup', 25 cstm_error = 'Invalid config for lvm-type'
26 '--find', 26 raise Exception()
27 '--show', 27 cstm_error = 'pv_sources error'
28 data['device']]).strip() 28 for device, mapper_name in data['pv_sources'].items():
29 cstm_error = 'system() error' 29 subprocess.check_call(['/sbin/cryptsetup',
30 subprocess.check_call(['/sbin/cryptsetup', 30 'luksOpen',
31 'luksOpen', 31 device,
32 data['device'], 32 mapper_name])
33 data['mapper_name']]) 33 cstm_error = 'lvchange error'
34 arguments = ['/bin/mount', '/dev/mapper/' + data['mapper_name']] 34 subprocess.check_call(['/sbin/lvchange',
35 if data.get('target'): 35 '-a',
36 arguments.append(data['target']) 36 'y',
37 subprocess.check_call(arguments) 37 data['device']])
38 cstm_error = 'mount error'
39 arguments = ['/bin/mount', data['device']]
40 if data.get('target'):
41 arguments.append(data['target'])
42 subprocess.check_call(arguments)
43 else:
44 if data.get('type') == 'efile':
45 cstm_error = 'Unable to create loop device'
46 data['device'] = subprocess.check_output(
47 ['/usr/sbin/losetup',
48 '--find',
49 '--show',
50 data['device']]).strip()
51 cstm_error = 'system() error'
52 subprocess.check_call(['/sbin/cryptsetup',
53 'luksOpen',
54 data['device'],
55 data['mapper_name']])
56 arguments = ['/bin/mount', '/dev/mapper/' + data['mapper_name']]
57 if data.get('target'):
58 arguments.append(data['target'])
59 subprocess.check_call(arguments)
38 except subprocess.CalledProcessError as e: 60 except subprocess.CalledProcessError as e:
39 sys.stderr.write('Execution error: {0}\n'.format(e)) 61 sys.stderr.write('Execution error: {0}\n'.format(e))
40 sys.stderr.flush() 62 sys.stderr.flush()