#!/usr/bin/env bash
set -euo pipefail
HOST="${1:-}"
DEST="${2:-}"
BUILD_DIR="public"
TMP="$(ssh -o StrictHostKeyChecking=no "$HOST" "mktemp -d")"
tar -cz -C "$BUILD_DIR" . | ssh -o StrictHostKeyChecking=no "$HOST" "tar -xz -C '$TMP'"
ssh -o StrictHostKeyChecking=no "$HOST" "bash -lc 'shopt -s dotglob nullglob; mkdir -p \"$DEST\"; rm -rf \"$DEST\"/* \"$DEST\"/.[!.]* \"$DEST\"/..?*; mv \"$TMP\"/* \"$DEST\"/; rmdir \"$TMP\"'"
