diff --git a/platform/shell-sync/sync.sh b/platform/shell-sync/sync.sh index 86ef43de..0496d178 100644 --- a/platform/shell-sync/sync.sh +++ b/platform/shell-sync/sync.sh @@ -53,3 +53,43 @@ log_oauth_authorization_guidance() { fi } +validate_settings() { + if ! [[ "$NUM_ACCOUNTS" =~ ^[1-9][0-9]*$ ]]; then + log "Configuration error: NUM_ACCOUNTS must be a positive integer" + return 1 + fi + + if [ -z "$SYNC_CRON" ] && ! [[ "$SYNC_INTERVAL" =~ ^[1-9][0-9]*$ ]]; then + log "Configuration error: SYNC_INTERVAL must be a positive number of seconds" + return 1 + fi + + case "$NOTIFY_MODE" in + none|batch_success|account_success|failure) ;; + *) + log "Configuration error: NOTIFY_MODE must be none, batch_success, account_success, or failure" + return 1 + ;; + esac + + if [ "$NOTIFY_MODE" != "none" ]; then + if [ -z "$SMTP_HOST" ] || [ -z "$SMTP_FROM" ] || [ -z "$SMTP_TO" ]; then + log "Configuration error: SMTP_HOST, SMTP_FROM, and SMTP_TO are required when notifications are enabled" + return 1 + fi + if ! [[ "$SMTP_PORT" =~ ^[1-9][0-9]*$ ]]; then + log "Configuration error: SMTP_PORT must be a valid port number" + return 1 + fi + if { [ -n "$SMTP_USER" ] && [ -z "$SMTP_PASS" ]; } || { [ -z "$SMTP_USER" ] && [ -n "$SMTP_PASS" ]; }; then + log "Configuration error: SMTP_USER and SMTP_PASS must either both be set or both be empty" + return 1 + fi + case "$SMTP_TLS" in starttls|tls|none) ;; *) + log "Configuration error: SMTP_TLS must be starttls, tls, or none" + return 1 + ;; + esac + fi +} +