implemented realm detection and improved configuration files loading
This commit is contained in:
@@ -59,6 +59,17 @@ export -f load_autoconf
|
||||
# 3) <workingdir>/conf/init.conf.sh (Generic default, for testing)
|
||||
load_configuration()
|
||||
{
|
||||
# --------------------------------------------------------------------------
|
||||
# Get list of possible files to load when REALM is not declared
|
||||
get_files()
|
||||
{
|
||||
for d in $MYPATH/conf/*; do
|
||||
if [[ -d $d ]]; then
|
||||
find $d -maxdepth 1 -name "$HOSTNAME.conf.sh"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -n $CONFFILES ]]; then
|
||||
local f=
|
||||
for f in $CONFFILES; do
|
||||
@@ -73,21 +84,48 @@ load_configuration()
|
||||
unset f
|
||||
else
|
||||
prnt I "Loading configuration..."
|
||||
if [[ -z $REALM ]]; then
|
||||
prnt W "REALM is undeclared, trying to scan configuration subdirectories for this host..."
|
||||
local found_realms=$(get_files)
|
||||
case "$(echo $found_realms | wc -w)" in
|
||||
"0")
|
||||
: # We do nothing as we'll check for other scenario
|
||||
;;
|
||||
"1")
|
||||
export REALM="$(basename $(dirname $found_realms))"
|
||||
local auto_realm="$REALM"
|
||||
;;
|
||||
*)
|
||||
prnt E "More than one file correspond to that host. This is ambigous and need to be fixed."
|
||||
prnt m "You can fix that situation with one of those actions:"
|
||||
prnt m "\t * Declare a REALM variable with the actual domain name of the host."
|
||||
prnt m "\t * Give manually the configuration file using the --file option."
|
||||
prnt m "\t * Configure the domain name of the host."
|
||||
die 20 --force
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [[ -e $MYPATH/conf/$REALM/$HOSTNAME.conf.sh ]]; then
|
||||
prnt I "A specific configuration will be used."
|
||||
. $MYPATH/conf/$HOSTNAME.conf.sh
|
||||
local cnffile=$MYPATH/conf/$REALM/$HOSTNAME.conf.sh
|
||||
if [[ -n $auto_realm && $REALM != $auto_realm ]]; then
|
||||
prnt E "The domain name in the confinguration file don't correspond to the detected domain through directory structure."
|
||||
die 21 --force
|
||||
fi
|
||||
elif [[ -e $MYPATH/conf/$HOSTNAME.conf.sh ]]; then
|
||||
prnt I "A specific configuration will be used."
|
||||
. $MYPATH/conf/$HOSTNAME.conf.sh
|
||||
local cnffile=$MYPATH/conf/$HOSTNAME.conf.sh
|
||||
else
|
||||
if [[ -e $MYPATH/conf/init.conf.sh ]]; then
|
||||
prnt I "A generic configuration will be used."
|
||||
. $MYPATH/conf/init.conf.sh
|
||||
local cnffile=$MYPATH/conf/init.conf.sh
|
||||
else
|
||||
prnt E "No configuration found, impossible to continue."
|
||||
die 6 --force
|
||||
fi
|
||||
fi
|
||||
prnt I "Loading $cnffile ..."
|
||||
. $cnffile
|
||||
fi
|
||||
}
|
||||
export -f load_configuration
|
||||
|
||||
Reference in New Issue
Block a user