From fa39c85fe42589a989b50b49066fb1520345e09c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 13 May 2019 18:46:30 -0600 Subject: [PATCH] Fix mounting backup shares under Linux --- .bin/Scripts/functions/data.py | 23 ++++++++++++++++++----- .bin/Scripts/settings/main.py | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.bin/Scripts/functions/data.py b/.bin/Scripts/functions/data.py index 15a854a8..8173a634 100644 --- a/.bin/Scripts/functions/data.py +++ b/.bin/Scripts/functions/data.py @@ -308,18 +308,31 @@ 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 = [] + 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) diff --git a/.bin/Scripts/settings/main.py b/.bin/Scripts/settings/main.py index 6df74127..4636dac2 100644 --- a/.bin/Scripts/settings/main.py +++ b/.bin/Scripts/settings/main.py @@ -43,7 +43,7 @@ BACKUP_SERVERS = [ { 'IP': '10.120.1.23', 'Name': 'Server1201', 'Mounted': False, - 'Share': r'Public\Backups', + 'Share': r'Public\TEMP', 'User': 'cx', 'Pass': '', 'RW-User': 'it',