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:
Landon Curt Noll committed 2024-02-23 19:19:55 -08:00
1 parent de0619a8b6
commit 09b8de5081
21 files changed
+1071 -1164

No files matched your search

+23 -24
View File
@@ -51,7 +51,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-12"
export VERSION="1.0.1 2024-02-23"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
@@ -59,7 +59,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 210
exit 5
fi
"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1
status="$?"
@@ -106,15 +106,14 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-n] [-N]
Exit codes:
0 all OK
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 YYYY is not a year directory
6 subst.year-navbar.awk tool or pandoc wrapper not found
7 cannot find a non-empty or read .year file
8 .year file under year YYYY is not a non-empty readable file
>= 10 < 210 ((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"
@@ -244,28 +243,28 @@ export REPO_NAME
if [[ -z $TOPDIR ]]; then
echo "$0: ERROR: cannot find top of git repo directory" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 211
exit 6
fi
if [[ ! -e $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR does not exist: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 212
exit 6
fi
if [[ ! -d $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR is not a directory: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 213
exit 6
fi
# cd to topdir
#
if [[ ! -e $TOPDIR ]]; then
echo "$0: ERROR: cannot cd to non-existent path: $TOPDIR" 1>&2
exit 217
exit 6
fi
if [[ ! -d $TOPDIR ]]; then
echo "$0: ERROR: cannot cd to a non-directory: $TOPDIR" 1>&2
exit 218
exit 6
fi
export CD_FAILED
if [[ $V_FLAG -ge 5 ]]; then
@@ -274,7 +273,7 @@ fi
cd "$TOPDIR" || CD_FAILED="true"
if [[ -n $CD_FAILED ]]; then
echo "$0: ERROR: cd $TOPDIR failed" 1>&2
exit 219
exit 6
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2
@@ -284,11 +283,11 @@ fi
#
if [[ ! -d $YYYY ]]; then
echo "$0: ERROR: arg is not a directory: $YYYY" 1>&2
exit 5
exit 6
fi
if [[ ! -r $YYYY ]]; then
echo "$0: ERROR: arg is not a writable directory: $YYYY" 1>&2
exit 5
exit 6
fi
# verify that YYYY has a non-empty readable .year file
@@ -296,19 +295,19 @@ fi
export YEAR_FILE="$YYYY/.year"
if [[ ! -e $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year does not exist: $YEAR_FILE" 1>&2
exit 7
exit 6
fi
if [[ ! -f $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not a regular file: $YEAR_FILE" 1>&2
exit 7
exit 6
fi
if [[ ! -r $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not an readable file: $YEAR_FILE" 1>&2
exit 7
exit 6
fi
if [[ ! -s $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not a non-empty readable file: $YEAR_FILE" 1>&2
exit 7
exit 6
fi
# verify that YYYY/README.md is a non-empty readable file
@@ -316,19 +315,19 @@ fi
export README_FILE="$YYYY/README.md"
if [[ ! -e $README_FILE ]]; then
echo "$0: ERROR: year $YYYY README.md does not exist: $README_FILE" 1>&2
exit 8
exit 6
fi
if [[ ! -f $README_FILE ]]; then
echo "$0: ERROR: year $YYYY README.md is not a file: $README_FILE" 1>&2
exit 8
exit 6
fi
if [[ ! -r $README_FILE ]]; then
echo "$0: ERROR: year $YYYY README.md is not a readable file: $README_FILE" 1>&2
exit 8
exit 6
fi
if [[ ! -s $README_FILE ]]; then
echo "$0: ERROR: year $YYYY README.md is not a non-empty readable file: $README_FILE" 1>&2
exit 8
exit 6
fi
# verify that the md2html.sh is executable