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"
if [ "$1" = "--setup" ]; then
REGISTER_EMAIL=""
REGISTER_GITEA_USERNAME=""
VERIFY_CODE_PARAM=""
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--setup)
MODE="setup"
elif [ "$1" = "--update" ]; then
shift
;;
--update)
MODE="update"
elif [ "$1" = "--status" ]; then
shift
;;
--status)
MODE="status"
elif [ -n "$1" ]; then
echo "❌ Unknown option: $1"
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 "Usage:"
echo " $0 # Auto-detect mode"
echo " $0 --setup # Force new deployment"
echo " $0 --update # Force update existing"
echo " $0 --status # Check deployment status"
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
fi
;;
esac
done
# ========================================
# Load Environment Variables
@@ -166,19 +227,36 @@ else
echo "No configuration found. Let's register your account."
echo ""
# Get Gitea username from .env
# 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 set in .env"
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
# 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 ""
echo "📧 Registering user: $USER_EMAIL"
@@ -231,15 +309,23 @@ else
echo "🔍 Check your email at MailHog:"
echo " https://mailhog.goryan.io"
echo ""
read -p "Enter the verification code from the email: " VERIFY_CODE
# 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 this script again."
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 ""
echo "🔐 Verifying email..."
@@ -281,12 +367,20 @@ 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
# 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 ""
echo "🔐 Verifying email..."