diff options
| author | Simeon Simeonov | 2015-03-26 17:47:31 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2015-03-26 17:47:31 +0100 |
| commit | b0a5f8a1ca75d4ca63e91226cc7d0c03da066b27 (patch) | |
| tree | 3032cb5609817def489231a4937af6aa0af7a086 | |
initial import
| -rwxr-xr-x | cmount.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cmount.py b/cmount.py new file mode 100755 index 0000000..9749582 --- /dev/null +++ b/cmount.py | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | # -*- coding: utf-8 -*- | ||
| 3 | |||
| 4 | import json | ||
| 5 | import os | ||
| 6 | import sys | ||
| 7 | |||
| 8 | |||
| 9 | def main(): | ||
| 10 | """ | ||
| 11 | """ | ||
| 12 | if (len(sys.argv) != 2): | ||
| 13 | sys.exit("Invalid parameter. Usage: " + sys.argv[0] + " <mapping>\n") | ||
| 14 | cstm_error = '' | ||
| 15 | try: | ||
| 16 | cstm_error = 'Could not open config' | ||
| 17 | with open(os.path.expanduser('~/.cmount.json')) as fp: | ||
| 18 | config_dict = json.load(fp) | ||
| 19 | cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) | ||
| 20 | data = config_dict[sys.argv[1]] | ||
| 21 | cstm_error = 'system() error' | ||
| 22 | os.system('/sbin/cryptsetup luksOpen {device} {name}'.format( | ||
| 23 | device=data['device'], | ||
| 24 | name=sys.argv[1])) | ||
| 25 | os.system('/bin/mount /dev/mapper/{name} {target}'.format( | ||
| 26 | name=sys.argv[1], | ||
| 27 | target=data['target'])) | ||
| 28 | except Exception as e: | ||
| 29 | sys.stderr.write('Error: {0}\n'.format(cstm_error)) | ||
| 30 | sys.stderr.flush() | ||
| 31 | |||
| 32 | if __name__ == '__main__': | ||
| 33 | main() | ||
