about to test this on rr-middleware...

This commit is contained in:
2025-06-30 13:23:24 -05:00
parent d82c8733fa
commit f3070de151
7 changed files with 40 additions and 95 deletions

View File

@ -1,4 +0,0 @@
#Global Variables used by the framework
export ProjectIncludes="0"
export PreflightCheck="0"

View File

@ -0,0 +1,3 @@
#Global Variables used by the framework
export ProjectIncludes="1"

View File

@ -19,7 +19,8 @@ export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
function error_out()
{
echo "Bailing out. See above for reason...."
print_error "$1"
print_error "Bailing out. See above for reason...."
exit 1
}

View File

@ -3,29 +3,17 @@
function PreflightCheck()
{
#Common things I check for in the scripts I write.
export curr_user="$USER"
export user_check
#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>)"
user_check="$(echo "$curr_user" | grep -c root)"
#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 [ $user_check -ne 1 ]; then
print_error "Must run as root."
error_out
fi
#if [ "$ARG_COUNT" -ne <the right num> ]; then
# help
# error_out
#fi
#Your additional stuff here...
echo "All checks passed...."
}

View File

@ -1,88 +1,44 @@
#!/usr/bin/bash
export CURRENT_TIMESTAMP
CURRENT_TIMESTAMP="$(date +%A-%Y-%m-%d-%T)"
#####
#Core framework functions...
#####
export LOGFILENAME
LOGFILENAME="SetupNewSystem.${CURRENT_TIMESTAMP}.$$"
export FRAMEWORK_INCLUDES_FULL_PATH
FRAMEWORK_INCLUDES_FULL_PATH="$(realpath ../Framework-Includes)"
# Standard strict mode and error handling boilderplate...
export FRAMEWORK_CONFIGS_FULL_PATH
FRAMEWORK_CONFIGS_FULL_PATH="$(realpath ../Framework-ConfigFiles)"
set -o errexit
set -o nounset
set -o pipefail
set -o functrace
export PROJECT_INCLUDES_FULL_PATH
PROJECT_INCLUDES_FULL_PATH="$(realpath ../Project-Includes)"
export PS4='(${BASH_SOURCE}:${LINENO}): - [${SHLVL},${BASH_SUBSHELL},$?] $ '
function print_info()
{
GREEN='\033[0;32m'
NC='\033[0m'
tput bold
echo -e "$GREEN $1${NC}"
echo -e "$GREEN $1${NC}" >> "$LOGFILENAME"
tput sgr0
}
function print_error()
{
RED='\033[0;31m'
NC='\033[0m'
tput bold
echo -e "$RED $1${NC}"
echo "$1"
echo -e "$RED $1${NC}" >> "$LOGFILENAME"
tput sgr0
}
log_info_message() {
local message="$1"
local logfile="/var/log/my_script.log" # Define your log file path
echo "$message" | tee -a "$logfile"
}
export PROJECT_CONGIGS_FULL_PATH
PROJECT_INCLUDES_FULL_PATH="$(realpath ../Project-ConfigFiles)"
function error_out()
{
print_error "$1"
print_error "Bailing out. See above for reason...."
exit 1
}
#Framework variables are read from hee
source $FRAMEWORK_CONFIGS_FULL_PATH/FrameworkVars
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"
}
#Boilerplate and support functions
FrameworkIncludeFiles="$(ls -1 --color=none $FRAMEWORK_INCLUDES_FULL_PATH/*)"
trap 'handle_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
function PreflightCheck()
{
export curr_user="$USER"
export user_check
user_check="$(echo "$curr_user" | grep -c root)"
IFS=$'\n\t'
for file in ${FrameworkIncludeFiles[@]}; do
. "$file"
done
unset IFS
if [ $user_check -ne 1 ]; then
print_error "Must run as root."
error_out
if [[ ProjectIncludes = 1 ]]; then
ProjectIncludeFiles="$(ls -1 --color=none $PROJECT_INCLUDES_FULL_PATH/*)"
IFS=$'\n\t'
for file in ${ProjectIncludeFiles[@]}; do
. "$file"
done
unset IFS
fi
print_info "All checks passed...."
}
# Start actual script logic here...
#################

1
logs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
!.gitignore