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:
2026-01-24 20:59:05 +01:00
parent 0fce839b7c
commit 23d1a7123d

View File

@@ -105,22 +105,83 @@ fi
# ======================================== # ========================================
MODE="auto" MODE="auto"
if [ "$1" = "--setup" ]; then REGISTER_EMAIL=""
MODE="setup" REGISTER_GITEA_USERNAME=""
elif [ "$1" = "--update" ]; then VERIFY_CODE_PARAM=""
MODE="update"
elif [ "$1" = "--status" ]; then # Parse arguments
MODE="status" while [ $# -gt 0 ]; do
elif [ -n "$1" ]; then case "$1" in
echo "❌ Unknown option: $1" --setup)
echo "" MODE="setup"
echo "Usage:" shift
echo " $0 # Auto-detect mode" ;;
echo " $0 --setup # Force new deployment" --update)
echo " $0 --update # Force update existing" MODE="update"
echo " $0 --status # Check deployment status" shift
exit 1 ;;
fi --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 # Load Environment Variables
@@ -166,18 +227,35 @@ else
echo "No configuration found. Let's register your account." echo "No configuration found. Let's register your account."
echo "" echo ""
# Get Gitea username from .env # Get Gitea username from .env or parameter
if [ -z "$GITEA_USERNAME" ]; then if [ -n "$REGISTER_GITEA_USERNAME" ]; then
echo "❌ Error: GITEA_USERNAME not set in .env" GITEA_USERNAME="$REGISTER_GITEA_USERNAME"
exit 1 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 fi
# Prompt for email # Get email from parameter or prompt
read -p "Enter your email address: " USER_EMAIL if [ -n "$REGISTER_EMAIL" ]; then
USER_EMAIL="$REGISTER_EMAIL"
if [ -z "$USER_EMAIL" ]; then echo "📧 Using email: $USER_EMAIL"
echo "❌ Error: Email address is required" else
exit 1 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 fi
echo "" echo ""
@@ -231,14 +309,22 @@ else
echo "🔍 Check your email at MailHog:" echo "🔍 Check your email at MailHog:"
echo " https://mailhog.goryan.io" echo " https://mailhog.goryan.io"
echo "" echo ""
read -p "Enter the verification code from the email: " VERIFY_CODE
if [ -z "$VERIFY_CODE" ]; then # Use parameter if provided, otherwise prompt
echo "❌ Error: Verification code is required" if [ -n "$VERIFY_CODE_PARAM" ]; then
echo "" VERIFY_CODE="$VERIFY_CODE_PARAM"
echo "You can verify later by running this script again." echo "🔐 Using verification code from parameter"
echo "Your configuration has been saved to $SAAC_CONFIG_FILE" else
exit 1 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 fi
echo "" echo ""
@@ -281,11 +367,19 @@ if [ "$VERIFIED" != "true" ]; then
echo "🔍 Check your email at MailHog:" echo "🔍 Check your email at MailHog:"
echo " https://mailhog.goryan.io" echo " https://mailhog.goryan.io"
echo "" echo ""
read -p "Enter the verification code from the email: " VERIFY_CODE
if [ -z "$VERIFY_CODE" ]; then # Use parameter if provided, otherwise prompt
echo "❌ Error: Verification code is required" if [ -n "$VERIFY_CODE_PARAM" ]; then
exit 1 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 fi
echo "" echo ""