This question already has an answer here:
I am writing a script to download build and install a bunch of packages. Building sometimes takes a while, and installing requires root priviledges:
make; sudo make install
What happens alot is that when a build takes a while I need to keep entering my password. I want to be able to only enter it once. I could call the script with root access, but then (as I understand it) every call it makes will be with root priviledges. I don't want this because then, eg., many files and folders get created that can't be deleted without root access.
so what is the best way to do this?