Last active
October 30, 2020 16:09
-
-
Save geraldvillorente/b2f10c7a68620905ae64 to your computer and use it in GitHub Desktop.
A simple script of using rsync and inotify to manage two separate repositories.
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
#!/usr/bin/env bash | |
# | |
# @file | |
# A one directional auto-sync triggered by inotify. | |
# The inotify-utils must be installed in the system | |
# before using this script. | |
# | |
# @source | |
# $SOURCE - A git repository. | |
# | |
# @destination | |
# $DEST - Apache's document root. | |
# | |
# @author | |
# Gerald Villorente | |
# 2014 | |
# | |
# @description | |
# Auto-sync changes after Git pushed the updates to | |
# $SOURCE. Changes will be then sync to | |
# $DEST. | |
# The source directory. | |
SOURCE="/home/drupal/Repo/git/lol-oceanic" | |
# Your target directory. | |
DEST="/home/drupal/Repo/git/riotesportsoceanic/docroot" | |
EVENTS="CREATE,DELETE,MODIFY,MOVED_FROM,MOVED_TO" | |
# Check if inotofywait is installed. | |
hash inotifywait 2>/dev/null | |
if [ $? -eq 1 ]; then | |
echo "Unable to execute the script. Please make sure that inotify-utils | |
is installed in the system." | |
exit 1 | |
fi | |
inotifywait -e "$EVENTS" -m -r --format '%:e %f' $SOURCE --exclude '$SOURCE/.*cache.*' | ( | |
WAITING=""; | |
while true; do | |
LINE=""; | |
read -t 1 LINE; | |
if test -z "$LINE"; then | |
if test ! -z "$WAITING"; then | |
echo "CHANGE"; | |
WAITING=""; | |
rsync --update -alvzr --exclude '*cache*' --exclude '*.git*' $SOURCE/* $DEST | |
cd $DEST | |
git add * | |
git commit -am "Cron triggered commit" | |
git pull origin master | |
git push origin master | |
fi; | |
else | |
WAITING=1; | |
fi; | |
done) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For MacOS