Created
January 20, 2017 17:50
-
-
Save achilleas-k/8383811a1f9b69ba8ccdaf8f32916089 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
set -e | |
gitconfig=( | |
"user.name annextester" | |
"user.email [email protected]" | |
"annex.addunlocked true" | |
"annex.largefiles largerthan=10M" | |
"annex.backends WORM" | |
"annex.thin true" | |
) | |
annexver="6" | |
printstatus() { | |
echo "------------------------------" | |
echo "Current status after $1" | |
echo "------------------------------" | |
nfiles=$(ls | wc -l) | |
echo -e "\nFile types" | |
if [ "$nfiles" -gt "0" ] | |
then | |
file * | |
else | |
echo "No files yet" | |
fi | |
echo -e "\nFile sizes" | |
if [ "$nfiles" -gt "0" ] | |
then | |
du -hd0 * .git/* | |
else | |
du -hd0 .git/* | |
fi | |
echo -e "\nLast recorded sizes" | |
if [ -f *_sizes.txt ] | |
then | |
cat *_sizes.txt | |
else | |
echo "Not recorded yet" | |
fi | |
echo -e "\nHashes" | |
if [ "$nfiles" -gt "0" ] | |
then | |
md5sum randfile* | |
else | |
echo "No files yet" | |
fi | |
echo -e "\nLast recorded hashes" | |
if [ -f *.md5 ] | |
then | |
cat *.md5 | |
echo "Checking" | |
md5sum -c *.md5 || echo "HASHES CHANGED" | |
else | |
echo "Not recorded yet" | |
fi | |
if [ "$nfiles" -gt "0" ] | |
then | |
echo -e "\nChecking for hard links" | |
for rf in randfile_* | |
do | |
echo "${rf} ->" | |
find .git -samefile $rf | |
done | |
fi | |
echo | |
read -p "Press enter to continue" | |
echo "--------------------------" | |
} | |
# create repo on gin | |
reponame=annextest-${RANDOM} | |
gin keys # should have non-temporary key | |
echo "Creating repository ${reponame} on GIN" | |
gin create ${reponame} | |
# clone it | |
git clone [email protected]:achilleas/${reponame} && cd ${reponame} | |
printstatus "Clone" | |
echo "Setting git config options" | |
for conf in "${gitconfig[@]}" | |
do | |
echo ${conf} | |
git config ${conf} | |
done | |
echo "Initialising annex with version ${annexver}" | |
git annex init --version=${annexver} | |
# create files | |
echo "Generating test files using /dev/urandom" | |
dd if=/dev/urandom of=randfile_1 bs=1M count=15 | |
dd if=/dev/urandom of=randfile_2 bs=1M count=30 | |
dd if=/dev/urandom of=randfile_3 bs=1M count=32 | |
printstatus "File creation" | |
# create md5sums and check them into git | |
echo "Calculating md5 sums for tracking file state manually" | |
md5sum randfile* > ${reponame}.md5 | |
git add ${reponame}.md5 | |
git commit -m "File hashes" | |
printstatus "Hash calculation" | |
# annex large files and push thewm | |
echo "Doing git annex add ." | |
git annex add . | |
# echo "Commit" | |
# git commit -a -m "Data files" | |
printstatus "git annex add" | |
echo "Running sync" | |
git annex sync --content &> /dev/null | |
printstatus "git annex sync" | |
# compute sizes | |
echo "Computing sizes" | |
du -hd0 * .git/* > ${reponame}_sizes.txt | |
printstatus "size calculation" | |
echo "Adding size file to git" | |
git add ${reponame}_sizes.txt | |
git commit -m "Sizes" | |
git push | |
printstatus "git add sizes, commit, push" | |
# tag current commit to test reverting | |
tagname="InitData" | |
echo "Tagging current commit as ${tagname}" | |
git tag "${tagname}" | |
git push --tags | |
# change files | |
echo "Appending data to file 1" | |
dd if=/dev/urandom of=randfile_1 bs=1M count=1 conv=notrunc oflag=append | |
printstatus "data append" | |
echo "Truncating file 3" | |
dd if=/dev/urandom of=randfile_3 bs=1M count=11 | |
printstatus "data replace" | |
# recompute hashes | |
echo "Calculating new md5 sums" | |
md5sum randfile* > ${reponame}.md5 | |
git add ${reponame}.md5 | |
git commit -m "File hashes" | |
printstatus "Hash calculation" | |
# update git and annex | |
echo "Doing git annex add ." | |
git annex add . | |
printstatus "git annex add" | |
echo "Running sync" | |
git annex sync --content &> /dev/null | |
printstatus "git annex sync" | |
# recompute sizes | |
echo "Computing sizes" | |
du -hd0 * .git/* > ${reponame}_sizes.txt | |
printstatus "size calculation" | |
echo "Adding size file to git" | |
git add ${reponame}_sizes.txt | |
git commit -m "Sizes" | |
git push | |
printstatus "git add sizes, commit, push" | |
# revert to previous version | |
echo "Checking out tagged commit" | |
git checkout "${tagname}" | |
printstatus "git checkout tag" | |
# check sizes and hashes | |
echo "FINISHED WITH TEST REPOSITORY ${reponame}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment