better failover handling for settings and functions import

This commit is contained in:
pyr0ball 2023-03-14 00:30:10 -07:00
parent b876a993c3
commit 7f0606c3aa

View file

@ -48,26 +48,33 @@ else
VER=$(uname -r) VER=$(uname -r)
fi fi
# source PRbL functions
if [ ! -z $prbl_functions ] ; then
source $prbl_functions
else
echo -e "PRbL functions not defined. Check ~/.bashrc"
fi
# Locate and import settings (shares same name with script apart from file extension) # Locate and import settings (shares same name with script apart from file extension)
scriptname="${0##*/}" scriptname="${0##*/}"
rundir="${0%/*}" rundir="${0%/*}"
# If running on login as a bashrc, the above variables will not give this script's data # If running on login as a bashrc, the above variables will not give this script's data
# Failover hardcoded settings location for now # Failover hardcoded settings location for now if running from login environment
if ! [[ $scriptname =~ "-bash" ]] ; then if ! [[ $scriptname =~ "-bash" ]] ; then
rundir_absolute=$(cd $rundir && pwd) #rundir_absolute=$(cd $rundir && pwd)
rundir_absolute=$(pushd $rundir && pwd && popd)
settingsfile=$(echo "$rundir_absolute/$scriptname" | sed -E 's/(.*)bashrc/\1settings/') settingsfile=$(echo "$rundir_absolute/$scriptname" | sed -E 's/(.*)bashrc/\1settings/')
else else
settingsfile="$HOME/.bashrc.d/11-quickinfo.settings" settingsfile="$HOME/.bashrc.d/11-quickinfo.settings"
fi fi
source $settingsfile source $settingsfile
# source PRbL functions
if [ ! -z $prbl_functions ] ; then
source $prbl_functions
else
# Failover if global variable is not defined. Checks for 'functions' in same location
echo -e "PRbL functions not defined. Check ~/.bashrc"
if [ -f "$rundir/functions" ] ; then
source $rundir/functions
else
echo -e "local functions file also missing. Some visual elements will be missing"
fi
fi
# check PRbL functions version # check PRbL functions version
if [[ $(vercomp $functionsrev $prbl_functons_req_ver) == 2 ]] ; then if [[ $(vercomp $functionsrev $prbl_functons_req_ver) == 2 ]] ; then
warn "PRbL functions installed are lower than recommended ($prbl_functons_req_ver)" warn "PRbL functions installed are lower than recommended ($prbl_functons_req_ver)"
@ -95,7 +102,7 @@ EOF
# Options parser # Options parser
while getopts ":cdh" opt while getopts ":h" opt
do do
case ${opt} in case ${opt} in
h) echo "$usage" h) echo "$usage"
@ -113,6 +120,11 @@ while getopts ":cdh" opt
################################ ################################
# Uncomment this section to disable running this in non-interactive sessions
# For example, on automated logins for a git process, the entire output of
# this script will be written to logs. Disabling non-interactive sessions
# will prevent this script from clogging the logging, but it also can cause
# unexpected exits if improperly deployed (immediate exit on ssh login)
#if [[ $interactive_only == true ]] ; then #if [[ $interactive_only == true ]] ; then
# [[ "$-" == *i* ]] || fail "non-interactive session" # [[ "$-" == *i* ]] || fail "non-interactive session"
#fi #fi
@ -139,9 +151,9 @@ fi
# Gets public IP address using opendns # Gets public IP address using opendns
# TODO: optimize this to run after time delay using timestamp in settings # TODO: optimize this to run after time delay using timestamp in settings
#spinstart & set_spinner spinner19
wan_ip=$(wget -qO- http://ipecho.net/plain | xargs echo) #spin "eval $(wan_ip=$(wget -qO- http://ipecho.net/plain \| xargs echo ))"
#spinstop wan_ip=$(wget -qO- http://ipecho.net/plain \| xargs echo )
# Checks memory usage # Checks memory usage
mem_usage=$(free -m | grep Mem | awk '{print $3"M/"$2"M"}') mem_usage=$(free -m | grep Mem | awk '{print $3"M/"$2"M"}')