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():
|
||||
"""Get mounted volumes, returns dict."""
|
||||
cmd = [
|
||||
'findmnt', '-J', '-b', '-i',
|
||||
'-t', (
|
||||
'findmnt',
|
||||
'--list',
|
||||
'--json',
|
||||
'--bytes',
|
||||
'--invert',
|
||||
'--types', (
|
||||
'autofs,binfmt_misc,bpf,cgroup,cgroup2,configfs,debugfs,devpts,'
|
||||
'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)
|
||||
mounted_volumes = []
|
||||
for item in json_data.get('filesystems', []):
|
||||
|
|
@ -195,6 +199,8 @@ def mount_volumes(
|
|||
volumes.update({child['name']: child})
|
||||
for grandchild in child.get('children', []):
|
||||
volumes.update({grandchild['name']: grandchild})
|
||||
for great_grandchild in grandchild.get('children', []):
|
||||
volumes.update({great_grandchild['name']: great_grandchild})
|
||||
|
||||
# Get list of mounted volumes
|
||||
mounted_volumes = get_mounted_volumes()
|
||||
|
|
@ -237,6 +243,7 @@ def mount_volumes(
|
|||
if vol_data['show_data']['data'] == 'Failed to mount':
|
||||
vol_data['mount_point'] = None
|
||||
else:
|
||||
fstype = vol_data.get('fstype', 'UNKNOWN FS')
|
||||
size_used = human_readable_size(
|
||||
mounted_volumes[vol_path]['used'],
|
||||
decimals=1,
|
||||
|
|
@ -250,8 +257,9 @@ def mount_volumes(
|
|||
vol_data['mount_point'] = mounted_volumes[vol_path]['target']
|
||||
vol_data['show_data']['data'] = 'Mounted on {}'.format(
|
||||
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'],
|
||||
fstype,
|
||||
size_used,
|
||||
size_avail)
|
||||
|
||||
|
|
@ -285,6 +293,14 @@ def mount_backup_shares(read_write=False):
|
|||
|
||||
def mount_network_share(server, read_write=False):
|
||||
"""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:
|
||||
username = server['RW-User']
|
||||
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)
|
||||
success = 'Mounted {Name}'.format(**server)
|
||||
elif psutil.LINUX:
|
||||
# Make mountpoint
|
||||
cmd = [
|
||||
'sudo', 'mkdir', '-p',
|
||||
'/Backups/{Name}'.format(**server)]
|
||||
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 = [
|
||||
'sudo', 'mount',
|
||||
'//{IP}/{Share}'.format(**server),
|
||||
'//{IP}/{Share}'.format(**server).replace('\\', '/'),
|
||||
'/Backups/{Name}'.format(**server),
|
||||
'-o', '{}username={},password={}'.format(
|
||||
'' if read_write else 'ro,',
|
||||
username,
|
||||
password)]
|
||||
'-o', ','.join(cmd_options),
|
||||
]
|
||||
|
||||
# Set result messages
|
||||
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
||||
**server)
|
||||
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ if __name__ == '__main__':
|
|||
# Prep
|
||||
clear_screen()
|
||||
|
||||
# Connect
|
||||
connect_to_network()
|
||||
|
||||
# Mount
|
||||
if is_connected():
|
||||
mount_backup_shares(read_write=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue