From b0a5f8a1ca75d4ca63e91226cc7d0c03da066b27 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 26 Mar 2015 17:47:31 +0100 Subject: initial import --- cmount.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 cmount.py diff --git a/cmount.py b/cmount.py new file mode 100755 index 0000000..9749582 --- /dev/null +++ b/cmount.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import json +import os +import sys + + +def main(): + """ + """ + if (len(sys.argv) != 2): + sys.exit("Invalid parameter. Usage: " + sys.argv[0] + " \n") + cstm_error = '' + try: + cstm_error = 'Could not open config' + 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]] + cstm_error = 'system() error' + os.system('/sbin/cryptsetup luksOpen {device} {name}'.format( + device=data['device'], + name=sys.argv[1])) + os.system('/bin/mount /dev/mapper/{name} {target}'.format( + name=sys.argv[1], + target=data['target'])) + except Exception as e: + sys.stderr.write('Error: {0}\n'.format(cstm_error)) + sys.stderr.flush() + +if __name__ == '__main__': + main() -- cgit v1.3