#!/usr/bin/env bash set -euo pipefail REMOTE="${1:-root@43.165.195.39}" REMOTE_DIR="${REMOTE_DIR:-/opt/chatapp-test}" MONITOR_REPO_URL="${MONITOR_REPO_URL:-git@gitea.haiyihy.com:hy/hy-app-monitor.git}" MONITOR_BRANCH="${MONITOR_BRANCH:-main}" MONITOR_CHECKOUT_DIR="${MONITOR_CHECKOUT_DIR:-$REMOTE_DIR/git/hy-app-monitor}" ssh "$REMOTE" \ "REMOTE_DIR='$REMOTE_DIR' MONITOR_REPO_URL='$MONITOR_REPO_URL' MONITOR_BRANCH='$MONITOR_BRANCH' MONITOR_CHECKOUT_DIR='$MONITOR_CHECKOUT_DIR' bash -s" <<'REMOTE_BOOTSTRAP' set -euo pipefail REMOTE_DIR="${REMOTE_DIR:-/opt/chatapp-test}" MONITOR_REPO_URL="${MONITOR_REPO_URL:-git@gitea.haiyihy.com:hy/hy-app-monitor.git}" MONITOR_BRANCH="${MONITOR_BRANCH:-main}" MONITOR_CHECKOUT_DIR="${MONITOR_CHECKOUT_DIR:-$REMOTE_DIR/git/hy-app-monitor}" export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh -o StrictHostKeyChecking=accept-new}" install_minimal_packages() { if command -v git >/dev/null 2>&1 && command -v rsync >/dev/null 2>&1; then return fi if command -v dnf >/dev/null 2>&1; then dnf -y install git rsync ca-certificates >/dev/null elif command -v apt-get >/dev/null 2>&1; then apt-get update >/dev/null apt-get install -y git rsync ca-certificates >/dev/null else echo "unsupported Linux distribution: missing dnf/apt-get" >&2 exit 1 fi } sync_repo() { local dir="$1" local url="$2" local branch="$3" local stamp mkdir -p "$(dirname "$dir")" if [ -e "$dir" ] && [ ! -d "$dir/.git" ]; then stamp="$(date +%Y%m%d%H%M%S)" mv "$dir" "$dir.pre-git-$stamp" echo "moved non-git directory to $dir.pre-git-$stamp" fi if [ ! -d "$dir/.git" ]; then git clone --branch "$branch" "$url" "$dir" fi git -C "$dir" remote set-url origin "$url" git -C "$dir" fetch --prune origin "$branch" git -C "$dir" checkout -B "$branch" "origin/$branch" git -C "$dir" reset --hard "origin/$branch" } install_minimal_packages sync_repo "$MONITOR_CHECKOUT_DIR" "$MONITOR_REPO_URL" "$MONITOR_BRANCH" exec bash "$MONITOR_CHECKOUT_DIR/testbox/scripts/deploy-from-git-remote.sh" REMOTE_BOOTSTRAP