added group and domain support for conf file and repository
This commit is contained in:
@@ -10,9 +10,12 @@
|
|||||||
|
|
||||||
|
|
||||||
# Some useful variables:
|
# Some useful variables:
|
||||||
export HOST_REPO_PATH=${HOST_REPO_PATH:-"$MYPATH/repo/hosts/$HOSTNAME"}
|
export HOST_REPO_PATH=${HOST_REPO_PATH:-"$MYPATH/repo/hosts/$HOSTNAME"}
|
||||||
export GROUP_REPO_PATH=${GROUP_REPO_PATH:-"$MYPATH/repo/groups"}
|
export REALM_REPO_PATH=${REALM_REPO_PATH:-"$MYPATH/repo/realms/$REALM"}
|
||||||
export COMM_REPO_PATH=${COMM_REPO_PATH:-"$MYPATH/repo/common"}
|
export GROUP_REPO_PATH=${GROUP_REPO_PATH:-"$MYPATH/repo/groups/$GROUPNAME"}
|
||||||
|
export RLMGRP_REPO_PATH=${RLMGRP_REPO_PATH:-"$MYPATH/repo/realms/$REALM/groups/$GROUPNAME"}
|
||||||
|
export RLMHST_REPO_PATH=${RLMHST_REPO_PATH:-"$MYPATH/repo/realms/$REALM/hosts/$HOSTNAME"}
|
||||||
|
export COMM_REPO_PATH=${COMM_REPO_PATH:-"$MYPATH/repo/common"}
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -40,10 +43,10 @@ backup_dist()
|
|||||||
die 12
|
die 12
|
||||||
fi
|
fi
|
||||||
elif [[ -d ${file} ]]; then
|
elif [[ -d ${file} ]]; then
|
||||||
prnt I "Creation a backup of the directory ${file} on $tmstmp..."
|
prnt I "Creating a backup of the directory ${file} on $tmstmp..."
|
||||||
cp -av $file ${file}.dist.${tmstmp}
|
cp -av $file ${file}.dist.${tmstmp}
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
prnt E "backup_dist(): Failed copyind directory recursively."
|
prnt E "backup_dist(): Failed copying directory recursively."
|
||||||
die 12
|
die 12
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -58,11 +61,26 @@ export -f backup_dist
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Select source file according to our priority mechanism
|
# Select source file according to our priority mechanism
|
||||||
|
# 1) repo/<realm>/hosts/<hostname>/ => specific hostname in specific realm
|
||||||
|
# 2) repo/<realm>/groups/<groupname>/ => specific group in specific realm
|
||||||
|
# 3) repo/hosts/<hostname>/ => specific hostname in any realm
|
||||||
|
# 4) repo/groups/<groupname>/ => specific group in any realm
|
||||||
|
# 5) repo/<realm>/ => any hostname in specific realm
|
||||||
|
# 6) repo/common => any hostname any realm
|
||||||
|
# Note: if a specific hostname is provided it makes unecessary to find a group.
|
||||||
select_file()
|
select_file()
|
||||||
{
|
{
|
||||||
local infile=$1
|
local infile=$1
|
||||||
if [[ -f $HOST_REPO_PATH/$infile ]]; then
|
if [[ -f $RLMHST_REPO_PATH/$infile ]]; then
|
||||||
|
local source="$RLMHST_REPO_PATH/$infile"
|
||||||
|
elif [[ -f $RLMGRP_REPO_PATH/$infile ]]; then
|
||||||
|
local source="$RLMGRP_REPO_PATH/$infile"
|
||||||
|
elif [[ -f $HOST_REPO_PATH/$infile ]]; then
|
||||||
local source="$HOST_REPO_PATH/$infile"
|
local source="$HOST_REPO_PATH/$infile"
|
||||||
|
elif [[ -f $GROUP_REPO_PATH/$infile ]]; then
|
||||||
|
local source="$GROUP_REPO_PATH/$infile"
|
||||||
|
elif [[ -f $REALM_REPO_PATH/$infile ]]; then
|
||||||
|
local source="$REALM_REPO_PATH/$infile"
|
||||||
elif [[ -f $COMM_REPO_PATH/$infile ]]; then
|
elif [[ -f $COMM_REPO_PATH/$infile ]]; then
|
||||||
local source="$COMM_REPO_PATH/$infile"
|
local source="$COMM_REPO_PATH/$infile"
|
||||||
else
|
else
|
||||||
@@ -77,12 +95,20 @@ export -f select_file
|
|||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Select source directory according to our priority mechanism
|
# Select source directory according to our priority mechanism (same as above)
|
||||||
select_directory()
|
select_directory()
|
||||||
{
|
{
|
||||||
local indir=$1
|
local indir=$1
|
||||||
if [[ -d $HOST_REPO_PATH/$indir ]]; then
|
if [[ -d $RLMHST_REPO_PATH/$indir ]]; then
|
||||||
|
local source="$RLMHST_REPO_PATH/$indir"
|
||||||
|
elif [[ -d $RLMGRP_REPO_PATH/$indir ]]; then
|
||||||
|
local source="$RLMGRP_REPO_PATH/$indir"
|
||||||
|
elif [[ -d $HOST_REPO_PATH/$indir ]]; then
|
||||||
local source="$HOST_REPO_PATH/$indir"
|
local source="$HOST_REPO_PATH/$indir"
|
||||||
|
elif [[ -d $GROUP_REPO_PATH/$indir ]]; then
|
||||||
|
local source="$GROUP_REPO_PATH/$indir"
|
||||||
|
elif [[ -d $REALM_REPO_PATH/$indir ]]; then
|
||||||
|
local source="$REALM_REPO_PATH/$indir"
|
||||||
elif [[ -d $COMM_REPO_PATH/$indir ]]; then
|
elif [[ -d $COMM_REPO_PATH/$indir ]]; then
|
||||||
local source="$COMM_REPO_PATH/$indir"
|
local source="$COMM_REPO_PATH/$indir"
|
||||||
else
|
else
|
||||||
@@ -116,19 +142,16 @@ install_file()
|
|||||||
local arg=
|
local arg=
|
||||||
for arg in $@; do
|
for arg in $@; do
|
||||||
filelist="$filelist $(select_file $arg)"
|
filelist="$filelist $(select_file $arg)"
|
||||||
|
# We always replace until the last argument being the target
|
||||||
|
target="$arg"
|
||||||
done
|
done
|
||||||
unset arg
|
unset arg
|
||||||
|
|
||||||
# Empty to just obtain the target which is the last element of the list
|
if [[ ! $target == /* ]]; then
|
||||||
local file=
|
|
||||||
for file in $filelist; do
|
|
||||||
:
|
|
||||||
done
|
|
||||||
if [[ ! $file == /* ]]; then
|
|
||||||
prnt E "install_file(): Target must be on the root filesystem and full path must be provided."
|
prnt E "install_file(): Target must be on the root filesystem and full path must be provided."
|
||||||
die 13
|
die 13
|
||||||
fi
|
fi
|
||||||
unset file
|
unset target
|
||||||
|
|
||||||
if [[ -d $(dirname $i) ]]; then
|
if [[ -d $(dirname $i) ]]; then
|
||||||
prnt I "Creating required target directory $(dirname $i)..."
|
prnt I "Creating required target directory $(dirname $i)..."
|
||||||
@@ -152,14 +175,19 @@ export -f install_file
|
|||||||
# Add the content of a file at the end of an other
|
# Add the content of a file at the end of an other
|
||||||
append_file()
|
append_file()
|
||||||
{
|
{
|
||||||
|
if [[ $# -ne 2 ]]; then
|
||||||
|
prnt E "append_file(): Two arguments are required, source and destination."
|
||||||
|
die 11
|
||||||
|
fi
|
||||||
|
|
||||||
local srcfile=$(select_file $1)
|
local srcfile=$(select_file $1)
|
||||||
local dstfile=$2
|
local dstfile=$2
|
||||||
if [[ -e $dstfile ]]; then
|
if [[ ! $dstfile == /* ]]; then
|
||||||
prnt E "append_file(): Target must be on the root filesystem and full path must be provided."
|
prnt E "append_file(): Target must be on the root filesystem and full path must be provided."
|
||||||
die 13
|
die 13
|
||||||
fi
|
fi
|
||||||
if [[ ! $dstfile == /* ]]; then
|
if [[ -e $dstfile ]]; then
|
||||||
prnt E "append_file(): Target file must exist."
|
prnt E "append_file(): Target file must exist (use touch first to create it if required)."
|
||||||
die 13
|
die 13
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -303,6 +331,7 @@ directory_exists()
|
|||||||
}
|
}
|
||||||
export -f directory_exists
|
export -f directory_exists
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# check if file exists and return error if not
|
# check if file exists and return error if not
|
||||||
directory_must_exists()
|
directory_must_exists()
|
||||||
@@ -315,7 +344,7 @@ directory_must_exists()
|
|||||||
fi
|
fi
|
||||||
unset md
|
unset md
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export -f directory_must_exists
|
export -f directory_must_exists
|
||||||
|
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ export -f load_autoconf
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Load configuration with the following priorities:
|
# Load configuration with the following priorities:
|
||||||
# 1) Those given on command line, if any
|
# 1) Those given on command line, if any
|
||||||
# 2) <workingdir>/conf/<hostname>.conf (Hostname based and specific)
|
# 2) <workingdir>/conf/<realm>/<hostname>.conf (Hostname based and specific)
|
||||||
# 3) <workingdir>/conf/init.conf.sh (Generic default)
|
# 2) <workingdir>/conf/<hostname>.conf (Hostname based and specific)
|
||||||
|
# 3) <workingdir>/conf/init.conf.sh (Generic default, for testing)
|
||||||
load_configuration()
|
load_configuration()
|
||||||
{
|
{
|
||||||
if [[ -n $CONFFILES ]]; then
|
if [[ -n $CONFFILES ]]; then
|
||||||
@@ -71,7 +72,10 @@ load_configuration()
|
|||||||
unset f
|
unset f
|
||||||
else
|
else
|
||||||
prnt I "Loading configuration..."
|
prnt I "Loading configuration..."
|
||||||
if [[ -e $MYPATH/conf/$HOSTNAME.conf.sh ]]; then
|
if [[ -e $MYPATH/conf/$REALM/$HOSTNAME.conf.sh ]]; then
|
||||||
|
prnt I "A specific configuration will be used."
|
||||||
|
. $MYPATH/conf/$HOSTNAME.conf.sh
|
||||||
|
elif [[ -e $MYPATH/conf/$HOSTNAME.conf.sh ]]; then
|
||||||
prnt I "A specific configuration will be used."
|
prnt I "A specific configuration will be used."
|
||||||
. $MYPATH/conf/$HOSTNAME.conf.sh
|
. $MYPATH/conf/$HOSTNAME.conf.sh
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user