Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:50:01 +08:00
commit 0a3981a4f1
12 changed files with 1496 additions and 0 deletions

View File

@@ -0,0 +1,196 @@
#!/bin/bash
# Setup script for fs-cli in FirstSpirit projects
# This script downloads and extracts fs-cli to .fs-cli/ directory
set -e
PROJECT_ROOT="$(pwd)"
FS_CLI_DIR="$PROJECT_ROOT/.fs-cli"
DEFAULT_FS_CLI_VERSION="4.8.6"
echo "========================================="
echo "FirstSpirit CLI Setup"
echo "========================================="
echo ""
# Step 1: Prompt for fs-cli version
read -p "Enter fs-cli version to download [$DEFAULT_FS_CLI_VERSION]: " FS_CLI_VERSION
FS_CLI_VERSION=${FS_CLI_VERSION:-$DEFAULT_FS_CLI_VERSION}
# Step 2: Create .fs-cli directory
echo ""
echo "Creating .fs-cli directory..."
mkdir -p "$FS_CLI_DIR"
# Step 3: Download fs-cli
DOWNLOAD_URL="https://github.com/e-Spirit/FSDevTools/releases/download/${FS_CLI_VERSION}/fs-cli-${FS_CLI_VERSION}.tar.gz"
TARBALL="$FS_CLI_DIR/fs-cli-${FS_CLI_VERSION}.tar.gz"
echo "Downloading fs-cli ${FS_CLI_VERSION}..."
echo "URL: $DOWNLOAD_URL"
if command -v curl &> /dev/null; then
curl -L -o "$TARBALL" "$DOWNLOAD_URL"
elif command -v wget &> /dev/null; then
wget -O "$TARBALL" "$DOWNLOAD_URL"
else
echo "Error: Neither curl nor wget found. Please install one of them."
exit 1
fi
# Step 4: Extract and flatten directory structure
echo "Extracting fs-cli..."
tar -xzf "$TARBALL" -C "$FS_CLI_DIR"
# Move contents from fs-cli-VERSION/ to .fs-cli/ directly
mv "$FS_CLI_DIR/fs-cli-${FS_CLI_VERSION}"/* "$FS_CLI_DIR/"
mv "$FS_CLI_DIR/fs-cli-${FS_CLI_VERSION}"/.[!.]* "$FS_CLI_DIR/" 2>/dev/null || true
rmdir "$FS_CLI_DIR/fs-cli-${FS_CLI_VERSION}"
rm "$TARBALL"
echo ""
echo "✓ fs-cli ${FS_CLI_VERSION} downloaded and extracted"
echo ""
# Step 5: Prompt for FirstSpirit version
read -p "Enter your FirstSpirit server version (e.g., 2025.01, 2024.09): " FS_VERSION
# Step 6: Instructions for fs-isolated-runtime.jar
echo ""
echo "========================================="
echo "IMPORTANT: Manual Step Required"
echo "========================================="
echo ""
echo "You need to obtain fs-isolated-runtime.jar for FirstSpirit ${FS_VERSION}"
echo ""
echo "Option 1: From your FirstSpirit server"
echo " 1. SSH into your FirstSpirit server"
echo " 2. Navigate to: <FS_INSTALL>/server/lib-isolated/"
echo " 3. Copy fs-isolated-runtime.jar to:"
echo " $FS_CLI_DIR/lib/fs-isolated-runtime.jar"
echo ""
echo "Option 2: From FirstSpirit developer portal"
echo " 1. Login to e-Spirit developer portal"
echo " 2. Download fs-isolated-runtime.jar for version ${FS_VERSION}"
echo " 3. Copy it to:"
echo " $FS_CLI_DIR/lib/fs-isolated-runtime.jar"
echo ""
echo "Press Enter when you have placed fs-isolated-runtime.jar in the lib folder..."
read
# Step 7: Validate jar exists
JAR_PATH="$FS_CLI_DIR/lib/fs-isolated-runtime.jar"
if [ ! -f "$JAR_PATH" ]; then
echo ""
echo "⚠ Warning: fs-isolated-runtime.jar not found at:"
echo " $JAR_PATH"
echo ""
echo "Please place the file there before running fs-cli commands."
echo ""
else
echo ""
echo "✓ fs-isolated-runtime.jar found"
echo ""
fi
# Step 8: Create .env file
ENV_FILE="$PROJECT_ROOT/.env"
ENV_EXAMPLE="$PROJECT_ROOT/.env.example"
if [ ! -f "$ENV_FILE" ]; then
echo "Creating .env file for configuration..."
echo ""
read -p "FirstSpirit server host [localhost]: " FS_HOST
FS_HOST=${FS_HOST:-localhost}
read -p "FirstSpirit server port [8000]: " FS_PORT
FS_PORT=${FS_PORT:-8000}
read -p "Connection mode (HTTP/HTTPS/SOCKET) [HTTP]: " FS_MODE
FS_MODE=${FS_MODE:-HTTP}
read -p "FirstSpirit project name: " FS_PROJECT
read -p "FirstSpirit username: " FS_USER
read -s -p "FirstSpirit password: " FS_PASSWORD
echo ""
cat > "$ENV_FILE" << EOF
# FirstSpirit Server Configuration
fshost=${FS_HOST}
fsport=${FS_PORT}
fsmode=${FS_MODE}
fsproject=${FS_PROJECT}
# FirstSpirit Credentials (KEEP SECRET - DO NOT COMMIT)
fsuser=${FS_USER}
fspwd=${FS_PASSWORD}
# fs-cli Configuration (for reference only, not used by fs-cli)
FS_CLI_VERSION=${FS_CLI_VERSION}
FS_VERSION=${FS_VERSION}
EOF
# Create .env.example (without secrets)
cat > "$ENV_EXAMPLE" << EOF
# FirstSpirit Server Configuration
fshost=localhost
fsport=8000
fsmode=HTTP
fsproject=your-project-name
# FirstSpirit Credentials (KEEP SECRET - DO NOT COMMIT)
fsuser=your-username
fspwd=your-password
# fs-cli Configuration (for reference only, not used by fs-cli)
FS_CLI_VERSION=${FS_CLI_VERSION}
FS_VERSION=${FS_VERSION}
EOF
echo ""
echo "✓ Created .env and .env.example files"
echo ""
fi
# Step 9: Update .gitignore
GITIGNORE="$PROJECT_ROOT/.gitignore"
if [ -f "$GITIGNORE" ]; then
if ! grep -q "^\.fs-cli/" "$GITIGNORE"; then
echo "" >> "$GITIGNORE"
echo "# FirstSpirit CLI" >> "$GITIGNORE"
echo ".fs-cli/" >> "$GITIGNORE"
echo ".env" >> "$GITIGNORE"
echo "" >> "$GITIGNORE"
echo "✓ Updated .gitignore"
else
echo "✓ .gitignore already configured"
fi
else
cat > "$GITIGNORE" << EOF
# FirstSpirit CLI
.fs-cli/
.env
EOF
echo "✓ Created .gitignore"
fi
# Step 10: Mark setup complete
echo "$FS_CLI_VERSION" > "$FS_CLI_DIR/.setup-marker"
echo "$FS_VERSION" >> "$FS_CLI_DIR/.setup-marker"
echo ""
echo "========================================="
echo "Setup Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo " 1. Verify fs-isolated-runtime.jar is in place"
echo " 2. Test connection: bash validate-environment.sh"
echo " 3. Start using fs-cli via the FirstSpirit skill"
echo ""
echo "Configuration stored in: .env"
echo "fs-cli installed at: $FS_CLI_DIR/"
echo "fs-cli version: ${FS_CLI_VERSION}"
echo ""

View File

@@ -0,0 +1,98 @@
#!/bin/bash
# Validates Java environment and fs-cli setup
set -e
PROJECT_ROOT="$(pwd)"
FS_CLI_DIR="$PROJECT_ROOT/.fs-cli"
echo "Validating FirstSpirit CLI environment..."
echo ""
# Load .env
if [ -f "$PROJECT_ROOT/.env" ]; then
source "$PROJECT_ROOT/.env"
else
echo "❌ .env file not found. Run setup-fs-cli.sh first."
exit 1
fi
# Check Java
echo "Checking Java..."
if ! command -v java &> /dev/null; then
echo "❌ Java not found. Please install Java 17 or higher."
exit 1
fi
JAVA_VERSION=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{print $1}')
if [ "$JAVA_VERSION" -lt 17 ]; then
echo "❌ Java 17+ required. Found Java $JAVA_VERSION"
exit 1
fi
echo "✓ Java $JAVA_VERSION found"
# Check JAVA_HOME
if [ -z "$JAVA_HOME" ]; then
echo "⚠ Warning: JAVA_HOME not set"
echo " Consider setting it in your shell profile"
else
echo "✓ JAVA_HOME: $JAVA_HOME"
fi
# Check fs-cli directory
if [ ! -d "$FS_CLI_DIR" ]; then
echo "❌ .fs-cli directory not found. Run setup-fs-cli.sh first."
exit 1
fi
echo "✓ .fs-cli directory exists"
# Check fs-cli installation
FS_CLI_VERSION=${FS_CLI_VERSION:-"4.8.6"}
if [ ! -d "$FS_CLI_DIR/bin" ] || [ ! -d "$FS_CLI_DIR/lib" ]; then
echo "❌ fs-cli not properly installed at: $FS_CLI_DIR"
echo " Expected bin/ and lib/ directories not found"
exit 1
fi
echo "✓ fs-cli $FS_CLI_VERSION installed"
# Check fs-isolated-runtime.jar
JAR_PATH="$FS_CLI_DIR/lib/fs-isolated-runtime.jar"
if [ ! -f "$JAR_PATH" ]; then
echo "❌ fs-isolated-runtime.jar not found at: $JAR_PATH"
echo " Please obtain it from your FirstSpirit server or developer portal"
exit 1
fi
echo "✓ fs-isolated-runtime.jar found"
# Check fs-cli executable
FS_CLI_BIN="$FS_CLI_DIR/bin/fs-cli"
if [ ! -x "$FS_CLI_BIN" ]; then
chmod +x "$FS_CLI_BIN"
fi
echo "✓ fs-cli executable ready"
# Test fs-cli help
echo ""
echo "Testing fs-cli..."
if "$FS_CLI_BIN" -h > /dev/null 2>&1; then
echo "✓ fs-cli runs successfully"
else
echo "❌ fs-cli failed to run"
exit 1
fi
# Display configuration
echo ""
echo "========================================="
echo "Environment Valid!"
echo "========================================="
echo ""
echo "Configuration:"
echo " Server: $fsmode://$fshost:$fsport"
echo " Project: $fsproject"
echo " User: $fsuser"
echo " fs-cli: $FS_CLI_VERSION"
echo " FS Version: $FS_VERSION"
echo ""
echo "Ready to use fs-cli!"
echo ""