You can use the $EUID since the effective user id will always be 0 for sudo :)
Example:
#!/usr/bin/env bash
if [[ $EUID = 0 ]]; then
echo "sudo!"
else
echo "not sudo!"
fi
Edit:
above doesn't work, but if you just want to check this from a simple bash script you could do this hack:
#!/usr/bin/env bash
if [[ $EUID = 0 && "$(ps -o comm= | sed -n '1p')" = "su" ]]; then
echo "sudo!"
else
echo "not sudo!"
fi
Will obviously not recognize normal root shells, but actual su use is properly recognized. ( could break when called by another script :/ )
really dirty and not stable against nested su use (where sudo could still pass when ran from nested su) , it might suffice to do something like this:
#!/usr/bin/env bash
if [[ $EUID = 0 && "$(ps -o comm= | grep su | sed -n '1p')" = "su" ]]; then
echo "sudo!"
else
echo "not sudo!"
fi
... admittedly a solution from the (NOT OK!) category ...