deploy/copy.sh
14 lines · 551 bytes · executable
1#!/bin/sh
2# Copy one file to the host: rsync when the host has it, since a stalled
3# transfer then resumes and the bytes are compressed on the wire; scp -C
4# otherwise. Both deploy targets go through here so neither can assume a
5# tool the host lacks.
6#
7# deploy/copy.sh <host> <port> <local-file> <remote-path>
8set -eu
9host=$1 port=$2 src=$3 dst=$4
10if ssh -p "$port" "root@$host" 'command -v rsync >/dev/null 2>&1'; then
11 rsync --partial --inplace -z -e "ssh -p $port" "$src" "root@$host:$dst"
12else
13 scp -C -P "$port" "$src" "root@$host:$dst"
14fi