Updated mounting sections
This commit is contained in:
parent
28bedc0873
commit
606efac3fe
2 changed files with 42 additions and 12 deletions
|
|
@ -151,12 +151,16 @@ def is_valid_wim_file(item):
|
||||||
def get_mounted_volumes():
|
def get_mounted_volumes():
|
||||||
"""Get mounted volumes, returns dict."""
|
"""Get mounted volumes, returns dict."""
|
||||||
cmd = [
|
cmd = [
|
||||||
'findmnt', '-J', '-b', '-i',
|
'findmnt',
|
||||||
'-t', (
|
'--list',
|
||||||
|
'--json',
|
||||||
|
'--bytes',
|
||||||
|
'--invert',
|
||||||
|
'--types', (
|
||||||
'autofs,binfmt_misc,bpf,cgroup,cgroup2,configfs,debugfs,devpts,'
|
'autofs,binfmt_misc,bpf,cgroup,cgroup2,configfs,debugfs,devpts,'
|
||||||
'devtmpfs,hugetlbfs,mqueue,proc,pstore,securityfs,sysfs,tmpfs'
|
'devtmpfs,hugetlbfs,mqueue,proc,pstore,securityfs,sysfs,tmpfs'
|
||||||
),
|
),
|
||||||
'-o', 'SOURCE,TARGET,FSTYPE,LABEL,SIZE,AVAIL,USED']
|
'--output', 'SOURCE,TARGET,FSTYPE,LABEL,SIZE,AVAIL,USED']
|
||||||
json_data = get_json_from_command(cmd)
|
json_data = get_json_from_command(cmd)
|
||||||
mounted_volumes = []
|
mounted_volumes = []
|
||||||
for item in json_data.get('filesystems', []):
|
for item in json_data.get('filesystems', []):
|
||||||
|
|
@ -195,6 +199,8 @@ def mount_volumes(
|
||||||
volumes.update({child['name']: child})
|
volumes.update({child['name']: child})
|
||||||
for grandchild in child.get('children', []):
|
for grandchild in child.get('children', []):
|
||||||
volumes.update({grandchild['name']: grandchild})
|
volumes.update({grandchild['name']: grandchild})
|
||||||
|
for great_grandchild in grandchild.get('children', []):
|
||||||
|
volumes.update({great_grandchild['name']: great_grandchild})
|
||||||
|
|
||||||
# Get list of mounted volumes
|
# Get list of mounted volumes
|
||||||
mounted_volumes = get_mounted_volumes()
|
mounted_volumes = get_mounted_volumes()
|
||||||
|
|
@ -237,6 +243,7 @@ def mount_volumes(
|
||||||
if vol_data['show_data']['data'] == 'Failed to mount':
|
if vol_data['show_data']['data'] == 'Failed to mount':
|
||||||
vol_data['mount_point'] = None
|
vol_data['mount_point'] = None
|
||||||
else:
|
else:
|
||||||
|
fstype = vol_data.get('fstype', 'UNKNOWN FS')
|
||||||
size_used = human_readable_size(
|
size_used = human_readable_size(
|
||||||
mounted_volumes[vol_path]['used'],
|
mounted_volumes[vol_path]['used'],
|
||||||
decimals=1,
|
decimals=1,
|
||||||
|
|
@ -250,8 +257,9 @@ def mount_volumes(
|
||||||
vol_data['mount_point'] = mounted_volumes[vol_path]['target']
|
vol_data['mount_point'] = mounted_volumes[vol_path]['target']
|
||||||
vol_data['show_data']['data'] = 'Mounted on {}'.format(
|
vol_data['show_data']['data'] = 'Mounted on {}'.format(
|
||||||
mounted_volumes[vol_path]['target'])
|
mounted_volumes[vol_path]['target'])
|
||||||
vol_data['show_data']['data'] = '{:40} ({} used, {} free)'.format(
|
vol_data['show_data']['data'] = '{:40} ({}, {} used, {} free)'.format(
|
||||||
vol_data['show_data']['data'],
|
vol_data['show_data']['data'],
|
||||||
|
fstype,
|
||||||
size_used,
|
size_used,
|
||||||
size_avail)
|
size_avail)
|
||||||
|
|
||||||
|
|
@ -285,6 +293,14 @@ def mount_backup_shares(read_write=False):
|
||||||
|
|
||||||
def mount_network_share(server, read_write=False):
|
def mount_network_share(server, read_write=False):
|
||||||
"""Mount a network share defined by server."""
|
"""Mount a network share defined by server."""
|
||||||
|
uid = '1000'
|
||||||
|
|
||||||
|
# Get UID
|
||||||
|
cmd = ['id', '--user', 'tech']
|
||||||
|
result = run_program(cmd, check=False, encoding='utf-8', errors='ignore')
|
||||||
|
if result.stdout.strip().isnumeric():
|
||||||
|
uid = result.stdout.strip()
|
||||||
|
|
||||||
if read_write:
|
if read_write:
|
||||||
username = server['RW-User']
|
username = server['RW-User']
|
||||||
password = server['RW-Pass']
|
password = server['RW-Pass']
|
||||||
|
|
@ -300,18 +316,35 @@ def mount_network_share(server, read_write=False):
|
||||||
error = r'Failed to mount \\{Name}\{Share} ({IP})'.format(**server)
|
error = r'Failed to mount \\{Name}\{Share} ({IP})'.format(**server)
|
||||||
success = 'Mounted {Name}'.format(**server)
|
success = 'Mounted {Name}'.format(**server)
|
||||||
elif psutil.LINUX:
|
elif psutil.LINUX:
|
||||||
|
# Make mountpoint
|
||||||
cmd = [
|
cmd = [
|
||||||
'sudo', 'mkdir', '-p',
|
'sudo', 'mkdir', '-p',
|
||||||
'/Backups/{Name}'.format(**server)]
|
'/Backups/{Name}'.format(**server)]
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
|
# Set mount options
|
||||||
|
cmd_options = [
|
||||||
|
# Assuming GID matches UID
|
||||||
|
'gid={}'.format(uid),
|
||||||
|
'uid={}'.format(uid),
|
||||||
|
]
|
||||||
|
cmd_options.append('rw' if read_write else 'ro')
|
||||||
|
cmd_options.append('username={}'.format(username))
|
||||||
|
if password:
|
||||||
|
cmd_options.append('password={}'.format(password))
|
||||||
|
else:
|
||||||
|
# Skip password check
|
||||||
|
cmd_options.append('guest')
|
||||||
|
|
||||||
|
# Set mount command
|
||||||
cmd = [
|
cmd = [
|
||||||
'sudo', 'mount',
|
'sudo', 'mount',
|
||||||
'//{IP}/{Share}'.format(**server),
|
'//{IP}/{Share}'.format(**server).replace('\\', '/'),
|
||||||
'/Backups/{Name}'.format(**server),
|
'/Backups/{Name}'.format(**server),
|
||||||
'-o', '{}username={},password={}'.format(
|
'-o', ','.join(cmd_options),
|
||||||
'' if read_write else 'ro,',
|
]
|
||||||
username,
|
|
||||||
password)]
|
# Set result messages
|
||||||
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
||||||
**server)
|
**server)
|
||||||
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@ if __name__ == '__main__':
|
||||||
# Prep
|
# Prep
|
||||||
clear_screen()
|
clear_screen()
|
||||||
|
|
||||||
# Connect
|
|
||||||
connect_to_network()
|
|
||||||
|
|
||||||
# Mount
|
# Mount
|
||||||
if is_connected():
|
if is_connected():
|
||||||
mount_backup_shares(read_write=True)
|
mount_backup_shares(read_write=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue