diff --git a/init.sh b/init.sh index 73eadf6..fc6666f 100755 --- a/init.sh +++ b/init.sh @@ -1,12 +1,13 @@ #!/bin/bash +# Remember the running path +MYPATH=$(dirname $0) + # Load libraries -. lib/display.sh -. lib/filefct.sh - -# Check gestparc native directory -#export REPO="/share/services/gestparc" +. $MYPATH/lib/display.sh +. $MYPATH/lib/filefct.sh +# Important global variables export HOSTNAME=$(hostname) export DATEFORMAT=${DATEFORMAT:-"+%Y/%m/%d-%H:%M:%S-%N"} diff --git a/lib/filefct.sh b/lib/filefct.sh index dd65f23..923b865 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -1,13 +1,17 @@ -# Backup original installation files (or any old files if runned several time on same file) +# 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 + [[ $# -lt 1 ]] && + prnt E "backupdist(): Au moins un argument requis." && + exit 129 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') + tmpstmp=$(date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g') + prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..." + cp -av $file $file.dist.$tmpstmp fi done } @@ -21,18 +25,18 @@ installfile() [[ $# -lt 2 ]] && ( prnt E "installfile(): Au moins deux arguments requis." - return 1 + exit 129 ) [[ $(echo $@ | grep "\*\|\?") ]] && ( prnt E "installfile(): Les wildcards sont interdits." - return 2 + exit 10 ) 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" + if [[ -f $MYPATH/repo/hosts/$HOSTNAME/$arg ]]; then + filelist="$filelist $MYPATH/repo/hosts/$HOSTNAME/$arg" + elif [[ -f $MYPATH/repo/common/$arg ]]; then + filelist="$filelist $MYPATH/repo/common/$arg" else filelist="$filelist $arg" fi @@ -42,7 +46,7 @@ installfile() 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..." + prnt I "Création du répertoire $(dirname $i) si nécessaire..." mkdir -pv $(dirname $i) prnt I "Copie des fichiers ${filelist}..." cp -av $filelist