# suexec library script if [ -z "${__suexec_sh_loaded}" ] then __suexec_sh_loaded=yes # exec a command via sudo/su # Can be used to reexec this process under su/sudo, if run like this from # the top-level: # # suexec "${0}" "${@}" # # Specify target user name with -u as the first parameter # # suexec -u user "${0}" "${@}" # # Just as exec, this will replace the current process entirely, and will not # return except upon error. suexec() { user="root" # Set name if user provided if [ "${1}" = "-u" ] then user="${2}" shift 2 fi # suexec if needed if [ "$(id -un)" != "${user}" ] then # Find a su/sudo cmd="sudo -u ${user}" [ -x "$(which sudo 2>/dev/null)" ] || cmd="su ${user} -c" exec ${cmd} "${@}" fi } fi