Created
September 21, 2012 22:33
-
-
Save MrJoy/3764313 to your computer and use it in GitHub Desktop.
Insane compression for consecutive snapshots of things...
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 | |
DIR=$1 | |
DIR=${DIR%/} | |
if [ -d "$DIR" ]; then | |
pushd "$DIR" > /dev/null 2>&1 | |
ls *.yml | sort -n > infiles.txt | |
cat infiles.txt | while read FNAME; do | |
BASIS=$(grep -E -B 1 "^$FNAME\$" infiles.txt | grep -v $FNAME) | |
if [ "$BASIS" != "" ]; then | |
echo "Creating diff between $BASIS and $FNAME..." | |
bsdiff $BASIS $FNAME ${BASIS%.yml}_${FNAME%.yml}.bspatch | |
else | |
export STARTING_POINT=$FNAME | |
fi | |
done | |
INITIAL_FILE=$(head -1 infiles.txt) | |
rm infiles.txt | |
popd > /dev/null 2>&1 | |
if [ $(($(ls "$DIR"/*.bspatch 2>/dev/null | wc -l) + 0)) -gt 0 ]; then | |
tar cjf "${DIR}.tar.bz2" "$DIR/$INITIAL_FILE" "$DIR"/*.bspatch && rm -f "$DIR"/*.bspatch | |
else | |
tar cjf "${DIR}.tar.bz2" "$DIR/$INITIAL_FILE" | |
fi | |
else | |
echo "Must specify a directory." | |
exit 1 | |
fi |
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 | |
PACKAGE="$1" | |
if [ ! -e "$PACKAGE" ]; then | |
echo "Must specify a package." | |
exit 1 | |
fi | |
tar xjf "$PACKAGE" | |
( | |
cd "${PACKAGE%.tar.bz2}" | |
while [ 1 ]; do | |
BASIS=$(ls *.yml | sort -n | tail -1 2>/dev/null) | |
if [ ! -e "$BASIS" ]; then | |
echo "Couldn't find a YML file to work from." | |
exit 1 | |
fi | |
DIFF=$(ls ${BASIS%.yml}_*.bspatch 2> /dev/null) | |
SUFFIX=${DIFF#${BASIS%.yml}_} | |
TARGET=${SUFFIX%.bspatch}.yml | |
if [ -e "$DIFF" ]; then | |
echo "Rebuilding $TARGET via $BASIS and $DIFF..." | |
bspatch $BASIS $TARGET $DIFF && rm $DIFF | |
else | |
echo "Looks like we're done here." | |
exit 0 | |
fi | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment