improve exit code use in bin scripts
The use of exit codes and exit code ranges has been made more consistent across most bin tools.
This commit is contained in:
1 parent
de0619a8b6
commit
09b8de5081
21 files changed
+1071
-1164
No files matched your search
+36
-38
@@ -49,7 +49,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
|
||||
|
||||
# set variables referenced in the usage message
|
||||
#
|
||||
export VERSION="1.0 2024-02-11"
|
||||
export VERSION="1.0.1 2024-02-23"
|
||||
NAME=$(basename "$0")
|
||||
export NAME
|
||||
export V_FLAG=0
|
||||
@@ -57,7 +57,7 @@ GIT_TOOL=$(type -P git)
|
||||
export GIT_TOOL
|
||||
if [[ -z "$GIT_TOOL" ]]; then
|
||||
echo "$0: FATAL: git tool is not installed or not in \$PATH" 1>&2
|
||||
exit 10
|
||||
exit 5
|
||||
fi
|
||||
"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||
status="$?"
|
||||
@@ -69,13 +69,13 @@ TAC_TOOL=$(type -P tac)
|
||||
export TAC_TOOL
|
||||
if [[ ! -x $TAC_TOOL ]]; then
|
||||
echo "$0: FATAL: tac executable is not installed or not in \$PATH" 1>&2
|
||||
exit 11
|
||||
exit 5
|
||||
fi
|
||||
FMT_TOOL=$(type -P fmt)
|
||||
export FMT_TOOL
|
||||
if [[ ! -x $FMT_TOOL ]]; then
|
||||
echo "$0: FATAL: fmt executable is not installed or not in \$PATH" 1>&2
|
||||
exit 12
|
||||
exit 5
|
||||
fi
|
||||
export DOCROOT_SLASH="./"
|
||||
export TAGLINE="bin/$NAME"
|
||||
@@ -131,16 +131,14 @@ NOTE: The '-v level' is passed as initial command line options to the 'markdown
|
||||
|
||||
Exit codes:
|
||||
0 all OK
|
||||
1 md2html.sh exited non-zero
|
||||
1 some internal tool exited non-zero
|
||||
2 -h and help string printed or -V and version string printed
|
||||
3 command line error
|
||||
4 bash version is < 4.2
|
||||
5 md2html.sh and/or location is not an executable file
|
||||
6 problems found with or in the topdir directory
|
||||
7 problems found with or in the topdir/YYYY directory
|
||||
8 problems found with or in the topdir/YYYY/dir directory
|
||||
>= 10 < 200 ((not used))
|
||||
>= 210 internal tool error
|
||||
5 some internal tool is not found or not an executable file
|
||||
6 problems found with or in the topdir or topdir/YYYY directory
|
||||
7 problems found with or in the entry topdir/YYYY/dir directory
|
||||
>= 10 internal error
|
||||
|
||||
$NAME version: $VERSION"
|
||||
|
||||
@@ -401,15 +399,6 @@ if [[ ! -d $TOPDIR ]]; then
|
||||
exit 6
|
||||
fi
|
||||
|
||||
# verify that we have an bin subdirectory
|
||||
#
|
||||
export BIN_PATH="$TOPDIR/bin"
|
||||
if [[ ! -d $BIN_PATH ]]; then
|
||||
echo "$0: ERROR: bin is not a directory under topdir: $BIN_PATH" 1>&2
|
||||
exit 211
|
||||
fi
|
||||
export BIN_DIR="bin"
|
||||
|
||||
# cd to topdir
|
||||
#
|
||||
if [[ ! -e $TOPDIR ]]; then
|
||||
@@ -433,6 +422,15 @@ if [[ $V_FLAG -ge 3 ]]; then
|
||||
echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2
|
||||
fi
|
||||
|
||||
# verify that we have an bin subdirectory
|
||||
#
|
||||
export BIN_PATH="$TOPDIR/bin"
|
||||
if [[ ! -d $BIN_PATH ]]; then
|
||||
echo "$0: ERROR: bin is not a directory under topdir: $BIN_PATH" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
export BIN_DIR="bin"
|
||||
|
||||
# verify we have a non-empty readable .top file
|
||||
#
|
||||
export TOP_FILE=".top"
|
||||
@@ -522,12 +520,12 @@ if [[ -z $NOOP ]]; then
|
||||
rm -f "$TMP_YEARS_MD"
|
||||
if [[ -e $TMP_YEARS_MD ]]; then
|
||||
echo "$0: ERROR: cannot remove temporary years markdown file: $TMP_YEARS_MD" 1>&2
|
||||
exit 212
|
||||
exit 10
|
||||
fi
|
||||
:> "$TMP_YEARS_MD"
|
||||
if [[ ! -e $TMP_YEARS_MD ]]; then
|
||||
echo "$0: ERROR: cannot create temporary years markdown file: $TMP_YEARS_MD" 1>&2
|
||||
exit 213
|
||||
exit 11
|
||||
fi
|
||||
elif [[ $V_FLAG -ge 3 ]]; then
|
||||
echo "$0: debug[3]: because of -n, temporary years markdown file is not used: $TMP_YEARS_MD" 1>&2
|
||||
@@ -582,19 +580,19 @@ for YYYY in $("$TAC_TOOL" "$TOP_FILE"); do
|
||||
#
|
||||
if [[ ! -e $YYYY ]]; then
|
||||
echo "$0: ERROR: YYYY does not exist: $YYYY" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -d $YYYY ]]; then
|
||||
echo "$0: ERROR: YYYY is not a directory: $YYYY" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -r $YYYY ]]; then
|
||||
echo "$0: ERROR: YYYY is not an readable directory: $YYYY" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
@@ -604,25 +602,25 @@ for YYYY in $("$TAC_TOOL" "$TOP_FILE"); do
|
||||
export YEAR_FILE="$YYYY/.year"
|
||||
if [[ ! -e $YEAR_FILE ]]; then
|
||||
echo "$0: ERROR: YYYY/.year does not exist: $YEAR_FILE" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -f $YEAR_FILE ]]; then
|
||||
echo "$0: ERROR: YYYY/.year is not a regular file: $YEAR_FILE" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -r $YEAR_FILE ]]; then
|
||||
echo "$0: ERROR: YYYY/.year is not an readable file: $YEAR_FILE" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -s $YEAR_FILE ]]; then
|
||||
echo "$0: ERROR: YYYY/.year is not a non-empty readable file: $YEAR_FILE" 1>&2
|
||||
EXIT_CODE="7" # exit 7
|
||||
EXIT_CODE="6" # exit 6
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
@@ -694,19 +692,19 @@ for YYYY in $("$TAC_TOOL" "$TOP_FILE"); do
|
||||
#
|
||||
if [[ ! -e $YYYY_DIR ]]; then
|
||||
echo "$0: ERROR: YYYY_DIR does not exist: $YYYY_DIR" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -d $YYYY_DIR ]]; then
|
||||
echo "$0: ERROR: YYYY_DIR is not a directory: $YYYY_DIR" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -w $YYYY_DIR ]]; then
|
||||
echo "$0: ERROR: YYYY_DIR is not an writable directory: $YYYY_DIR" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
@@ -716,33 +714,33 @@ for YYYY in $("$TAC_TOOL" "$TOP_FILE"); do
|
||||
export DOT_PATH="$YYYY_DIR/.path"
|
||||
if [[ ! -s $DOT_PATH ]]; then
|
||||
echo "$0: ERROR: not a non-empty file: $DOT_PATH" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
DOT_PATH_CONTENT=$(< "$DOT_PATH")
|
||||
if [[ $YYYY_DIR != "$DOT_PATH_CONTENT" ]]; then
|
||||
echo "$0: ERROR: arg: $YYYY_DIR does not match $DOT_PATH contents: $DOT_PATH_CONTENT" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
export ENTRY_JSON="$YYYY_DIR/.entry.json"
|
||||
if [[ ! -e $ENTRY_JSON ]]; then
|
||||
echo "$0: ERROR: .entry.json does not exist: $ENTRY_JSON" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -f $ENTRY_JSON ]]; then
|
||||
echo "$0: ERROR: .entry.json is not a file: $ENTRY_JSON" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
if [[ ! -r $ENTRY_JSON ]]; then
|
||||
echo "$0: ERROR: .entry.json is not a readable file: $ENTRY_JSON" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
@@ -752,7 +750,7 @@ for YYYY in $("$TAC_TOOL" "$TOP_FILE"); do
|
||||
AWARD=$(output_award "$ENTRY_JSON")
|
||||
if [[ -z $AWARD ]]; then
|
||||
echo "$0: ERROR: cannot find award in .entry.json: $ENTRY_JSON" 1>&2
|
||||
EXIT_CODE="8" # exit 8
|
||||
EXIT_CODE="7" # exit 7
|
||||
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
|
||||
continue
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user