#!/usr/bin/env bash sudo_args=() etc_sudoers_warning() { printf "%b" "Warning: $1, falling back to call via \`/usr/bin/env\`, this breaks rules from \`/etc/sudoers\`. Run: export rvmsudo_secure_path=1 to avoid the warning, put it in shell initialization file to make it persistent. " >&2 case "${2:-}" in (cant_read) printf "%b" " In case there is no \`secure_path\` in \`/etc/sudoers\`. Run: export rvmsudo_secure_path=0 to avoid the warning, put it in shell initialization file to make it persistent. " >&2 ;; esac } while (( $# )) do case "$1" in (--trace) export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " set -o xtrace ;; (--verbose) set -o verbose ;; (-*) sudo_args+=("$1") case "$1" in (-g|-u|-p|-r|-t|-U|-C) shift sudo_args+=("${1:-}") ;; esac ;; (*) break ;; esac (( $# == 0 )) || shift done if (( $# )) then if [[ -n "${rvmsudo_secure_path}" ]] then if [[ "${rvmsudo_secure_path:-0}" == 1 ]] then sudo_args+=( "/usr/bin/env" ) fi else if [[ -f "/etc/sudoers" ]] then if [[ ! -r "/etc/sudoers" ]] then sudo_args+=( "/usr/bin/env" ) etc_sudoers_warning 'can not check `/etc/sudoers` for `secure_path`' cant_read elif \grep -E '^[[:space:]]*Defaults[[:space:]]+secure_path=' "/etc/sudoers" >/dev/null then sudo_args+=( "/usr/bin/env" ) etc_sudoers_warning '`secure_path` found in `/etc/sudoers`' found_secure_path fi fi fi eval command sudo \"\${sudo_args[@]}\" $( /usr/bin/env | awk -F= 'BEGIN{v=0;}/^[a-zA-Z_][a-zA-Z0-9_]*=/{v=1;}v==1&&$2~/^['\''\$]/{v=2;} v==1&&$2~/^\(\) \{/{v=0;} v==1&&$2~/^\(/{v=3;}v==2&&/'\''$/&&!/'\'\''$/{v=1;}v==3&&/\)$/{v=1;}v{print;}v==1{v=0;}' | GREP_OPTIONS="" \grep -E '^rvm|^gemset|^http_|^PATH|^IRBRC|RUBY|GEM' | sed 's/=\(.*\)$/="\1"/' ) \"\$@\" || { result=$? case $result in (126) printf "%b" "\nTarget user does not have access to the given command, try finding problem below:\n\n" p="$rvm_path" dirs=() while [[ "$p" != "" ]] do dirs+=( "$p" ) p="${p%/*}" done \command \ls -ld "${dirs[@]}" printf "%b" "\nIf you could not find the issue check permissions of all involved users and directories.\n\n" ;; esac exit $result } else printf "%b" "Usage:\n $0 [--trace] [--verbose] [sudo-options] command [command-options]\n" fi