implemented appendfile

This commit is contained in:
levasseur
2021-10-12 17:00:43 +02:00
parent 2859cbfc67
commit ef2e724d1a

View File

@@ -117,6 +117,40 @@ installfile()
export -f installfile
# ------------------------------------------------------------------------------
# Add the content of a file at the end of an other
appendfile()
{
local infile=$1
if [[ -f $MYPATH/repo/hosts/$HOSTNAME/$infile ]]; then
local source="$MYPATH/repo/hosts/$HOSTNAME/$infile"
elif [[ -f $MYPATH/repo/common/$infile ]]; then
local source="$MYPATH/repo/common/$infile"
else
# Not found in repository, we expect full name
local source="$infile"
fi
unset infile
local file=$2
if [[ -e $file ]]; then
prnt E "appendfile(): Target must be on the root filesystem and full path must be provided."
die 13
fi
if [[ ! $file == /* ]]; then
prnt E "appendfile(): Target file must exist."
die 13
fi
prnt I "Ajout de contenu au fichier $file..."
cat $ource >> $file
if [[ $? -ne 0 ]]; then
prnt E "appendfile(): Couldn't append a file!"
die 12
fi
}
# ------------------------------------------------------------------------------
# determine if a directory is empty
isdirempty()