dtucker@openbsd.org | f689adb | 2017-12-11 11:41:56 +0000 | [diff] [blame] | 1 | # $OpenBSD: scp-uri.sh,v 1.2 2017/12/11 11:41:56 dtucker Exp $ |
millert@openbsd.org@openbsd.org | 116b1b4 | 2017-10-24 19:33:32 +0000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="scp-uri" |
| 5 | |
| 6 | #set -x |
| 7 | |
| 8 | COPY2=${OBJ}/copy2 |
| 9 | DIR=${COPY}.dd |
| 10 | DIR2=${COPY}.dd2 |
| 11 | |
| 12 | SRC=`dirname ${SCRIPT}` |
| 13 | cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp |
| 14 | chmod 755 ${OBJ}/scp-ssh-wrapper.scp |
| 15 | scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp" |
| 16 | export SCP # used in scp-ssh-wrapper.scp |
| 17 | |
| 18 | scpclean() { |
| 19 | rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} |
| 20 | mkdir ${DIR} ${DIR2} |
| 21 | } |
| 22 | |
| 23 | # Remove Port and User from ssh_config, we want to rely on the URI |
| 24 | cp $OBJ/ssh_config $OBJ/ssh_config.orig |
| 25 | egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config |
| 26 | |
| 27 | verbose "$tid: simple copy local file to remote file" |
| 28 | scpclean |
| 29 | $SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed" |
| 30 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 31 | |
| 32 | verbose "$tid: simple copy remote file to local file" |
| 33 | scpclean |
| 34 | $SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed" |
| 35 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 36 | |
| 37 | verbose "$tid: simple copy local file to remote dir" |
| 38 | scpclean |
| 39 | cp ${DATA} ${COPY} |
| 40 | $SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed" |
| 41 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 42 | |
| 43 | verbose "$tid: simple copy remote file to local dir" |
| 44 | scpclean |
| 45 | cp ${DATA} ${COPY} |
| 46 | $SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed" |
| 47 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 48 | |
| 49 | verbose "$tid: recursive local dir to remote dir" |
| 50 | scpclean |
| 51 | rm -rf ${DIR2} |
| 52 | cp ${DATA} ${DIR}/copy |
| 53 | $SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed" |
dtucker@openbsd.org | f689adb | 2017-12-11 11:41:56 +0000 | [diff] [blame] | 54 | for i in $(cd ${DIR} && echo *); do |
| 55 | cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy" |
| 56 | done |
millert@openbsd.org@openbsd.org | 116b1b4 | 2017-10-24 19:33:32 +0000 | [diff] [blame] | 57 | |
| 58 | verbose "$tid: recursive remote dir to local dir" |
| 59 | scpclean |
| 60 | rm -rf ${DIR2} |
| 61 | cp ${DATA} ${DIR}/copy |
| 62 | $SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed" |
dtucker@openbsd.org | f689adb | 2017-12-11 11:41:56 +0000 | [diff] [blame] | 63 | for i in $(cd ${DIR} && echo *); do |
| 64 | cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy" |
| 65 | done |
millert@openbsd.org@openbsd.org | 116b1b4 | 2017-10-24 19:33:32 +0000 | [diff] [blame] | 66 | |
| 67 | # TODO: scp -3 |
| 68 | |
| 69 | scpclean |
| 70 | rm -f ${OBJ}/scp-ssh-wrapper.exe |