INGit for Is Not GIT

Rédigé par BeHuman 3 commentaires
Classé dans : Shell/Bash Mots clés : git, version, commit, hscript

Is Not GIT mais il l'utilise 

Dans l'idée de HScript, Ingit est basé sur ce dernier. j'ai juste ajouté une routine pour commiter tranquille avec GIT et ainsi avoir à disposition mes sauvegardes de fichier modifier couplet au gestionnaire de version GIT.

 

 

 

#! /bin/bash

_help() {
    printf "
INGit for Is Not GIT
GNU/GPL v3
by BeHuman (craft at ckdevelop dot org)

Utilisation :
        ingeet <directory backup> <directory scan> <no display>
        Help:   -h
Exemple :
	ingeet backups WWW '.jpg|.png|.gif|.pdf|.swf|atos-[0-9]*|.csv|.bz2|.zip|.log|.rar|.mp4|.mp3|.eot'

"
    exit
}

_veriffiles() {
    commit='no'
    find "$2" | egrep -v "$3" | grep -v ".git" | while read filename; do
        if [ -f "$filename" ]; then
            modif=$(stat -c '%y' "$filename")
            tim=${modif#* }
            tim=${tim%.*}
            hour=${tim%%:*}
            year=${modif%%-*}
            base=${modif%% *}
            day=${base##*-}
            month=${base#*-}
            month=${month%-*}
            pfile=`echo $filename | sed -e 's/\//_/g'`
            if [ -d "$1/$year" ]; then
                if [ -d "$1/$year/$month" ]; then
                    if [ -d "$1/$year/$month/$day" ]; then
                        if [ -d "$1/$year/$month/$day/$hour" ]; then
                            if [ ! -f "$1/$year/$month/$day/$hour/[$tim]-$pfile" ]; then
                                echo "Copie de $filename"
                                commit='ok'
                                cp -p "$filename" "$1/$year/$month/$day/$hour/[$tim]-$pfile"
                                oldy=$PWD
                                cd "$2"
                                echo "Commit en cours..."
                                #git pull
                                git commit -a -m "`date`"
                                cd $oldy
                            fi
                        fi
                    fi
                fi
            fi
        fi
    done
}

_verifdir() {
    if [ -d "$1" ]; then
        cd "$1"
    else
        echo "création du repertoire $1"
        mkdir "$1"
        cd "$1"
    fi
}

_history() {
    _verifdir "$1"
    _verifdir `date +%Y`
    _verifdir `date +%m`
    _verifdir `date +%d`
    _verifdir `date +%H`
    cd "$3"
    if [ ! -d "$2/.git" ]; then
        cd $2
        git init
        git add .
        echo "Commit en cours..."
        git commit -a -m "Initial import"
        #git pull
    fi
    cd $3
    _veriffiles "$1" "$2" "$4"
    sleep 5
    _history "$1" "$2" "$3" "$4"
}

if [ "$1" == "-h" ];then
    _help
else
    _history "$1" "$2" "$PWD" "$3"
fi

 

3 commentaires

#1  - ShiNooby a dit :

Merci mec !!
cependant dans la fonction _veriffiles() j'ai ajouté un contrôle sur index.lock

_veriffiles() {
commit='no'
find "$2" | egrep -v "$3" | grep -v ".git" | while read filename; do
if [ -f "$filename" ]; then
modif=$(stat -c '%y' "$filename")
tim=${modif#* }
tim=${tim%.*}
hour=${tim%%:*}
year=${modif%%-*}
base=${modif%% *}
day=${base##*-}
month=${base#*-}
month=${month%-*}
pfile=`echo $filename | sed -e 's/\//_/g'`
if [ -d "$1/$year" ]; then
if [ -d "$1/$year/$month" ]; then
if [ -d "$1/$year/$month/$day" ]; then
if [ -d "$1/$year/$month/$day/$hour" ]; then
if [ ! -f "$1/$year/$month/$day/$hour/[$tim]-$pfile" ]; then
echo "Copie de $filename"
commit='ok'
cp -p "$filename" "$1/$year/$month/$day/$hour/[$tim]-$pfile"
oldy=$PWD
cd "$2"
echo "Commit en cours..."
if [ -f ".git/index.lock" ]; then
echo "Suppression de .git/index.lock"
rm -f ".git/index.lock"
fi
#git pull
git commit -a -m "`date`"
cd $oldy
fi
fi
fi
fi
fi
fi
done
}

Répondre
#2  - ShiNooby a dit :

oups, désolé :/ ça n'a pas gardé l'indentation

Répondre
#3  - BeHuman a dit :

@ShiNooby :
yes cool l'ami :) je l'intègre dans mon script.

Répondre

Écrire un commentaire

Quelle est la sixième lettre du mot x6v2tpk ?

Fil RSS des commentaires de cet article