Skip to content

Commit

Permalink
handle root vs non-root user and sudo command
Browse files Browse the repository at this point in the history
  • Loading branch information
srlefevre committed Feb 12, 2014
1 parent ad7f55d commit f633eae
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions target-config
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ find_rmt_bins() {
local x
local IFS
local e
declare -a execs=($2)
local uid
ssh_host=$1
declare -a execs=($2)
result_var=$3

#get remote users id
rmt_run $ssh_host "id -u 2> /dev/null" "uid"

#build command to run
for e in ${execs[*]}; do
cmd="$cmd x=\$(which $e);test \$? -eq 0 && echo \$x || echo 'not found';"
Expand All @@ -59,6 +62,10 @@ find_rmt_bins() {
guess_rmt_bin $ssh_host ${execs[$x]}
p="${_guess_rmt_bin}"
fi
# root doesn't need sudo
if [[ ${execs[$x]} == sudo && $uid -eq 0 ]]; then
p=' '
fi
paths="${paths}${p}"$'\n'
x=$(( x + 1 ))
done
Expand Down Expand Up @@ -105,12 +112,7 @@ while [ $# -gt 0 ];do
case $1 in
-H|--host)
shift
let pos=$(expr index "$1" @)
if [ $pos -gt 0 ]; then
HOST=${1:$pos}
else
HOST=$1
fi
HOST=$1
;;
*)
usage
Expand Down

0 comments on commit f633eae

Please sign in to comment.