Skip to content

Instantly share code, notes, and snippets.

@sytranvn
Last active June 10, 2020 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sytranvn/24954a35e42d370d3d23d19355036b65 to your computer and use it in GitHub Desktop.
Save sytranvn/24954a35e42d370d3d23d19355036b65 to your computer and use it in GitHub Desktop.
Sync home data
#!/usr/bin/env sh
# USAGE: transfer.sh [--ignore-existing] [user@]host[:port] <source> <destination>
ie=""
if [ "$1" = "--ignore-existing" ]; then
ie="$1"
shift
fi
if [ -z "$1" ]; then
echo "USAGE:\n\t $0 [--ignore-existing] [user@]host[:port] <source> <destination>"
exit 1
fi
echo 'Install inital packages'
sudo apt install -y openssh-client curl rsync
echo 'Generate ssh key'
cat /dev/zero | ssh-keygen -q -N ""
echo 'Sign in remote host'
ssh-copy-id -i $HOME/.ssh/id_rsa.pub -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" $1
echo 'Transfer files'
rsync -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -azvpPhl "$ie" "$1:$2" $3
echo 'Finished'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment