Created
September 28, 2012 16:39
-
-
Save greenarrow/3800846 to your computer and use it in GitHub Desktop.
gsync
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 | |
set -e | |
METADIR=".gsync" | |
ARCHIVE=false | |
OLDHEAD="" | |
function init { | |
mkdir $METADIR | |
cd $METADIR | |
git init | |
cd .. | |
} | |
function clone { | |
cd $METADIR | |
# TODO need real value for ssh | |
git remote add origin ../$1/$METADIR | |
git remote update | |
touch manifest | |
git add manifest | |
git commit -m "Empty" | |
OLDHEAD=`git rev-parse HEAD` | |
git merge origin/master | |
cd .. | |
} | |
function index { | |
find . -path ./.gsync -prune -o -print | sort > $METADIR/manifest | |
cd $METADIR | |
git add manifest | |
git commit -m "Auto commit" | |
cd .. | |
} | |
function catchup { | |
cd $METADIR | |
OLDHEAD=`git rev-parse HEAD` | |
git remote update | |
git merge origin/master | |
} | |
function enact { | |
cd $METADIR | |
echo "git diff $OLDHEAD..HEAD | sed '1,5d' | grep ^+" | |
# does this include things we added? no | |
# how do we know what we added, do we need to do ref store before index | |
# then have another list of what to push to server? | |
for FILE in `git diff $OLDHEAD..HEAD | sed '1,5d' | grep ^+`; do | |
echo "fetch $FILE" | |
# scp | |
done | |
for FILE in `git diff $OLDHEAD..HEAD | sed '1,5d' | grep ^-`; do | |
echo "delete $FILE" | |
# rm or mv | |
done | |
cd .. | |
} | |
while getopts 'hva' OPTION | |
do | |
case $OPTION in | |
h) | |
print_usage "`basename $0`" | |
exit 1 | |
;; | |
v) | |
VERBOSE="-v" | |
;; | |
a) | |
ARCHIVE=true | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
case "$1" in | |
init) | |
init | |
;; | |
clone) | |
init | |
clone $2 | |
enact | |
;; | |
index) | |
# internal command | |
index | |
;; | |
sync) | |
if [ ! -d "$METADIR" ]; then | |
echo "not a thing" | |
exit 1 | |
fi; | |
catchup | |
enact | |
;; | |
*) | |
echo "help" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simplify: allow only one remote
format to supply remote?
save in file? (gitignore it or move repo subdir)
from .gsync have: repo, config, archive dirs. simple
git config --add receive.denyCurrentBranch refuse
server will index nighly
also add remote sync command to this script
should be used for all data on mesing?
use tags raather than passing refs around? (less state in process)
rsync daemon?
must index before sync?
examples of cases of move, delete local, remote etc..
can we always put all heads back where we found them when we exit badly?
no once we index locally and push our changes to master it should delete files in
cron. perhaps master should archive?
seperate:
cron jobs could also download artwork etc
metadata on each album (release date etc)