From 6131afa3e36b39e79f36346c05a459c72e6f7f45 Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Thu, 27 Jan 2022 19:57:38 +0100 Subject: [PATCH] filefct.sh: few fixes after last commit --- lib/filefct.sh | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/filefct.sh b/lib/filefct.sh index af35b9e..78865e8 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -15,7 +15,7 @@ backup_dist() { if [[ $# -lt 1 ]]; then - prnt E "backupdist(): At least one argument is required." + prnt E "backup_dist(): At least one argument is required." exit 11 fi @@ -23,31 +23,31 @@ backup_dist() for file in $@; do local tmstmp=$(stdtime) if [[ -L ${file} ]]; then - # With symbolik links we call again backupdist to treat target + # With symbolik links we call again backup_dist to treat target prnt I "Following the symbolic link $file to do a proper backup..." - backupdist $(readlink -f ${file}) + backup_dist $(readlink -f ${file}) elif [[ -f ${file} ]]; then prnt I "Creating a backup of ${file} on $tmstmp..." cp -av $file ${file}.dist.${tmstmp} if [[ $? -ne 0 ]]; then - prnt E "backupdist(): Failed copying file." + prnt E "backup_dist(): Failed copying file." die 12 fi elif [[ -d ${file} ]]; then prnt I "Creation a backup of the directory ${file} on $tmstmp..." cp -av $file ${file}.dist.${tmstmp} if [[ $? -ne 0 ]]; then - prnt E "backupdist(): Failed copyind directory recursively." + prnt E "backup_dist(): Failed copyind directory recursively." die 12 fi else - prnt W "backupdist(): $file don't exists, nothing to do." + prnt W "backup_dist(): $file don't exists, nothing to do." fi unset tmstmp done unset file } -export -f backupdist +export -f backup_dist # ------------------------------------------------------------------------------ @@ -67,6 +67,7 @@ select_file() echo $source unset source } +export -f select_file # ------------------------------------------------------------------------------ @@ -86,6 +87,7 @@ select_directory() echo $source unset source } +export -f select_directory # ------------------------------------------------------------------------------ @@ -97,11 +99,11 @@ install_file() local i=0 if [[ $# -lt 2 ]]; then - prnt E "installfile(): At least two arguments are required." + prnt E "install_file(): At least two arguments are required." die 11 fi if [[ $(echo $@ | grep "\*\|\?") ]]; then - prnt E "installfile(): Wildcards are not authorized." + prnt E "install_file(): Wildcards are not authorized." die 7 fi @@ -117,7 +119,7 @@ install_file() : done if [[ ! $file == /* ]]; then - prnt E "installfile(): 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 fi unset file @@ -126,18 +128,18 @@ install_file() prnt I "Creating required target directory $(dirname $i)..." mkdir -pv $(dirname $i) if [[ $? -ne 0 ]]; then - prnt E "installfile(): Can't create target directory!" + prnt E "install_file(): Can't create target directory!" die 12 fi fi prnt I "Copying files ${filelist} to target directory $(dirname $i)..." cp -av $filelist if [[ $? -ne 0 ]]; then - prnt E "installfile(): Couldn't copy some required files!" + prnt E "install_file(): Couldn't copy some required files!" die 12 fi } -export -f installfile +export -f install_file # ------------------------------------------------------------------------------ @@ -147,22 +149,22 @@ append_file() local srcfile=$(select_file $1) local dstfile=$2 if [[ -e $dstfile ]]; then - prnt E "appendfile(): 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 fi if [[ ! $dstfile == /* ]]; then - prnt E "appendfile(): Target file must exist." + prnt E "append_file(): Target file must exist." die 13 fi prnt I "Adding content to file $dstfile..." cat $srcfile >> $dstfile if [[ $? -ne 0 ]]; then - prnt E "appendfile(): Couldn't append a file!" + prnt E "append_file(): Couldn't append a file!" die 12 fi } -export -f appendfile +export -f append_file # ------------------------------------------------------------------------------ @@ -172,7 +174,7 @@ is_dir_empty() dir=$1 if [[ -f $dir ]]; then - prnt E "isdirempty(): The given parameter is not a directory." + prnt E "is_dir_empty(): The given parameter is not a directory." die 15 fi if [[ ! -d $dir ]]; then @@ -185,7 +187,7 @@ is_dir_empty() fi return 1 } -export -f isdirempty +export -f is_dir_empty # ------------------------------------------------------------------------------ @@ -198,7 +200,7 @@ patch_file() local workfile=${dstfile}.work if [[ ! -s $srcfile ]]; then - prnt E "patchfile(): Source file is empty, is not a file or don't exists!" + prnt E "patch_file(): Source file is empty, is not a file or don't exists!" die 10 fi @@ -231,7 +233,7 @@ patch_file() unset rights dstfile } -export -f patchfile +export -f patch_file # ------------------------------------------------------------------------------ @@ -248,7 +250,7 @@ tag_file() fi done } -export -f tagfile +export -f tag_file # ------------------------------------------------------------------------------