diff --git a/.bin/Scripts/connect_to_network b/.bin/Scripts/connect-to-network similarity index 100% rename from .bin/Scripts/connect_to_network rename to .bin/Scripts/connect-to-network diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index 06ac16e7..c1a3b352 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -1,6 +1,7 @@ # Wizard Kit: Functions - Data import ctypes +import json from operator import itemgetter @@ -157,6 +158,82 @@ def is_valid_wim_file(item): print_log('WARNING: Image "{}" damaged.'.format(item.name)) return valid +def get_mounted_data(): + """Get mounted volumes, returns dict.""" + cmd = [ + 'findmnt', '-J', '-b', '-i', + 't', ( + 'autofs,binfmt_misc,cgroup,cgroup2,configfs,debugfs,devpts,devtmpfs,' + 'hugetlbfs,mqueue,proc,pstore,securityfs,sysfs,tmpfs' + ), + '-o', 'SOURCE,TARGET,FSTYPE,LABEL,SIZE,AVAIL,USED'] + result = run_program(cmd) + json_data = json.loads(result.stdout.decode()) + mounted_data = [] + for item in json_data.get('filesystems', []): + mounted_data.append(item) + mounted_data.extend(item.get('children', [])) + return {item['source']: item for item in mounted_data} + +def mount_all_volumes(): + """Mount all attached devices with recognized filesystems.""" + report = [] + + # Get list of block devices + cmd = ['lsblk', '-J', '-o', 'NAME,FSTYPE,LABEL,UUID,PARTTYPE,TYPE,SIZE'] + result = run_program(cmd) + json_data = json.loads(result.stdout.decode()) + devs = json_data.get('blockdevices', []) + + # Get list of mounted devices + mounted_data = get_mounted_data() + mounted_list = [m['source'] for m in mounted_data.values()] + + # Loop over devices + for dev in devs: + dev_path = '/dev/{}'.format(dev['name']) + if re.search(r'^(loop|sr)', dev['name'], re.IGNORECASE): + # Skip loopback devices and optical media + report.append([dev_path, 'Skipped']) + continue + for child in dev.get('children', []): + child_path = '/dev/{}'.format(child['name']) + if child_path in mounted_list: + report.append([child_path, 'Already Mounted']) + else: + try: + run_program(['udevil', 'mount', '-o', 'ro', child_path]) + report.append([child_path, 'CS']) + except subprocess.CalledProcessError: + report.append([child_path, 'NS']) + + # Update list of mounted devices + mounted_data = get_mounted_data() + mounted_list = [m['source'] for m in mounted_data.values()] + + # Update report lines for show_data() + for line in report: + _path = line[0] + _result = line[1] + info = {'message': '{}:'.format(_path)} + if _path in mounted_list: + info['data'] = 'Mounted on {}'.format( + mounted_data[_path]['target']) + info['data'] = '{:40} ({} used, {} free)'.format( + info['data'], + human_readable_size(mounted_data[_path]['used']), + human_readable_size(mounted_data[_path]['avail'])) + if _result == 'Already Mounted': + info['warning'] = True + elif _result == 'Skipped': + info['data'] = 'Skipped' + info['warning'] = True + else: + info['data'] = 'Failed to mount' + info['error'] = True + line.append(info) + return report + def mount_backup_shares(): """Mount the backup shares unless labeled as already mounted.""" for server in BACKUP_SERVERS: diff --git a/.bin/Scripts/mount-all-volumes b/.bin/Scripts/mount-all-volumes new file mode 100755 index 00000000..587bc4c9 --- /dev/null +++ b/.bin/Scripts/mount-all-volumes @@ -0,0 +1,38 @@ +#!/bin/python3 +# +## Wizard Kit: Volume mount tool + +import os +import sys + +# Init +os.chdir(os.path.dirname(os.path.realpath(__file__))) +sys.path.append(os.getcwd()) +from functions.data import * +init_global_vars() + +if __name__ == '__main__': + try: + # Prep + clear_screen() + print_standard('{}: Volume mount tool'.format(KIT_NAME_FULL)) + + # Mount volumes + report = mount_all_volumes() + + # Print report + print_info('\nResults') + for line in report: + show_data(indent=4, width=16, **line[-1]) + + # Done + print_standard('\nDone.') + if 'foh' in __file__: + pause("Press Enter to exit...") + popen_program(['thunar', '/media']) + exit_script() + except SystemExit: + pass + except: + major_exception() + diff --git a/.linux_items/packages/live b/.linux_items/packages/live index b5300bdc..b673f686 100644 --- a/.linux_items/packages/live +++ b/.linux_items/packages/live @@ -75,6 +75,7 @@ udevil udisks2 ufw unzip +util-linux veracrypt vim virtualbox-guest-modules-arch