From: Iain Patterson Date: Fri, 20 May 2016 15:45:28 +0000 (+0100) Subject: Copy became script to target directory. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=33e89a52bbbf10cc2294c7589711b17d7470dfcc;p=profile.git Copy became script to target directory. Ensure the became script can be run when the source user's home directory is not readable, by copying the script itself to the target directory if the -D flag is used instead of -d. --- diff --git a/opt/bin/become b/opt/bin/become index ea4926d..07801c3 100755 --- a/opt/bin/become +++ b/opt/bin/become @@ -3,9 +3,14 @@ chdir=0 kerberos=0 x11=0 +copy=0 dir= -while getopts ":cd:kx" opt; do +while getopts ":D:cd:kx" opt; do case $opt in + D) + copy=1 + dir=$OPTARG + ;; c) chdir=1;; d) dir=$OPTARG;; k) kerberos=1;; @@ -14,9 +19,17 @@ while getopts ":cd:kx" opt; do done shift $((OPTIND-1)) -if [ -z "$dir" ]; then - dir=${0%/*} - [ "$dir" = "$0" -o "$dir" = "." ] && dir=$PWD +srcdir=${0%/*} +[ "$srcdir" = "$0" -o "$srcdir" = "." ] && srcdir=$PWD +if [ -n "$dir" ]; then + if [ $copy = 1 ]; then + if ! cp "$srcdir/became" "$dir/became"; then + echo >&2 "Failed to copy $srcdir/became to $dir!" + exit 100 + fi + fi +else + dir=$srcdir fi user="$1"; shift