--- /usr/bin/ssh-copy-id	2006-11-01 00:03:52.000000000 +0100
+++ /usr/bin/ssh-copy-id.samy	2007-07-04 16:31:42.000000000 +0200
@@ -5,46 +5,112 @@
 # Obviously, the remote machine must accept password authentication,
 # or one of the other keys in your ssh-agent, for this to work.
 
+# Modded by H3rbz <h3rbz@ascha.org> to except a portnumber and use getopts for jsust
+# a little more extendability.
+USAGE="Usage: $0 [-hct] [-p port] [-i id] [-a auth_keys_file] [user@]machine"
+HELP="Help:
+-h\tPrint this help message.
+-t\tTest ssh-copy-id.samy. Copies keys to \`~/.ssh/authorized_keys_test'.
+-a\tSpecify a custom remote key authorization file.
+-c\tCheck remote authorized_keys file. Opens the file in a pager
+\tafter successful transfer.
+"
 ID_FILE="${HOME}/.ssh/identity.pub"
-
-if [ "-i" = "$1" ]; then
-  shift
-  # check if we have 2 parameters left, if so the first is the new ID file
-  if [ -n "$2" ]; then
-    if expr "$1" : ".*\.pub" ; then
-      ID_FILE="$1"
-    else
-      ID_FILE="$1.pub"
-    fi
-    shift         # and this should leave $1 as the target name
-  fi
-else
-  if [ x$SSH_AUTH_SOCK != x ] ; then
-    GET_ID="$GET_ID ssh-add -L"
-  fi
+AUTH_KEYS_FILE="~/.ssh/authorized_keys"
+PORTNUMBER_EXP="-p 22"
+HOST_EXP=''
+DO_CHECK=''
+WE_ARE_TEST='no'
+while getopts "hcti:p:a:" options
+do
+	case "$options" in
+    	i )
+		matches=`expr "$OPTARG" : ".*\.pub"`
+		if [ $matches -gt 0 ];
+		then
+			ID_FILE="$OPTARG"
+		else
+			ID_FILE="$OPTARG.pub"
+		fi
+	;;
+	a )
+		AUTH_KEYS_FILE="$OPTARG"
+		if [ "$WE_ARE_TEST" == "yes" ];
+		then
+			AUTH_KEYS_FILE="${AUTH_KEYS_FILE}_test"
+		fi
+	;;
+	p )
+		PORTNUMBER_EXP="-p $OPTARG"
+	;;
+	t )
+		AUTH_KEYS_FILE="${AUTH_KEYS_FILE}_test";
+		WE_ARE_TEST='yes'
+	;;
+	c )
+		DO_CHECK='check'
+	;;
+	h )
+		echo $USAGE
+		echo -e "$HELP"
+		exit
+	;;
+	\? )
+		echo "ERROR: Option needs parameter" >&2
+		echo $USAGE >&2
+		exit 1
+	;;
+	* )
+		echo "ERROR: Illegal option(s)" >&2
+		echo $USAGE >&2
+		exit 1
+	;;
+	esac
+done
+# Skip to last in $@:
+shift $((OPTIND-1));
+HOST_EXP="$1"
+if [ -z $HOST_EXP ];
+then
+	echo "ERROR: No host specified" >&2
+	echo $USAGE >&2
+	exit 1
 fi
-
-if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
-  GET_ID="cat ${ID_FILE}"
-fi
-
-if [ -z "`eval $GET_ID`" ]; then
-  echo "$0: ERROR: No identities found" >&2
-  exit 1
+# The rest is pretty much as it was, except for the addition
+# of extra arguments in the final call to ssh and the use of '~' in
+# the path to the authorized_keys file (any good reasons to leave it out?).
+if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ];
+then
+	GET_ID="cat ${ID_FILE}"
 fi
 
-if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
-  echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
-  exit 1
+if [ -z "`eval $GET_ID`" ];
+then
+	echo "$0: ERROR: No identities found" >&2
+	exit 1
 fi
 
-{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1
+{ eval "$GET_ID" ; } | ssh $PORTNUMBER_EXP $HOST_EXP "umask 077; test -d .ssh || mkdir .ssh ; cat >> $AUTH_KEYS_FILE" || exit 1
 
-cat <<EOF
-Now try logging into the machine, with "ssh '$1'", and check in:
-
-  .ssh/authorized_keys
-
-to make sure we haven't added extra keys that you weren't expecting.
-
-EOF
+# This original text is pretty lame(IMHO) :] I'm replacing it and saving the
+# original, for now...
+#cat <<EOF
+#Now try logging into the machine, with "ssh '$HOST_EXP'", and check in:
+#
+#  .ssh/authorized_keys
+#
+#to make sure we haven't added extra keys that you weren't expecting.
+#
+#EOF
+
+# My version:
+CHECK_MESSAGE="You can check the remote hosts authorized_keys file to make sure
+we haven't added extra keys that you weren't expecting. Use e.g.:
+
+ssh -t $PORTNUMBER_EXP $HOST_EXP \"less $AUTH_KEYS_FILE\""
+# Report:
+if [ -z "$DO_CHECK" ]; then
+	echo $CHECK_MESSAGE >&2
+else
+	ssh -t $PORTNUMBER_EXP $HOST_EXP "less $AUTH_KEYS_FILE"
+fi
