aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2012-11-10 03:44:08 +0000
committerEitan Adler <eadler@FreeBSD.org>2012-11-10 03:44:08 +0000
commit076ea53ee56431925b3bc8ae896f897000da63d7 (patch)
tree13bfeda8cde9a7b082b57e306cf30bfb7bb4aedf /usr.bin
parent79f62ed69004b699d56e16b29fc2ac3a6d3a7d34 (diff)
downloadsrc-076ea53ee56431925b3bc8ae896f897000da63d7.tar.gz
src-076ea53ee56431925b3bc8ae896f897000da63d7.zip
Notes
Diffstat (limited to 'usr.bin')
-rwxr-xr-xusr.bin/ssh-copy-id/ssh-copy-id.sh42
1 files changed, 23 insertions, 19 deletions
diff --git a/usr.bin/ssh-copy-id/ssh-copy-id.sh b/usr.bin/ssh-copy-id/ssh-copy-id.sh
index 8f087d3ea969..94429de1bad1 100755
--- a/usr.bin/ssh-copy-id/ssh-copy-id.sh
+++ b/usr.bin/ssh-copy-id/ssh-copy-id.sh
@@ -34,19 +34,18 @@ usage() {
sendkey() {
local h="$1"
- shift 1
- local k="$@"
- echo "$k" | ssh $port -S none $options "$user$h" /bin/sh -c \''
- set -e;
- umask 077;
- keyfile=$HOME/.ssh/authorized_keys ;
- mkdir -p $HOME/.ssh/ ;
- while read alg key comment ; do
- if ! grep -sqwF "$key" "$keyfile"; then
- echo "$alg $key $comment" |
- tee -a "$keyfile" >/dev/null ;
- fi ;
- done
+ local k="$2"
+ printf "%s\n" "$k" | ssh $port -S none $options "$user$h" /bin/sh -c \'' \
+ set -e; \
+ umask 077; \
+ keyfile=$HOME/.ssh/authorized_keys ; \
+ mkdir -p -- "$HOME/.ssh/" ; \
+ while read alg key comment ; do \
+ [ -n "$key" ] || continue; \
+ if ! grep -sqwF "$key" "$keyfile"; then \
+ printf "$alg $key $comment\n" >> "$keyfile" ; \
+ fi ; \
+ done \
'\'
}
@@ -63,12 +62,17 @@ nl="
"
options=""
+IFS=$nl
+
while getopts 'i:lo:p:' arg; do
case $arg in
i)
hasarg="x"
- if [ -f "$OPTARG" ]; then
- keys="$(cat $OPTARG)$nl$keys"
+ if [ -r "$OPTARG" ]; then
+ keys="$(cat -- "$OPTARG")$nl$keys"
+ else
+ echo "File $OPTARG not found" >&2
+ exit 1
fi
;;
l)
@@ -76,10 +80,10 @@ while getopts 'i:lo:p:' arg; do
agentKeys
;;
p)
- port="-p $OPTARG"
+ port=-p$nl$OPTARG
;;
o)
- options="$options -o '$OPTARG'"
+ options=$options$nl-o$nl$OPTARG
;;
*)
usage
@@ -92,11 +96,11 @@ shift $((OPTIND-1))
if [ -z "$hasarg" ]; then
agentKeys
fi
-if [ -z "$keys" -o "$keys" = "$nl" ]; then
+if [ -z "$keys" ] || [ "$keys" = "$nl" ]; then
echo "no keys found" >&2
exit 1
fi
-if [ -z "$@" ]; then
+if [ "$#" -eq 0 ]; then
usage
fi