How to execute a script as super user first checking the user and getting pass from askpass if not super user

I just call sudo if the program needs root permissions, but doesn't have:

#!/bin/bash
if [ $(id -u) != 0 ]; then
   echo "This script requires root permissions"
   sudo "$0" "$@"
   exit
fi

"$0" contains the name of the script, "$@" optional arguments. It may be omitted if your program does not accept arguments.

Note: this shellscript is expected to be run in a shell, if this script should run as GUI, use something like gksu or kdesudo instead of sudo.