summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcmount.py25
-rwxr-xr-xcumount.py37
2 files changed, 53 insertions, 9 deletions
diff --git a/cmount.py b/cmount.py
index 9749582..341b5a0 100755
--- a/cmount.py
+++ b/cmount.py
@@ -1,8 +1,9 @@
1#!/usr/bin/python 1#!/usr/bin/env python
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4import json 4import json
5import os 5import os
6import subprocess
6import sys 7import sys
7 8
8 9
@@ -10,24 +11,30 @@ def main():
10 """ 11 """
11 """ 12 """
12 if (len(sys.argv) != 2): 13 if (len(sys.argv) != 2):
13 sys.exit("Invalid parameter. Usage: " + sys.argv[0] + " <mapping>\n") 14 sys.exit('Invalid parameter. Usage: {0} <mapping>\n'.format(
15 sys.argv[0]))
14 cstm_error = '' 16 cstm_error = ''
15 try: 17 try:
16 cstm_error = 'Could not open config' 18 cstm_error = 'Could not open config (~/.cmount.json)'
17 with open(os.path.expanduser('~/.cmount.json')) as fp: 19 with open(os.path.expanduser('~/.cmount.json')) as fp:
18 config_dict = json.load(fp) 20 config_dict = json.load(fp)
19 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) 21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1])
20 data = config_dict[sys.argv[1]] 22 data = config_dict[sys.argv[1]]
21 cstm_error = 'system() error' 23 cstm_error = 'system() error'
22 os.system('/sbin/cryptsetup luksOpen {device} {name}'.format( 24 subprocess.check_call(['/sbin/cryptsetup',
23 device=data['device'], 25 'luksOpen',
24 name=sys.argv[1])) 26 data['device'],
25 os.system('/bin/mount /dev/mapper/{name} {target}'.format( 27 data['mapper_name']])
26 name=sys.argv[1], 28 subprocess.check_call(['/bin/mount',
27 target=data['target'])) 29 '/dev/mapper/' + data['mapper_name'],
30 data['target']])
31 except subprocess.CalledProcessError as e:
32 sys.stderr.write('Execution error: {0}\n'.format(e))
33 sys.stderr.flush()
28 except Exception as e: 34 except Exception as e:
29 sys.stderr.write('Error: {0}\n'.format(cstm_error)) 35 sys.stderr.write('Error: {0}\n'.format(cstm_error))
30 sys.stderr.flush() 36 sys.stderr.flush()
31 37
38
32if __name__ == '__main__': 39if __name__ == '__main__':
33 main() 40 main()
diff --git a/cumount.py b/cumount.py
new file mode 100755
index 0000000..ad9f681
--- /dev/null
+++ b/cumount.py
@@ -0,0 +1,37 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import json
5import os
6import subprocess
7import sys
8
9
10def main():
11 """
12 """
13 if (len(sys.argv) != 2):
14 sys.exit('Invalid parameter. Usage: {0} <mapping>\n'.format(
15 sys.argv[0]))
16 cstm_error = ''
17 try:
18 cstm_error = 'Could not open config (~/.cmount.json)'
19 with open(os.path.expanduser('~/.cmount.json')) as fp:
20 config_dict = json.load(fp)
21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1])
22 data = config_dict[sys.argv[1]]
23 subprocess.check_call(['/bin/umount',
24 '/dev/mapper/' + data['mapper_name']])
25 subprocess.check_call(['/sbin/cryptsetup',
26 'luksClose',
27 data['mapper_name']])
28 except subprocess.CalledProcessError as e:
29 sys.stderr.write('Execution error: {0}\n'.format(e))
30 sys.stderr.flush()
31 except Exception as e:
32 sys.stderr.write('Error: {0}\n'.format(cstm_error))
33 sys.stderr.flush()
34
35
36if __name__ == '__main__':
37 main()