mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-08-06 08:22:51 +00:00
- Add internal/webui/ package with //go:build embedui tag for optional SPA embedding (handler.go serves static files with SPA fallback) - Add internal/version/ shared semver comparison (DRY: extracted from gateway/update_check.go and updater/updater.go) - Enhance UpdateChecker: release notes, ETag caching, filter lite-v* tags - Add web UI build stage to Dockerfile with ENABLE_EMBEDUI build arg - Simplify CI: 7 Docker variants → 4 (base, latest, full, otel) - Add SHA256 checksums job to release workflow - Add Makefile build-full target (embeds web UI in Go binary) - Default make up now embeds web UI (no separate nginx needed) - Add WITH_WEB_NGINX=1 flag for optional nginx reverse proxy - Update README + 30 translated READMEs: make up, port 18790 - Update docker-compose comments and prepare-env.sh - About dialog: show release notes with markdown rendering - Health card: amber badge for available updates BREAKING: Default Docker setup no longer requires selfservice overlay. Web dashboard served at :18790 (same port as API).
94 lines
2.5 KiB
Bash
Executable File
94 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# prepare-env.sh — Create or update .env with auto-generated secrets.
|
|
# Safe to run multiple times: only fills in missing values, never overwrites existing ones.
|
|
#
|
|
# Usage: ./prepare-env.sh
|
|
|
|
set -euo pipefail
|
|
|
|
ENV_FILE=".env"
|
|
|
|
# --- helpers ---
|
|
|
|
gen_hex() { openssl rand -hex "$1" 2>/dev/null || head -c "$1" /dev/urandom | xxd -p | tr -d '\n'; }
|
|
|
|
# Read current value from .env (KEY=VALUE format, no export prefix).
|
|
get_env_val() {
|
|
local key="$1"
|
|
if [ -f "$ENV_FILE" ]; then
|
|
grep -E "^${key}=" "$ENV_FILE" 2>/dev/null | tail -1 | cut -d'=' -f2-
|
|
fi
|
|
}
|
|
|
|
# Set a key in .env. Appends if missing, replaces if empty.
|
|
set_env_val() {
|
|
local key="$1" val="$2"
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
echo "${key}=${val}" >> "$ENV_FILE"
|
|
elif grep -qE "^${key}=" "$ENV_FILE" 2>/dev/null; then
|
|
# Key exists — only replace if current value is empty
|
|
local current
|
|
current="$(get_env_val "$key")"
|
|
if [ -z "$current" ]; then
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
sed -i '' "s|^${key}=.*|${key}=${val}|" "$ENV_FILE"
|
|
else
|
|
sed -i "s|^${key}=.*|${key}=${val}|" "$ENV_FILE"
|
|
fi
|
|
fi
|
|
else
|
|
echo "${key}=${val}" >> "$ENV_FILE"
|
|
fi
|
|
}
|
|
|
|
# --- main ---
|
|
|
|
echo ""
|
|
echo "=== GoClaw Environment Preparation ==="
|
|
echo ""
|
|
|
|
# 1. Create .env from .env.example if it doesn't exist
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
if [ -f ".env.example" ]; then
|
|
# Strip 'export ' prefix for Docker Compose compatibility
|
|
sed 's/^export //' .env.example > "$ENV_FILE"
|
|
chmod 600 "$ENV_FILE"
|
|
echo " [created] .env from .env.example"
|
|
else
|
|
touch "$ENV_FILE"
|
|
chmod 600 "$ENV_FILE"
|
|
echo " [created] .env (empty)"
|
|
fi
|
|
else
|
|
echo " [exists] .env"
|
|
fi
|
|
|
|
# 2. Auto-generate GOCLAW_ENCRYPTION_KEY if missing
|
|
current_enc="$(get_env_val GOCLAW_ENCRYPTION_KEY)"
|
|
if [ -z "$current_enc" ]; then
|
|
new_key="$(gen_hex 32)"
|
|
set_env_val "GOCLAW_ENCRYPTION_KEY" "$new_key"
|
|
echo " [generated] GOCLAW_ENCRYPTION_KEY"
|
|
else
|
|
echo " [exists] GOCLAW_ENCRYPTION_KEY"
|
|
fi
|
|
|
|
# 3. Auto-generate GOCLAW_GATEWAY_TOKEN if missing
|
|
current_tok="$(get_env_val GOCLAW_GATEWAY_TOKEN)"
|
|
if [ -z "$current_tok" ]; then
|
|
new_tok="$(gen_hex 16)"
|
|
set_env_val "GOCLAW_GATEWAY_TOKEN" "$new_tok"
|
|
echo " [generated] GOCLAW_GATEWAY_TOKEN"
|
|
else
|
|
echo " [exists] GOCLAW_GATEWAY_TOKEN"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Done ==="
|
|
echo ""
|
|
echo " Run: make up"
|
|
echo ""
|
|
echo " Web dashboard: http://localhost:18790"
|
|
echo " With separate nginx: make up WITH_WEB_NGINX=1 → http://localhost:3000"
|
|
echo ""
|