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.
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;;
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