several improvement and armonisation in filefct.sh, module auth and patch_snmp improved
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Backup original installation files
|
||||
# (or any old files if runned several time on same file)
|
||||
backupdist()
|
||||
backup_dist()
|
||||
{
|
||||
if [[ $# -lt 1 ]]; then
|
||||
prnt E "backupdist(): At least one argument is required."
|
||||
@@ -51,7 +51,7 @@ export -f backupdist
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Select source file according to our priority mechanisme
|
||||
# Select source file according to our priority mechanism
|
||||
select_file()
|
||||
{
|
||||
local infile=$1
|
||||
@@ -69,10 +69,29 @@ select_file()
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Select source directory according to our priority mechanism
|
||||
select_directory()
|
||||
{
|
||||
local indir=$1
|
||||
if [[ -d $MYPATH/repo/hosts/$HOSTNAME/$indir ]]; then
|
||||
local source="$MYPATH/repo/hosts/$HOSTNAME/$indir"
|
||||
elif [[ -d $MYPATH/repo/common/$indir ]]; then
|
||||
local source="$MYPATH/repo/common/$indir"
|
||||
else
|
||||
# Not found in repository, we expect full name
|
||||
local source="$indir"
|
||||
fi
|
||||
unset indir
|
||||
echo $source
|
||||
unset source
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install file to the host (specific first then general)
|
||||
# Todo: implement wildcard support
|
||||
installfile()
|
||||
install_file()
|
||||
{
|
||||
local filelist=""
|
||||
local i=0
|
||||
@@ -123,7 +142,7 @@ export -f installfile
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add the content of a file at the end of an other
|
||||
appendfile()
|
||||
append_file()
|
||||
{
|
||||
local srcfile=$(select_file $1)
|
||||
local dstfile=$2
|
||||
@@ -148,7 +167,7 @@ export -f appendfile
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# determine if a directory is empty
|
||||
isdirempty()
|
||||
is_dir_empty()
|
||||
{
|
||||
dir=$1
|
||||
|
||||
@@ -172,7 +191,7 @@ export -f isdirempty
|
||||
# ------------------------------------------------------------------------------
|
||||
# copy and patch a file replacing all @var@ by the corresponding value in
|
||||
# the environment or the variable list given in parameter
|
||||
patchfile()
|
||||
patch_file()
|
||||
{
|
||||
local srcfile=$(select_file $1) && shift
|
||||
local dstfile=$1 && shift
|
||||
@@ -217,7 +236,7 @@ export -f patchfile
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Put a small header in a file showing it have been automatically modified
|
||||
tagfile()
|
||||
tag_file()
|
||||
{
|
||||
for f in $@; do
|
||||
local text="# File automatically modified by init.sh on $(stdtime)."
|
||||
@@ -233,17 +252,60 @@ export -f tagfile
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# check a file exists and return error if not
|
||||
# check files exists and return 1 if one do not
|
||||
file_exists()
|
||||
{
|
||||
prnt I "Checking $@ files existance..."
|
||||
for f in $@; do
|
||||
if [[ ! -f $(select_file $f) ]]; then
|
||||
prnt E "file_exists(): The $f file is missing, can't continue."
|
||||
die 10
|
||||
fi
|
||||
echo $f
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
export -f file_exists
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# check if file exists and return error if not
|
||||
file_must_exists()
|
||||
{
|
||||
prnt I "Checking $@ files existance..."
|
||||
local mf=$(file_exists $@)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
prnt E "file_must_exists(): The $mf file is missing, can't continue."
|
||||
die 10
|
||||
fi
|
||||
unset mf
|
||||
}
|
||||
export -f file_must_exists
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# check files exists and return 1 if one do not
|
||||
directory_exists()
|
||||
{
|
||||
for d in $@; do
|
||||
if [[ ! -d $(select_directory $d) ]]; then
|
||||
echo $d
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
export -f directory_exists
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# check if file exists and return error if not
|
||||
directory_must_exists()
|
||||
{
|
||||
prnt I "Checking $@ directories existance..."
|
||||
local md=$(directory_exists $@)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
prnt E "directory_must_exists(): The $md directory is missing, can't continue."
|
||||
die 10
|
||||
fi
|
||||
unset md
|
||||
}
|
||||
export -f directory_must_exists
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user