If the user passes a directory when updating via-u <dir> then this code selects a random file from the directory and uses it instead.
This is useful so one can update the lock image on boot and have a random image every reboot (Adds variety)
repeated tasks with pre-lock, lock, post-lock are made into functions.
spaces + tabs => tabs only
removed consecutive empty lines
moved resolution rectangles calculation to --update where it's only used