Hmm, just looking at your question and your needs, why does this need to run as root, it is running the the first time they
. If you are having the user log in via a web form (as it looks from above), can't you snag their password and have the script run as them? Isn't there a way of doing this rather than running the script as root? I don't know, maybe I'm way off base, but to me that would be a little better than just blindly running the script as root.