From ef2e724d1a6d3e7104c7a6e6551ccc87a0888cd0 Mon Sep 17 00:00:00 2001 From: levasseur Date: Tue, 12 Oct 2021 17:00:43 +0200 Subject: [PATCH] implemented appendfile --- lib/filefct.sh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/filefct.sh b/lib/filefct.sh index c342b15..848f54f 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -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() @@ -139,7 +173,7 @@ isdirempty() # patch a file replacing all @var@ by the corresponding value in environment patchfile() { - : # todo + : # todo } # EOF