Skip to content

Commit

Permalink
Optimize directory checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed May 6, 2017
1 parent 69387b8 commit 7ea4569
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions bin/list_all_entities_exported.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ display_help () {
LOG_LEVEL The global log level [0..5]
All of the above environment variables are REQUIRED
(except LOG_LEVEL, which defaults to LOG_LEVEL=3).
except LOG_LEVEL, which defaults to LOG_LEVEL=3.
EXAMPLES
Expand All @@ -64,51 +64,31 @@ HELP_MSG

script_name=${0##*/} # equivalent to basename $0

# check the bin directory
if [ -z "$BIN_DIR" ]; then
echo "ERROR: $script_name requires env var BIN_DIR" >&2
exit 2
fi
if [ ! -d "$BIN_DIR" ]; then
echo "ERROR: $script_name: directory does not exist: $BIN_DIR" >&2
exit 2
fi

# check the source lib directory
if [ -z "$LIB_DIR" ]; then
echo "ERROR: $script_name requires env var LIB_DIR" >&2
exit 2
fi
if [ ! -d "$LIB_DIR" ]; then
echo "ERROR: $script_name: directory does not exist: $LIB_DIR" >&2
exit 2
fi

# check the cache directory
if [ -z "$CACHE_DIR" ]; then
echo "ERROR: $script_name requires env var CACHE_DIR" >&2
exit 2
fi
if [ ! -d "$CACHE_DIR" ]; then
echo "ERROR: $script_name: directory does not exist: $CACHE_DIR" >&2
exit 2
fi

# check the tmp directory
if [ -z "$TMPDIR" ]; then
echo "ERROR: $script_name requires env var TMPDIR" >&2
exit 2
fi
if [ ! -d "$TMPDIR" ]; then
echo "ERROR: $script_name: directory does not exist: $TMPDIR" >&2
exit 2
fi
# required directories
env_vars="BIN_DIR
LIB_DIR
CACHE_DIR
TMPDIR"

# check required directories
for env_var in $env_vars; do
eval "env_var_val=\${$env_var}"
if [ -z "$env_var_val" ]; then
echo "ERROR: $script_name requires env var $env_var" >&2
exit 2
fi
if [ ! -d "$env_var_val" ]; then
echo "ERROR: $script_name: directory does not exist: $env_var_val" >&2
exit 2
fi
done

# check the log file
if [ -z "$LOG_FILE" ]; then
echo "ERROR: $script_name requires env var LOG_FILE" >&2
exit 2
fi
# devices such as /dev/tty and /dev/null are allowed
if [ ! -f "$LOG_FILE" ] && [[ $LOG_FILE != /dev/* ]]; then
echo "ERROR: $script_name: file does not exist: $LOG_FILE" >&2
exit 2
Expand Down

0 comments on commit 7ea4569

Please sign in to comment.