first functional commit
This commit is contained in:
84
_libs/libbase.sh
Normal file
84
_libs/libbase.sh
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Function: EnsureRoot
|
||||
# Ensures that commands are being executed as root.
|
||||
function EnsureRoot {
|
||||
if (( EUID != 0 )); then
|
||||
echo "[X] Must run as root"
|
||||
exit 100
|
||||
fi
|
||||
}
|
||||
|
||||
# Function: EchoBlanks
|
||||
# Echo number of blank lines indicated by input
|
||||
#
|
||||
# Parameters:
|
||||
# ${1} - The number of blank lines to echo
|
||||
function EchoBlanks {
|
||||
local num_lines
|
||||
|
||||
# Strip non-numbers from input
|
||||
num_lines="${1//[^0-9]/}"
|
||||
if [[ -z "${num_lines}" ]]; then
|
||||
num_lines=0
|
||||
fi
|
||||
|
||||
if [[ "${num_lines}" -ne 0 ]]; then
|
||||
for ((i = 0; i < num_lines; i++)); do
|
||||
echo ""
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function: StatusEcho
|
||||
# Echos out provided text in inverted colors so it stands out
|
||||
#
|
||||
# Parameters:
|
||||
# ${1} - The text to send
|
||||
# ${2} - The number of leading empty lines before the echo
|
||||
# ${3} - The number of trailing empty lines after the echo
|
||||
function StatusEcho {
|
||||
EchoBlanks "${2}"
|
||||
echo -e "\e[7m${1} \e[0m"
|
||||
EchoBlanks "${3}"
|
||||
}
|
||||
|
||||
# Function: WarningEcho
|
||||
# Echos out provided text as white letters on a red background so it stands out.
|
||||
#
|
||||
# Parameters:
|
||||
# ${1} - The text to send
|
||||
# ${2} - The number of leading empty lines before the echo
|
||||
# ${3} - The number of trailing empty lines after the echo
|
||||
function WarningEcho {
|
||||
EchoBlanks "${2}"
|
||||
echo -e "\e[97m\e[41m${1} \e[0m"
|
||||
EchoBlanks "${3}"
|
||||
}
|
||||
|
||||
# Function: CyanEcho
|
||||
# Echos out provided text as Light Cyan letters on a black background so it stands out.
|
||||
#
|
||||
# Parameters:
|
||||
# ${1} - The text to send
|
||||
# ${2} - The number of leading empty lines before the echo
|
||||
# ${3} - The number of trailing empty lines after the echo
|
||||
function CyanEcho {
|
||||
EchoBlanks "${2}"
|
||||
echo -e "\e[96m\e[40m${1} \e[0m"
|
||||
EchoBlanks "${3}"
|
||||
}
|
||||
|
||||
# Function: pushd
|
||||
# Overrides default pushd functionatlity to suppress console messages.
|
||||
function pushd {
|
||||
command pushd "$@" >/dev/null
|
||||
}
|
||||
|
||||
# Function: popd
|
||||
# Overrides default popd functionatlity to suppress console messages.
|
||||
function popd {
|
||||
command popd >/dev/null
|
||||
}
|
||||
Reference in New Issue
Block a user