Skip to content

Commit

Permalink
Enhance log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed May 2, 2017
1 parent cdbba53 commit 08f9bf0
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/core_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ print_log_message () {
echo "FATAL: $FUNCNAME requires env var LOG_FILE" >&2
exit 2
fi
if [ ! -f "$LOG_FILE" ]; then
if [ ! -f "$LOG_FILE" ] && [[ $LOG_FILE != /dev/* ]]; then
echo "FATAL: $FUNCNAME: file does not exist: $LOG_FILE" >&2
exit 2
fi
Expand Down Expand Up @@ -292,39 +292,36 @@ clean_up_and_exit () {
unwanted_dir="$OPTARG"
;;
\?)
echo "ERROR: $FUNCNAME: Unrecognized option: -$OPTARG" >&2
return 2
print_log_message -E "$FUNCNAME: Unrecognized option: -$OPTARG"
;;
:)
echo "ERROR: $FUNCNAME: Option -$OPTARG requires an argument" >&2
return 2
print_log_message -E "$FUNCNAME: Option -$OPTARG requires an argument"
;;
esac
done

# determine the exit code
shift $(( OPTIND - 1 ))
if [ $# -ne 1 ]; then
echo "ERROR: $FUNCNAME: wrong number of arguments: $# (1 required)" >&2
return 2
print_log_message -F "$FUNCNAME: wrong number of arguments: $# (1 required)"
exit 2
fi
exit_code="$1"
if [ ! "$exit_code" -ge 0 ] ; then
echo "ERROR: $FUNCNAME: illegal exit code: $exit_code" >&2
return 2
print_log_message -F "$FUNCNAME: illegal exit code: $exit_code"
exit 2
fi

if [ -n "$unwanted_dir" ]; then
if [ ! -d "$unwanted_dir" ]; then
echo "ERROR: $FUNCNAME: directory does not exist: $unwanted_dir" >&2
return 2
fi

# remove the unwanted directory (!)
print_log_message -D "$FUNCNAME removing dir: $unwanted_dir"
/bin/rm -rf "$unwanted_dir"
if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME failed to remove dir: $unwanted_dir" >&2
print_log_message -E "$FUNCNAME: directory does not exist: $unwanted_dir"
else
# remove the unwanted directory (!)
print_log_message -D "$FUNCNAME removing dir: $unwanted_dir"
/bin/rm -rf "$unwanted_dir"
if [ $? -ne 0 ]; then
print_log_message -E "$FUNCNAME failed to remove dir: $unwanted_dir"
fi
fi
fi

Expand Down

0 comments on commit 08f9bf0

Please sign in to comment.