Add non-interactive mode for LLM/automation support
Enable fully automated registration and deployment workflow without manual input prompts. New Command-Line Parameters: - --email EMAIL Email for registration - --gitea-username USERNAME Gitea username (optional, auto-detected) - --verify-code CODE Email verification code - --register Force registration mode - --help Show usage information Non-Interactive Workflows: 1. Two-step registration (wait for email): Step 1: ./deploy.sh --register --email user@example.com Step 2: ./deploy.sh --verify-code 123456 2. Full automation (if code known): ./deploy.sh --register --email user@example.com --verify-code 123456 3. Update deployment: ./deploy.sh --update Error Messages for Automation: - Clear error messages indicate missing required parameters - Suggest exact command-line syntax for non-interactive mode - Exit codes: 0 (success), 1 (error with helpful message) Benefits for LLMs: - No stdin prompts to block execution - All inputs via command-line parameters - Clear error messages with exact fix commands - Can be chained in scripts or automation tools Backward Compatible: - Interactive mode still default (no parameters) - Prompts for missing information when interactive - Auto-detects Gitea username from git config
This commit is contained in:
@@ -105,22 +105,83 @@ fi
|
||||
# ========================================
|
||||
|
||||
MODE="auto"
|
||||
if [ "$1" = "--setup" ]; then
|
||||
MODE="setup"
|
||||
elif [ "$1" = "--update" ]; then
|
||||
MODE="update"
|
||||
elif [ "$1" = "--status" ]; then
|
||||
MODE="status"
|
||||
elif [ -n "$1" ]; then
|
||||
echo "❌ Unknown option: $1"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " $0 # Auto-detect mode"
|
||||
echo " $0 --setup # Force new deployment"
|
||||
echo " $0 --update # Force update existing"
|
||||
echo " $0 --status # Check deployment status"
|
||||
exit 1
|
||||
fi
|
||||
REGISTER_EMAIL=""
|
||||
REGISTER_GITEA_USERNAME=""
|
||||
VERIFY_CODE_PARAM=""
|
||||
|
||||
# Parse arguments
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--setup)
|
||||
MODE="setup"
|
||||
shift
|
||||
;;
|
||||
--update)
|
||||
MODE="update"
|
||||
shift
|
||||
;;
|
||||
--status)
|
||||
MODE="status"
|
||||
shift
|
||||
;;
|
||||
--register)
|
||||
MODE="registration"
|
||||
shift
|
||||
;;
|
||||
--email)
|
||||
REGISTER_EMAIL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--gitea-username)
|
||||
REGISTER_GITEA_USERNAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--verify-code)
|
||||
VERIFY_CODE_PARAM="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help)
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "Modes:"
|
||||
echo " (default) Auto-detect mode (registration/verification/setup/update)"
|
||||
echo " --setup Force new deployment"
|
||||
echo " --update Force update existing deployment"
|
||||
echo " --status Check deployment status"
|
||||
echo " --register Force registration mode"
|
||||
echo ""
|
||||
echo "Registration Options:"
|
||||
echo " --email EMAIL Email for registration"
|
||||
echo " --gitea-username USERNAME Gitea username (optional, auto-detected from git)"
|
||||
echo " --verify-code CODE Verification code from email (for automation)"
|
||||
echo ""
|
||||
echo "Environment Variables Required:"
|
||||
echo " GITEA_API_TOKEN Gitea API token (for webhook setup)"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " # Interactive registration (prompts for email and verification code)"
|
||||
echo " $0"
|
||||
echo ""
|
||||
echo " # Step 1: Non-interactive registration (returns and waits)"
|
||||
echo " $0 --register --email user@example.com"
|
||||
echo ""
|
||||
echo " # Step 2: Verify with code (after checking MailHog)"
|
||||
echo " $0 --verify-code 123456"
|
||||
echo ""
|
||||
echo " # Full non-interactive (if you already have the code)"
|
||||
echo " $0 --register --email user@example.com --verify-code 123456"
|
||||
echo ""
|
||||
echo " # Update existing deployment"
|
||||
echo " $0 --update"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "❌ Unknown option: $1"
|
||||
echo "Run '$0 --help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ========================================
|
||||
# Load Environment Variables
|
||||
@@ -166,18 +227,35 @@ else
|
||||
echo "No configuration found. Let's register your account."
|
||||
echo ""
|
||||
|
||||
# Get Gitea username from .env
|
||||
if [ -z "$GITEA_USERNAME" ]; then
|
||||
echo "❌ Error: GITEA_USERNAME not set in .env"
|
||||
exit 1
|
||||
# Get Gitea username from .env or parameter
|
||||
if [ -n "$REGISTER_GITEA_USERNAME" ]; then
|
||||
GITEA_USERNAME="$REGISTER_GITEA_USERNAME"
|
||||
elif [ -z "$GITEA_USERNAME" ]; then
|
||||
# Try to auto-detect from git config
|
||||
GITEA_USERNAME=$(git config user.name 2>/dev/null || echo "")
|
||||
if [ -z "$GITEA_USERNAME" ]; then
|
||||
echo "❌ Error: GITEA_USERNAME not provided"
|
||||
echo ""
|
||||
echo "Provide it via:"
|
||||
echo " 1. --gitea-username parameter: $0 --register --email EMAIL --gitea-username USERNAME"
|
||||
echo " 2. GITEA_USERNAME in .env file"
|
||||
echo " 3. Git config: git config user.name"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prompt for email
|
||||
read -p "Enter your email address: " USER_EMAIL
|
||||
|
||||
if [ -z "$USER_EMAIL" ]; then
|
||||
echo "❌ Error: Email address is required"
|
||||
exit 1
|
||||
# Get email from parameter or prompt
|
||||
if [ -n "$REGISTER_EMAIL" ]; then
|
||||
USER_EMAIL="$REGISTER_EMAIL"
|
||||
echo "📧 Using email: $USER_EMAIL"
|
||||
else
|
||||
read -p "📧 Enter your email address: " USER_EMAIL
|
||||
if [ -z "$USER_EMAIL" ]; then
|
||||
echo "❌ Error: Email address is required"
|
||||
echo ""
|
||||
echo "For non-interactive mode, use: $0 --register --email YOUR_EMAIL"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -231,14 +309,22 @@ else
|
||||
echo "🔍 Check your email at MailHog:"
|
||||
echo " https://mailhog.goryan.io"
|
||||
echo ""
|
||||
read -p "Enter the verification code from the email: " VERIFY_CODE
|
||||
|
||||
if [ -z "$VERIFY_CODE" ]; then
|
||||
echo "❌ Error: Verification code is required"
|
||||
echo ""
|
||||
echo "You can verify later by running this script again."
|
||||
echo "Your configuration has been saved to $SAAC_CONFIG_FILE"
|
||||
exit 1
|
||||
# Use parameter if provided, otherwise prompt
|
||||
if [ -n "$VERIFY_CODE_PARAM" ]; then
|
||||
VERIFY_CODE="$VERIFY_CODE_PARAM"
|
||||
echo "🔐 Using verification code from parameter"
|
||||
else
|
||||
read -p "Enter the verification code from the email: " VERIFY_CODE
|
||||
if [ -z "$VERIFY_CODE" ]; then
|
||||
echo "❌ Error: Verification code is required"
|
||||
echo ""
|
||||
echo "You can verify later by running:"
|
||||
echo " $0 --verify-code YOUR_CODE"
|
||||
echo ""
|
||||
echo "Your configuration has been saved to $SAAC_CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -281,11 +367,19 @@ if [ "$VERIFIED" != "true" ]; then
|
||||
echo "🔍 Check your email at MailHog:"
|
||||
echo " https://mailhog.goryan.io"
|
||||
echo ""
|
||||
read -p "Enter the verification code from the email: " VERIFY_CODE
|
||||
|
||||
if [ -z "$VERIFY_CODE" ]; then
|
||||
echo "❌ Error: Verification code is required"
|
||||
exit 1
|
||||
# Use parameter if provided, otherwise prompt
|
||||
if [ -n "$VERIFY_CODE_PARAM" ]; then
|
||||
VERIFY_CODE="$VERIFY_CODE_PARAM"
|
||||
echo "🔐 Using verification code from parameter"
|
||||
else
|
||||
read -p "Enter the verification code from the email: " VERIFY_CODE
|
||||
if [ -z "$VERIFY_CODE" ]; then
|
||||
echo "❌ Error: Verification code is required"
|
||||
echo ""
|
||||
echo "Run with: $0 --verify-code YOUR_CODE"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user