diff --git a/remount_checker/example_mount_points.py b/remount_checker/example_mount_points.py new file mode 100644 index 0000000..8744c46 --- /dev/null +++ b/remount_checker/example_mount_points.py @@ -0,0 +1,4 @@ +mount_points = ( + # ('/mnt/external', 'mount /mnt/external') + # ('/mnt/network_drive', 'cd /mnt; mount network_drive') +) diff --git a/remount_checker/mount_points.py b/remount_checker/mount_points.py new file mode 100644 index 0000000..ac2336f --- /dev/null +++ b/remount_checker/mount_points.py @@ -0,0 +1,5 @@ +mount_points = ( + ('/mnt/btn', '/usr/bin/mount /mnt/btn'), + ('/mnt/ptp', '/usr/bin/mount /mnt/ptp'), + ('/mnt/music', '/usr/bin/mount /mnt/music') +) diff --git a/remount_checker/remount.py b/remount_checker/remount.py new file mode 100644 index 0000000..2874a8a --- /dev/null +++ b/remount_checker/remount.py @@ -0,0 +1,31 @@ +import sys +import subprocess + +try: + from mount_points import mount_points +except ImportError: + print('Couldn\'t find the mount points. Please copy the example_mount_points.py') + print('to mount_points.py and edit the file.') + sys.exit(1) + +def is_mounted(mount_point): + lines = None + with open('/proc/mounts', 'r') as f: + lines = f.readlines() + for line in lines: + if mount_point in line: + return True + return False + +if __name__ == '__main__': + for mount_point in mount_points: + if is_mounted(mount_point[0]): + print('{} is mounted'.format(mount_point[0])) + else: + print('{} is not mounted; remounting using {}'.format(mount_point[0], mount_point[1])) + subprocess.call(mount_point[1], shell=True) + if is_mounted(mount_point[0]): + print('{} if mounted again'.format(mount_point[0])) + else: + print('{} is not mounted - might need fixing'.format(mount_point[0])) +