#!/usr/bin/env bash set -euo pipefail DIST_DIR="${DIST_DIR:-dist}" REMOTE_ROOT="${RELEASE_DEPLOY_REMOTE_ROOT:-/}" HOST="${RELEASE_DEPLOY_HOST:-}" USER_NAME="${RELEASE_DEPLOY_USER:-}" PASSWORD="${RELEASE_DEPLOY_PASSWORD:-}" DEPLOY_URL="${RELEASE_DEPLOY_URL:-}" if [[ ! -d "$DIST_DIR" ]]; then echo "Missing dist directory: $DIST_DIR" >&2 exit 1 fi if ! command -v lftp >/dev/null 2>&1; then echo "lftp is required for FTP/SFTP uploads." >&2 exit 1 fi if [[ -z "$DEPLOY_URL" ]]; then if [[ -z "$HOST" || -z "$USER_NAME" || -z "$PASSWORD" ]]; then echo "Set RELEASE_DEPLOY_URL or RELEASE_DEPLOY_HOST, RELEASE_DEPLOY_USER, and RELEASE_DEPLOY_PASSWORD." >&2 exit 1 fi DEPLOY_URL="ftp://${USER_NAME}:${PASSWORD}@${HOST}" fi upload_file() { local source_file="$1" local remote_file="$2" if [[ -f "$source_file" ]]; then lftp "$DEPLOY_URL" -e "set ftp:ssl-allow true; set net:max-retries 3; set net:timeout 20; cd \"$REMOTE_ROOT\"; put -O \"$(dirname "$remote_file")\" \"$source_file\" -o \"$(basename "$remote_file")\"; bye" fi } for directory in assets resources favicons icons img sounds .well-known; do if [[ -d "$DIST_DIR/$directory" ]]; then lftp "$DEPLOY_URL" -e "set ftp:ssl-allow true; set net:max-retries 3; set net:timeout 20; cd \"$REMOTE_ROOT\"; mirror -R --only-newer --parallel=4 \"$DIST_DIR/$directory\" \"$directory\"; bye" fi done find "$DIST_DIR" -maxdepth 1 -type f \ ! -name 'index.html' \ ! -name 'release-entry.json' \ ! -name 'release-manifest.json' \ -print0 | while IFS= read -r -d '' file; do upload_file "$file" "$(basename "$file")" done upload_file "$DIST_DIR/release-manifest.json" "release-manifest.json" upload_file "$DIST_DIR/release-entry.json" "release-entry.json" upload_file "$DIST_DIR/index.html" "index.html"