Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password.

So far I have:

if [[ "$(/usr/bin/whoami)" != "root" ]]; then 
    sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2
        if [ ! $? = 0 ]; then 
            echo "You entered an invalid password or you are not an admin/sudoer user. Script aborted."
            exit 1
        fi
fi

which does get the prompt, but the rest of the script does not run with sudo privileges as needed. What do I need to do for this to apply to the whole script?

Thanks.

the way your script is written is to only run the date comand with sudo. if you want to run other commands you should probably create a second script and call that instead of date.

Try this code:

sudo -p "Please enter you admin password: " whoami 1>/dev/null && {sudo whoami;sudo whoami;whoami;sudo -k}

Let sudo do the work instead of doubling the effort. Note if the user fails to type their correct admin password or is not an admin user nothing else will run. Each command run as root must be preference with sudo. sudo -k will remove the timestamp so no other sudo commands will run without authentication.