diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 4ef1c4d..90ac0db 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -77,6 +77,83 @@ for arg in "$@"; do esac done +# ADVANCED FEATURE: Configuration File Support (OPT-18) +# Allows loading configuration from file instead of command-line flags +# Useful for production deployments and reproducible configurations +declare -g CONFIG_FILE="" +declare -g USE_CONFIG_FILE=false + +# Load configuration from file +# Supported format: KEY=VALUE (one per line, shell-style) +load_config_file() { + local config_path="${1:-/etc/wordpress-cron-manager.conf}" + + if [ ! -f "$config_path" ]; then + return 0 # Config file is optional + fi + + if [ ! -r "$config_path" ]; then + print_warning "Config file not readable: $config_path" + return 1 + fi + + print_info "Loading configuration from: $config_path" + + # Source the config file (validates shell syntax and loads variables) + # Use subshell to avoid polluting global scope with unexpected variables + if ! source "$config_path" 2>/dev/null; then + print_error "Invalid syntax in config file: $config_path" + return 1 + fi + + # Apply configuration options from file + [ -n "$ENABLE_PARALLEL" ] && ENABLE_PARALLEL="$ENABLE_PARALLEL" + [ -n "$DRY_RUN" ] && DRY_RUN="$DRY_RUN" + [ -n "$BATCH_MODE" ] && BATCH_MODE="$BATCH_MODE" + [ -n "$LOG_OUTPUT_FILE" ] && LOG_OUTPUT_FILE="$LOG_OUTPUT_FILE" + [ -n "$LOG_DIR" ] && LOG_OUTPUT_FILE="$LOG_DIR/wordpress-cron-manager-$(date +%Y%m%d-%H%M%S).log" + [ -n "$BACKUP_DIR" ] && BACKUP_DIR="$BACKUP_DIR" + [ -n "$ROLLBACK_ENABLED" ] && ROLLBACK_ENABLED="$ROLLBACK_ENABLED" + + return 0 +} + +# Generate sample configuration file +generate_sample_config() { + cat <<'EOF' +# WordPress Cron Manager Configuration File +# Location: /etc/wordpress-cron-manager.conf +# Note: Command-line flags override these settings + +# Enable parallel processing for multi-site operations +ENABLE_PARALLEL=false + +# Run in dry-run mode (show what would be done without making changes) +DRY_RUN=false + +# Batch mode (skip all confirmations for automation) +BATCH_MODE=false + +# Enable logging to file (auto-generated timestamp or custom path) +LOG_OUTPUT_FILE="/var/log/wordpress-cron-manager.log" + +# Custom log directory +LOG_DIR="/var/log" + +# Custom backup directory for rollback support +BACKUP_DIR="/var/backups/wordpress-cron" + +# Enable automatic rollback on failure +ROLLBACK_ENABLED=true + +# Report format (text, json, csv) +REPORT_FORMAT="text" + +# Report output file (leave empty for stdout) +REPORT_FILE="/var/log/wordpress-cron-report.txt" +EOF +} + # Initialize logging if --log flag was used if [ -n "$LOG_OUTPUT_FILE" ]; then LOG_ENABLED=true @@ -88,6 +165,11 @@ if [ -n "$LOG_OUTPUT_FILE" ]; then fi fi +# Load configuration file if it exists (can be overridden by command-line flags) +if [ -f /etc/wordpress-cron-manager.conf ]; then + load_config_file /etc/wordpress-cron-manager.conf +fi + # PHP binary path detection PHP_BIN=$(command -v php 2>/dev/null || echo "/usr/bin/php")