toes/scripts/deploy.sh

41 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
# Get absolute path of this script's directory
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$SCRIPT_DIR/.."
# Load config
source "$ROOT_DIR/scripts/config.sh"
git push origin main
# SSH to target and update
ssh "$HOST" "cd $DEST && git pull origin main && bun run build"
# Sync default apps/tools from repo to APPS_DIR
echo "=> Syncing default apps..."
ssh "$HOST" bash -s "$DEST" "$APPS_DIR" <<'SCRIPT'
DEST="$1"
APPS_DIR="$2"
for app_dir in "$DEST"/apps/*/; do
app=$(basename "$app_dir")
for version_dir in "$app_dir"*/; do
[ -d "$version_dir" ] || continue
version=$(basename "$version_dir")
[ -f "$version_dir/package.json" ] || continue
target="$APPS_DIR/$app/$version"
mkdir -p "$target"
cp -a "$version_dir"/. "$target"/
rm -f "$APPS_DIR/$app/current"
echo " $app/$version"
(cd "$target" && bun install --frozen-lockfile 2>/dev/null || bun install)
done
done
SCRIPT
ssh "$HOST" "sudo systemctl restart toes.service"
echo "=> Deployed to $HOST"
echo "=> Visit $URL"