now in it's own repo, like it should be!

This commit is contained in:
2024-11-18 08:46:54 -06:00
parent 665b1b8d85
commit dcb40d94ab
12 changed files with 274 additions and 1 deletions

33
includes/DebugMe.sh Normal file
View File

@ -0,0 +1,33 @@
function DebugMe() {
[[ $script_debug = 1 ]] && "$@" || :
#to turn debugging on, set script_debug=1
#to turn debugging off, set script_debug=0
# be sure to append || : or || true here or use return 0, since the return code
# of this function should always be 0 to not influence anything else with an unwanted
# "false" return code (for example the script's exit code if this function is used
# as the very last command in the script)
#This function does nothing when script_debug is unset or empty, but it executes the
#given parameters as commands when script_debug is set. Use it like this:
#debugme logger "Sorting the database"
#database_sort
#debugme logger "Finished sorting the database, exit code $?"
# * print commands to be executed to stderr as if they were read from input
# (script file or keyboard)
# * print everything before any ( substitution and expansion, …) is applied
set -v
# * print everything as if it were executed, after substitution and expansion is applied
# * indicate the depth-level of the subshell (by default by prefixing a + (plus) sign to
# the displayed command)
# * indicate the recognized words after word splitting by marking them like 'x y'
# * in shell version 4.1, this debug output can be printed to a configurable file
#descriptor, rather than sdtout by setting the BASH_XTRACEFD variable.
set -x
}

13
includes/LocalHelp.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
function LocalHelp()
{
echo "$0 is <description here>"
echo "$0 takes <num> arguments: "
echo "1) <stuff>"
echo "2) <other stuff>"
echo "<additional info on arguments...>:"
echo "<put>"
echo "<stuff>"
echo "<here>"
}

13
includes/LookupKv.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
function LookupKV()
{
#Arguments:
#$1 <path to key/value table>
#$2 unique record identifier
#Returns:
#Variable/array containing all the values in the record
}

View File

@ -0,0 +1,31 @@
#!/bin/bash
function PreflightCheck()
{
#Common things I check for in the scripts I write.
#export curr_host="$(hostname)"
#export curr_user="$USER"
#export host_check="$(echo $curr_host | grep -c <desired hostname>)"
#export user_check="$(echo $curr_user | grep -c <desired username>)"
#if [ $host_check -ne 1 ]; then
# echo "Must run on <desired host>."
# error_out
#fi
#if [ $user_check -ne 1 ]; then
# echo "Must run as <desired user>."
# error_out
#fi
#if [ "$ARG_COUNT" -ne <the right num> ]; then
# help
# error_out
#fi
#Your additional stuff here...
echo "All checks passed...."
}

8
includes/bail_out.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
bail_out()
#Exit code
{
echo "Exiting...."
exit 0
}

23
includes/error_out.sh Normal file
View File

@ -0,0 +1,23 @@
#!/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

41
includes/strictMode.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
function StrictMode()
{
# Standard strict mode and error handling boilderplate..
# 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
# Bits and pieces Sourced from (as best I recall):
# * https://news.ycombinator.com/item?id=24727495
# * many other hacker news / slashdot etc posts over the years
# * https://www.tothenew.com/blog/foolproof-your-bash-script-some-best-practices/
# * https://translucentcomputing.com/2020/05/unofficial-bash-strict-mode-errexit/
# * http://redsymbol.net/articles/unofficial-bash-strict-mode/
# * the school of hard knocks... (aka my code failures...)
#Here's the beef (as the commercial says..)
#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.
set -o errexit
# Use set -o nounset (a.k.a. set -u) to exit when your script tries to use undeclared
# variables.
set -o nounset
#Use set -o pipefail in scripts to catch (for example) mysqldump fails
#in e.g. mysqldump |gzip.
#The exit status of the last command that threw a non-zero exit code is returned
set -o pipefail
#Function tracing...
set -o functrace
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
}