diff options
| author | Simeon Simeonov | 2015-03-26 18:41:13 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2015-03-26 18:41:13 +0100 |
| commit | a3cb3662a8b15efb3e6a7381cb376a0ca3f095a0 (patch) | |
| tree | d2f7ff17bc5b63c0a41f5083c108f7d54b3341f2 /cumount.py | |
| parent | b0a5f8a1ca75d4ca63e91226cc7d0c03da066b27 (diff) | |
c*mount suite ready
Diffstat (limited to 'cumount.py')
| -rwxr-xr-x | cumount.py | 37 |
1 files changed, 37 insertions, 0 deletions
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 | |||
| 4 | import json | ||
| 5 | import os | ||
| 6 | import subprocess | ||
| 7 | import sys | ||
| 8 | |||
| 9 | |||
| 10 | def 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 | |||
| 36 | if __name__ == '__main__': | ||
| 37 | main() | ||
