add static-site-deploy

This commit is contained in:
朱潮 2026-03-08 13:38:36 +08:00
parent 6b2ef1137a
commit 2280bac2d1
2 changed files with 118 additions and 2 deletions

View File

@ -10,24 +10,27 @@ triggers:
- download from vps
- list files on vps
- browse ftp
- read file from vps
- 部署静态网站
- 部署HTML
- 部署到VPS
- 从服务器下载
- 浏览服务器文件
- 读取服务器文件
---
# Static Site Deploy
Upload, download, and browse static HTML files on a VPS via FTP.
Upload, download, read, and browse static HTML files on a VPS via FTP.
## Use when
- Deploying static HTML/CSS/JS files to a VPS
- Downloading deployed files from VPS
- Reading file contents directly from VPS (without downloading to local)
- Browsing files and directories on VPS
- Publishing a single-page app, landing page, or documentation site
- User says "deploy", "upload to server", "publish site", "download from server", or "list files"
- User says "deploy", "upload to server", "publish site", "download from server", "read file", or "list files"
## Prerequisites
@ -91,6 +94,7 @@ URL: https://domain/path/to/deploy/
- Use `scripts/deploy.sh` for uploading files to VPS
- Use `scripts/download.sh` for downloading files from VPS
- Use `scripts/list.sh` for browsing FTP directory contents
- Use `scripts/read.sh` for reading file contents directly from FTP (output to stdout)
- Verify ASSISTANT_ID environment variable is set before calling scripts
- Show the command to the user before executing
- The scripts handle all FTP operations, progress display, and verification
@ -130,3 +134,20 @@ The download script will:
- Download files from `/{bot_id}/{project_name}/`
- Save to the specified target directory
- Show download summary and file count
## Read File Workflow
To read a file's content directly from VPS (output to stdout, no local download):
```bash
# Read a file from a project
bash scripts/read.sh <project-name>/<path/to/file.html>
# With custom config
bash scripts/read.sh <project-name>/index.html --config /path/to/config.yml
```
The read script will:
- Read bot_id from ASSISTANT_ID environment variable
- Fetch the file from `/{bot_id}/{file-path}` via FTP
- Output file contents directly to stdout

View File

@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -euo pipefail
# Static Site Read - FTP file content reader
# Usage: read.sh <file-path> [--config path]
# ─── Argument Parsing ───────────────────────────────────────────────
FILE_PATH=""
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="${SCRIPT_DIR}/static-site-deploy.yml"
while [[ $# -gt 0 ]]; do
case "$1" in
--config)
CONFIG_FILE="$2"
shift 2
;;
*)
if [[ -z "$FILE_PATH" ]]; then
FILE_PATH="$1"
else
echo "Error: unexpected argument '$1'" >&2
exit 1
fi
shift
;;
esac
done
if [[ -z "$FILE_PATH" ]]; then
echo "Usage: read.sh <file-path> [--config path]" >&2
echo " file-path: project-name/path/to/file.html" >&2
exit 1
fi
# Read bot_id from environment variable
BOT_ID="${ASSISTANT_ID:-}"
if [[ -z "$BOT_ID" ]]; then
echo "Error: ASSISTANT_ID environment variable is not set" >&2
exit 1
fi
# ─── Config Parsing ─────────────────────────────────────────────────
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "Error: config file '$CONFIG_FILE' not found" >&2
exit 1
fi
# Simple YAML parser (no external dependencies)
parse_yaml() {
local key="$1"
grep "^${key}:" "$CONFIG_FILE" | sed "s/^${key}:[[:space:]]*//" | sed 's/[[:space:]]*#.*//' | sed 's/[[:space:]]*$//' | sed 's/^[\"'\'']\(.*\)[\"'\'']$/\1/'
}
HOST=$(parse_yaml "host")
FTP_USER=$(parse_yaml "ftp_user")
FTP_PASS=$(parse_yaml "ftp_pass")
FTP_PORT=$(parse_yaml "ftp_port")
USE_FTPS=$(parse_yaml "use_ftps")
WEB_ROOT=$(parse_yaml "web_root")
# Defaults
FTP_PORT="${FTP_PORT:-21}"
USE_FTPS="${USE_FTPS:-true}"
# Validate required fields
for field in HOST FTP_USER FTP_PASS WEB_ROOT; do
if [[ -z "${!field}" ]]; then
echo "Error: missing required config field: $(echo "$field" | tr '[:upper:]' '[:lower:]')" >&2
exit 1
fi
done
REMOTE_PATH="${WEB_ROOT}/${BOT_ID}/${FILE_PATH}"
# ─── Read File ─────────────────────────────────────────────────────
curl_ssl_flag=""
if [[ "$USE_FTPS" == "true" ]]; then
curl_ssl_flag="--ssl-reqd"
fi
ftp_url="ftp://${FTP_USER}:${FTP_PASS}@${HOST}:${FTP_PORT}${REMOTE_PATH}"
content=$(curl -s $curl_ssl_flag "$ftp_url" 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to read file '${FILE_PATH}'" >&2
echo "$content" >&2
exit 1
fi
echo "$content"