-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/sh | ||
if [ "${LIB_SSH-}" ]; then | ||
return 0 | ||
fi | ||
LIB_SSH=1 | ||
. ./log.sh | ||
. ./flag.sh | ||
|
||
ssh_copy_id_help() { | ||
cat <<EOF | ||
usage: ssh_copy_id -i=id.pub host | ||
EOF | ||
} | ||
|
||
ssh_copy_id() { | ||
while flag_parse "$@"; do | ||
case "$FLAG" in | ||
h|help) | ||
ssh_copy_id_help | ||
return 1 | ||
;; | ||
i) | ||
flag_nonemptyarg && shift "$FLAGSHIFT" | ||
ID_PUB_PATH=$FLAGARG | ||
;; | ||
*) | ||
flag_errusage "unrecognized flag $FLAGRAW" | ||
;; | ||
esac | ||
done | ||
shift "$FLAGSHIFT" | ||
|
||
if [ -z "${ID_PUB_PATH-}" ]; then | ||
flag_errusage "-i for id.pub is mandatory" | ||
fi | ||
|
||
if [ $# -ne 1 ] ; then | ||
flag_errusage "only one argument for the remote host is accepted" | ||
fi | ||
|
||
REMOTE_HOST=${1-} | ||
sh_c ssh-copy-id -fi "$ID_PUB_PATH" "$REMOTE_HOST" | ||
sh_c ssh "$REMOTE_HOST" 'cat .ssh/authorized_keys \| sort -u \> .ssh/authorized_keys.dedup' | ||
sh_c ssh "$REMOTE_HOST" 'cp .ssh/authorized_keys.dedup .ssh/authorized_keys' | ||
sh_c ssh "$REMOTE_HOST" 'rm .ssh/authorized_keys.dedup' | ||
} |