Bash - Passing arguments with "$@" to either 'sudo su' or 'sh'
The only simpler way to do this I've come up with is just to sudo every time and not worry about whether you're already the right user or not.  But overall it seems pretty straight forward and it should work fine as-is.  Some other suggestions:


Indent your code with the function.  Leaving the heredoc alone is ok.
Use [[ for conditionals.  See https://unix.stackexchange.com/a/306115/79839 for more context.
It is more modern to use $() for subcommands instead of backticks (``).  Parenthesis () are also used for creating subshells so the $() is just substituting the result of a subshell.