Skip to content

Simplify boolean env var handling: only accept 'true'/'false' #564

@kojiromike

Description

@kojiromike

Problem

The current boolean env var handling in openemr.sh scripts accepts many different truthy/falsy values (1, yes, true, on, 0, no, false, off, etc.). This causes several problems:

  1. String matching everywhere - Every check requires [[ "$VAR" = "true" ]] or similar
  2. Potential confusion - on and no are easy to confuse/typo
  3. Inconsistent behavior - Different scripts may accept different subsets of values
  4. More code to maintain - The normalization function adds complexity

Proposal

Only accept literal true and false strings for boolean env vars:

validate_bool() {
    local var_name=$1
    local value=${!var_name}
    case "$value" in
        true|false) ;;
        *) echo "Error: $var_name must be 'true' or 'false', got '$value'" >&2; exit 1 ;;
    esac
}

Benefits

  1. Simpler checks - Can use if $VAR; then directly since true and false are shell builtins
  2. No ambiguity - Clear, explicit values only
  3. Fail-fast - Invalid values caught immediately with helpful error message
  4. Less code - No normalization logic needed

Migration

  • Update documentation to specify true/false only
  • Add validation that exits with a clear error message for invalid values
  • Existing users with EASY_DEV_MODE=1 or =yes will see a clear error telling them to use =true

Affected variables

  • EASY_DEV_MODE
  • EASY_DEV_MODE_NEW
  • INSANE_DEV_MODE
  • PCOV_ON
  • And potentially others that currently accept yes/no

Alternative considered

Keep the current normalization approach (accepting many values). Rejected because:

  • Adds complexity for marginal user convenience
  • Users can easily adapt to true/false
  • Clear error messages make the transition painless

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions