Added manual configuration through command line, finished function headers comments
This commit is contained in:
@@ -7,14 +7,20 @@
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Read command line and set appropriate vars. Some basic checks can trigger
|
||||
# errors with immediate exit.
|
||||
read_commandline()
|
||||
{
|
||||
# Processing command line options
|
||||
local want_module=false
|
||||
local want_logfile=false
|
||||
local want_conffile=false
|
||||
|
||||
for opt in $@; do
|
||||
if [[ $want_module != true ]] && [[ $want_logfile != true ]]; then
|
||||
if [[ $want_module != true ]] && [[ $want_logfile != true ]] &&
|
||||
[[ $want_conffile != true ]]; then
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
disp_help
|
||||
@@ -51,6 +57,9 @@ read_commandline()
|
||||
"-l"|"--logfile")
|
||||
local want_logfile=true
|
||||
;;
|
||||
"-f"|"--file")
|
||||
local want_conffile=true
|
||||
;;
|
||||
*)
|
||||
prnt E "Paramètre \"$opt\" non géré."
|
||||
die 1 --force
|
||||
@@ -59,16 +68,18 @@ read_commandline()
|
||||
else
|
||||
if [[ $want_module == true ]]; then
|
||||
[[ $want_logfile == true ]] && synthax_error
|
||||
[[ $want_conffile == true ]] && synthax_error
|
||||
if [[ ! $MANUAL_MODULE_LIST ]]; then
|
||||
export MANUAL_MODULE_LIST=$opt
|
||||
want_module=false
|
||||
else
|
||||
prnt E "Une liste de module à déjà été fournie !"
|
||||
prnt E "La ligne de commande ne tolère qu'un paramètre --module."
|
||||
prnt E "La ligne de commande ne tolère qu'un seul paramètre --module."
|
||||
die 1 --force
|
||||
fi
|
||||
elif [[ $want_logfile == true ]]; then
|
||||
[[ $want_module == true ]] && synthax_error
|
||||
[[ $want_conffile == true ]] && synthax_error
|
||||
if [[ ! $NEW_LOGFILE ]]; then
|
||||
export NEW_LOGFILE=$opt
|
||||
want_logfile=false
|
||||
@@ -76,6 +87,11 @@ read_commandline()
|
||||
prnt E "Il n'est pas possible de spécifier plusieurs fichiers de log."
|
||||
die 1 --force
|
||||
fi
|
||||
elif [[ $want_conffile == true ]]; then
|
||||
[[ $want_module == true ]] && synthax_error
|
||||
[[ $want_logfile == true ]] && synthax_error
|
||||
export CONFFILES="$CONFFILES $opt"
|
||||
want_logfile=false
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -88,24 +104,44 @@ read_commandline()
|
||||
}
|
||||
export -f read_commandline
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Load configuration with the following priorities:
|
||||
# 1) Those given on command line, if any
|
||||
# 2) <workingdir>/conf/<hostname>.conf (Hostname based and specific)
|
||||
# 3) <workingdir>/conf/init.conf.sh (Generic default)
|
||||
load_configuration()
|
||||
{
|
||||
prnt I "Chargement de la configuration..."
|
||||
if [[ -e $MYPATH/conf/$HOSTNAME.conf ]]; then
|
||||
prnt I "Une configuration spécifique sera utilisé."
|
||||
. $MYPATH/conf/$HOSTNAME.conf
|
||||
if [[ -n $CONFFILES ]]; then
|
||||
for f in $CONFFILES; do
|
||||
prnt I "Chargement de $f spécifié manuellement."
|
||||
if [[ -s $f ]]; then
|
||||
. $f
|
||||
else
|
||||
prnt E "Le fichier $f n'existe pas ou est vide."
|
||||
die 6 --force
|
||||
fi
|
||||
done
|
||||
else
|
||||
if [[ -e $MYPATH/conf/init.conf.sh ]]; then
|
||||
prnt I "Une configuration générique sera utilisé."
|
||||
. $MYPATH/conf/init.conf.sh
|
||||
prnt I "Chargement de la configuration..."
|
||||
if [[ -e $MYPATH/conf/$HOSTNAME.conf ]]; then
|
||||
prnt I "Une configuration spécifique sera utilisé."
|
||||
. $MYPATH/conf/$HOSTNAME.conf
|
||||
else
|
||||
prnt E "Aucune configuration trouvée, impossible de continuer."
|
||||
die 6 --force
|
||||
if [[ -e $MYPATH/conf/init.conf.sh ]]; then
|
||||
prnt I "Une configuration générique sera utilisé."
|
||||
. $MYPATH/conf/init.conf.sh
|
||||
else
|
||||
prnt E "Aucune configuration trouvée, impossible de continuer."
|
||||
die 6 --force
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
export -f load_configuration
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Do deeper command line analysis to detect unconsistancies
|
||||
process_commandline_and_vars()
|
||||
{
|
||||
# Check unconsistant parameters
|
||||
@@ -148,3 +184,6 @@ process_commandline_and_vars()
|
||||
fi
|
||||
}
|
||||
export -f process_commandline_and_vars
|
||||
|
||||
# EOF
|
||||
|
||||
|
||||
Reference in New Issue
Block a user