moved code to new libs, conf moved to subfolder, conf splitted into unit and specific files

This commit is contained in:
levasseur
2021-06-01 12:35:38 +02:00
parent 6c70c0826f
commit 50f4f40eff
5 changed files with 167 additions and 187 deletions

50
lib/filefct.sh Normal file
View File

@@ -0,0 +1,50 @@
# Backup original installation files (or any old files if runned several time on same file)
backupdist()
{
[[ $# -lt 1 ]] && prnt E "backupdist(): Au moins un argument requis." && return 1
for file in $@; do
if [[ -e ${file} ]]; then
prnt I "Création d'une copie de sauvegarde de ${file}..."
cp -av $file $file.dist.$(date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g')
fi
done
}
export -f backupdist
# Install file to the host (specific first then general)
installfile()
{
local filelist=""
local i=0
[[ $# -lt 2 ]] && (
prnt E "installfile(): Au moins deux arguments requis."
return 1
)
[[ $(echo $@ | grep "\*\|\?") ]] && (
prnt E "installfile(): Les wildcards sont interdits."
return 2
)
for arg in $@; do
if [[ -f $BASEGPDIR/profile/$HOSTNAME/$arg ]]; then
filelist="$filelist $BASEGPDIR/profile/$HOSTNAME/$arg"
elif [[ -f $BASEGPDIR/profile/$arg ]]; then
filelist="$filelist $BASEGPDIR/profile/$arg"
else
filelist="$filelist $arg"
fi
done
for i in $filelist; do :; done
if [[ ! $i==/* ]]; then
prnt E "installfile(): Target must be on the root filesystem."
exit 3
fi
prnt I "Création su répertoire $(dirname $i) si nécessaire..."
mkdir -pv $(dirname $i)
prnt I "Copie des fichiers ${filelist}..."
cp -av $filelist
}
export -f installfile