“better” scp using rsync
authorThorsten Glaser <tg@mirbsd.org>
Wed, 9 Mar 2011 14:33:50 +0000 (15:33 +0100)
committerThorsten Glaser <tg@mirbsd.org>
Wed, 9 Mar 2011 14:33:50 +0000 (15:33 +0100)
mksh/rcp [new file with mode: 0644]

diff --git a/mksh/rcp b/mksh/rcp
new file mode 100644 (file)
index 0000000..fb790b1
--- /dev/null
+++ b/mksh/rcp
@@ -0,0 +1,69 @@
+#!/bin/mksh
+# $MirOS: contrib/hosted/tg/rcp,v 1.4 2010/10/06 18:46:18 tg Exp $
+#-
+# Copyright (c) 2009, 2010
+#      Thorsten Glaser <tg@mirbsd.org>
+#
+# Provided that these terms and disclaimer and all copyright notices
+# are retained or reproduced in an accompanying document, permission
+# is granted to deal in this work without restriction, including un-
+# limited rights to use, publicly perform, distribute, sell, modify,
+# merge, give away, or sublicence.
+#
+# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
+# the utmost extent permitted by applicable law, neither express nor
+# implied; without malicious intent or gross negligence. In no event
+# may a licensor, author or contributor be held liable for indirect,
+# direct, other damage, loss, or other issues arising in any way out
+# of dealing in the work, even if advised of the possibility of such
+# damage or existence of a defect, except proven that it results out
+# of said person's immediate fault when using the work as intended.
+
+sshx="--rsh=ssh -T"
+set -A args -- "$@"
+i=0
+is_inplace=0
+use_K=-K
+while (( i < ${#args[*]} )); do
+       case ${args[i]} {
+       (-4)
+               sshx="$sshx -4"
+               unset args[i]
+               ;;
+       (-h)
+               print -u2 "Syntax:\t$0 [-h] [-4] [--sshkey=~/.etc/ssh/id_rsa] \\"
+               print -u2 "     [«rsync_args»] source [source …] dest"
+               print -u2
+               exec rsync --help
+               ;;
+       (--sshkey=*)
+               sshx="$sshx -i '${args[i]#*=}'"
+               unset args[i]
+               ;;
+       (--inplace)
+               is_inplace=1
+               ;;
+       (--no-K|--no-keep-dirlinks)
+               use_K=
+               unset args[i]
+               ;;
+       (-K|--keep-dirlinks)
+               use_K=-K
+               unset args[i]
+               ;;
+       (-*)
+               ;;
+       (*)
+               break
+               ;;
+       }
+       let ++i
+done
+
+if (( is_inplace )); then
+       use_sparse=
+else
+       use_sparse=-S
+fi
+
+exec rsync -xzavPH $use_K $use_sparse --stats "$sshx" "${args[@]}"