some light refactoring and general cleanup
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Standard strict mode and error handling/tracing boilderplate..
|
||||||
function StrictMode()
|
|
||||||
{
|
|
||||||
|
|
||||||
# Standard strict mode and error handling boilderplate..
|
|
||||||
|
|
||||||
# This is a function I include and execute in every shell script that I write.
|
# This is a function I include and execute in every shell script that I write.
|
||||||
# It sets up a bunch of error handling odds and ends
|
# It sets up a bunch of error handling odds and ends
|
||||||
@@ -19,6 +15,28 @@ function StrictMode()
|
|||||||
|
|
||||||
#Here's the beef (as the commercial says..)
|
#Here's the beef (as the commercial says..)
|
||||||
|
|
||||||
|
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
|
||||||
|
|
||||||
|
function error_out()
|
||||||
|
{
|
||||||
|
echo "Bailing out. See above for reason...."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_failure() {
|
||||||
|
local lineno=$1
|
||||||
|
local fn=$2
|
||||||
|
local exitstatus=$3
|
||||||
|
local msg=$4
|
||||||
|
local lineno_fns=${0% 0}
|
||||||
|
if [[ "$lineno_fns" != "-1" ]] ; then
|
||||||
|
lineno="${lineno} ${lineno_fns}"
|
||||||
|
fi
|
||||||
|
echo "${BASH_SOURCE[0]}: Function: ${fn} Line Number : [${lineno}] Failed with status ${exitstatus}: $msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'handle_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
|
||||||
|
|
||||||
#use errexit (a.k.a. set -e) to make your script exit when a command fails.
|
#use errexit (a.k.a. set -e) to make your script exit when a command fails.
|
||||||
#add || true to commands that you allow to fail.
|
#add || true to commands that you allow to fail.
|
||||||
set -o errexit
|
set -o errexit
|
||||||
@@ -33,9 +51,4 @@ set -o nounset
|
|||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
#Function tracing...
|
#Function tracing...
|
||||||
set -o functrace
|
set -o functrace
|
||||||
|
|
||||||
|
|
||||||
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
|
|
||||||
|
|
||||||
}
|
|
5
includes/Logging.sh
Executable file
5
includes/Logging.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
export CURRENT_TIMESTAMP
|
||||||
|
CURRENT_TIMESTAMP="$(date +%A-%Y-%m-%d-%T)"
|
||||||
|
|
||||||
|
export LOGFILENAME
|
||||||
|
LOGFILENAME="$0.${CURRENT_TIMESTAMP}.$$"
|
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
bail_out()
|
|
||||||
#Exit code
|
|
||||||
{
|
|
||||||
echo "Exiting...."
|
|
||||||
exit 0
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
||||||
function error_out()
|
|
||||||
{
|
|
||||||
echo "Bailing out. See above for reason...."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function handle_failure() {
|
|
||||||
local lineno=$1
|
|
||||||
local fn=$2
|
|
||||||
local exitstatus=$3
|
|
||||||
local msg=$4
|
|
||||||
local lineno_fns=${0% 0}
|
|
||||||
if [[ "$lineno_fns" != "-1" ]] ; then
|
|
||||||
lineno="${lineno} ${lineno_fns}"
|
|
||||||
fi
|
|
||||||
echo "${BASH_SOURCE[0]}: Function: ${fn} Line Number : [${lineno}] Failed with status ${exitstatus}: $msg"
|
|
||||||
}
|
|
||||||
|
|
||||||
trap 'handle_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
|
|
Reference in New Issue
Block a user