#!/bin/bash

# This requires SSH access to the deployment server, and the user you are SSHing as needs
# +rwx permissions for the target directory.
#
# 1. On macOS, make sure to install rsync from homebrew.
# 2. You can pass-thru options such as '-n' for a dry-run

. environments/shell-env
if [ -e environments/shell-env-local ]; then
    . environments/shell-env-local
fi

# Rsync options:
# -r: recursive
# -v: verbose
# -z: compress
# --checksum: if file size and time match, do a checksum at both ends to see if the files are really identical.
# -e: use external command to connect via ssh
# --filter: excluding things in .gitignore
# --exclude: multiple excludes to remove localized directories and files

rsync -rvz --checksum -e "ssh -p $CV_DEPLOY_PORT" --links \
 --filter=":- .gitignore" \
 --exclude 'local' --exclude 'sessions' --exclude '.git' \
 --exclude 'logs' --exclude '*node_modules' --exclude 'run' \
 --exclude '*-local*' --exclude '*.example' --exclude "*~" \
 --exclude 'eg' --exclude '.DS_Store' \
 $@ \
 --delete $CV_ROOT $CV_DEPLOY_USER@$CV_DEPLOY_HOST:$CV_DEPLOY_DIR
