Last active
November 2, 2022 16:17
-
-
Save DeeNewcum/817169b09a928d23beb18a7b03db896b to your computer and use it in GitHub Desktop.
a template for making single-step deployment scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######## begin single-step debugging mechanism ######## | |
DEBUG_COLOR_ONE="\e[47;30m" # gray background, black foreground | |
DEBUG_COLOR_TWO="\e[0;1;31m" # black background, bright red foreground | |
function _trap_DEBUG() { | |
echo -e "\n$DEBUG_COLOR_ONE$1\e[0m $DEBUG_COLOR_TWO$BASH_COMMAND\e[0m"; | |
read -s _ignore | |
} | |
# prefix a command with this to indicate that specific command should | |
# be skipped when $IS_DRY_RUN is true | |
function DRY_RUN() { | |
if [ "$IS_DRY_RUN" ]; then | |
echo "(skipped because this is a dry run)" | |
else | |
eval "$@" | |
fi | |
} | |
echo "======== to single-step, press enter before each command is run ========" | |
# other things that could go on this line: | |
# "DEBUG level:$SHLVL" | |
# "subshell-level: $BASH_SUBSHELL" | |
# "function:${FUNCNAME[0]:+${FUNCNAME[0]}(): }" | |
trap '_trap_DEBUG "$BASH_SOURCE line $LINENO:"' DEBUG | |
######## end single-step debugging mechanism ######## | |
# set to a non-empty string to avoid making any actual changes | |
IS_DRY_RUN= | |
echo test one two three | |
DRY_RUN touch /tmp/test123 | |
echo hi | |
DRY_RUN rm -f /tmp/test123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment