#!/bin/sh
# Sync the deployable surface to a remote host for `make install`. Pins the
# include list to what the project ships: Makefile, party, party.1,
# README.md, tools/post-install.sh, and tests/ (so the host can run `make
# check` as a target-OS smoke test). This is the dev-rsync variant. The
# release-tarball variant strips tests/ as well; not implemented here.
#
# Usage:
#   ./deploy.sh <host>[:path] [extra rsync args]
#
# Path defaults to `tmux-party-src` (relative to the remote login user's
# home directory) when omitted.
#
# Examples:
#   ./deploy.sh user@domain.tld                         # → :tmux-party-src
#   ./deploy.sh user@domain.tld:dev/tmux-party-src      # explicit path
#   ./deploy.sh user@domain.tld -n                      # dry-run, default path

set -eu

dest="${1:-}"
[ -n "$dest" ] || {
    echo "usage: $0 <host>[:path] [extra rsync args]" >&2
    exit 2
}
shift

# Default path when only a host (no ":path") is given. Bare-host form
# is the common case for casual sync; an explicit path overrides it.
case "$dest" in
    *:*) ;;
    *)   dest="$dest:tmux-party-src" ;;
esac

cd "$(dirname "$0")"

exec rsync -av --delete "$@" \
    --include='/Makefile' \
    --include='/party' \
    --include='/party.1' \
    --include='/README.md' \
    --include='/tools/' \
    --include='/tools/post-install.sh' \
    --include='/tests/' \
    --include='/tests/*.bats' \
    --include='/tests/helpers.bash' \
    --exclude='*' \
    ./ "$dest"
