There's likely a way to get root without having to read the password each time, this is just what I managed to hack together. If anyone has any ideas/suggestions I would be happy to fix this ASAP!
Allow the script to run under sudo without a password.