31 lines
809 B
Bash
31 lines
809 B
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Example --dry-run pattern for deployment/change scripts
|
||
|
|
# Recommendation: docs/10-best-practices/RECOMMENDATIONS_AND_SUGGESTIONS.md (§ Script Improvements)
|
||
|
|
# Usage: DRY_RUN=1 ./your-script.sh OR ./your-script.sh --dry-run
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
DRY_RUN="${DRY_RUN:-0}"
|
||
|
|
for arg in "$@"; do
|
||
|
|
if [[ "$arg" == "--dry-run" || "$arg" == "-n" ]]; then
|
||
|
|
DRY_RUN=1
|
||
|
|
break
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
run_or_echo() {
|
||
|
|
if [[ "$DRY_RUN" == "1" ]]; then
|
||
|
|
echo "[DRY-RUN] Would execute: $*"
|
||
|
|
else
|
||
|
|
"$@"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# Example: run_or_echo pct set 106 --memory 8192
|
||
|
|
# Example: run_or_echo cp config.toml /opt/besu/
|
||
|
|
|
||
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||
|
|
echo "DRY_RUN=$DRY_RUN - Use DRY_RUN=1 or --dry-run to preview without executing."
|
||
|
|
run_or_echo echo "Example command (no-op when dry-run)"
|
||
|
|
fi
|