From 754dfa19340ee76254a6189833aec67085d84f0a Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Mon, 7 Jun 2021 18:31:54 +0200 Subject: [PATCH] cleanup main program initialization and add stdtime function to libs --- init.sh | 9 ++++----- lib/filefct.sh | 9 ++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/init.sh b/init.sh index f693e9e..28ba0ef 100755 --- a/init.sh +++ b/init.sh @@ -4,14 +4,13 @@ MYPATH=$(dirname $0) # Load libraries -. $MYPATH/lib/display.sh -. $MYPATH/lib/filefct.sh +for lib in $MYPATH/lib/*.sh; do + . $lib +done # Important global variables export HOSTNAME=$(hostname) - -export DATEFORMAT=${DATEFORMAT:-"+%Y/%m/%d-%H:%M:%S-%N"} -export LOGFILE=${LOGFILE:-"/var/log/$(uname -n)-$(date +%Y%m%d-%H%M).log"} +export LOGFILE=${LOGFILE:-"/var/log/$(uname -n)-$(stdtime).log"} # Authentication #authnz() diff --git a/lib/filefct.sh b/lib/filefct.sh index 923b865..ecf4756 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -1,4 +1,11 @@ +# Define normalised time display, filename friendly +stdtime() +{ + date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g' +} +export -f stdtime + # Backup original installation files # (or any old files if runned several time on same file) backupdist() @@ -9,7 +16,7 @@ backupdist() for file in $@; do if [[ -e ${file} ]]; then - tmpstmp=$(date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g') + tmpstmp=$(stdtime) prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..." cp -av $file $file.dist.$tmpstmp fi