Last active
February 22, 2017 14:11
-
-
Save kstefanini/1eba1c8b3a2470c0c9dc40a5baa46db4 to your computer and use it in GitHub Desktop.
Cron-able script for auto pull
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Permet de mettre à jour un dépot git local à partir d'un remote github | |
# Va chercher le sha du dernier commit distant et le compare au sha stocké | |
# suite au dernier lancement du script. Si le sha est différent, le | |
# script lance le git pull | |
# Si le script est bloqué, faut vider le fichier dans /tmp avant de relancer | |
OWNER="telabotanica" | |
REPO="wp-theme-telabotanica" | |
# fichier contenant le sha du dernier commit | |
SHAFILE="/tmp/lastCommitSha_$OWNER-$REPO.sha" | |
SOURCESPATH="/var/www" | |
ERRORMAILS="[email protected]" | |
if [[ -e $SHAFILE ]]; then | |
read -r PREVIOUSSHA<$SHAFILE | |
else | |
PREVIOUSSHA="lolilol" | |
fi | |
SHA=$(curl -s "https://api.github.com/repos/$OWNER/$REPO/commits" | python -c "import sys, json; print json.load(sys.stdin)[0]['sha']") | |
if [[ $SHA != $PREVIOUSSHA ]]; then | |
$(echo $SHA>$SHAFILE) | |
#git pull au bon endroit | |
ERRORMESSAGE=$(eval cd $SOURCESPATH && git pull && composer install) | |
for EMAIL in $ERRORMAILS; do | |
[[ -z "$ERRORMESSAGE" || "Already up-to-date." = $ERRORMESSAGE ]] || echo $ERRORMESSAGE | mail -n -s "Erreur avec le script de pull auto, PREVIOUSSHA:$PREVIOUSSHA, SHA:$SHA" $EMAIL | |
done | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment