From a3cb3662a8b15efb3e6a7381cb376a0ca3f095a0 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 26 Mar 2015 18:41:13 +0100 Subject: c*mount suite ready --- cumount.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 cumount.py (limited to 'cumount.py') diff --git a/cumount.py b/cumount.py new file mode 100755 index 0000000..ad9f681 --- /dev/null +++ b/cumount.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import json +import os +import subprocess +import sys + + +def main(): + """ + """ + if (len(sys.argv) != 2): + sys.exit('Invalid parameter. Usage: {0} \n'.format( + sys.argv[0])) + cstm_error = '' + try: + cstm_error = 'Could not open config (~/.cmount.json)' + with open(os.path.expanduser('~/.cmount.json')) as fp: + config_dict = json.load(fp) + cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) + data = config_dict[sys.argv[1]] + subprocess.check_call(['/bin/umount', + '/dev/mapper/' + data['mapper_name']]) + subprocess.check_call(['/sbin/cryptsetup', + 'luksClose', + data['mapper_name']]) + except subprocess.CalledProcessError as e: + sys.stderr.write('Execution error: {0}\n'.format(e)) + sys.stderr.flush() + except Exception as e: + sys.stderr.write('Error: {0}\n'.format(cstm_error)) + sys.stderr.flush() + + +if __name__ == '__main__': + main() -- cgit v1.3