Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Last active October 30, 2020 16:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/b2f10c7a68620905ae64 to your computer and use it in GitHub Desktop.
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.
#!/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)
@geraldvillorente
Copy link
Author

geraldvillorente commented Oct 4, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment