Skip to content

Instantly share code, notes, and snippets.

@mattrude
Created February 2, 2019 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrude/216df85bb6fc2d1cf76b71d047ec9d72 to your computer and use it in GitHub Desktop.
Save mattrude/216df85bb6fc2d1cf76b71d047ec9d72 to your computer and use it in GitHub Desktop.
A simple script to update my local version of my git mirrors.
#!/bin/bash
if [ "${SHELL}" != "/bin/bash" ]; then int="0"; else int="1"; fi
if [ "${int}" == "0" ]; then
sleep $(expr $RANDOM \% 900)
mkdir -p /var/lib/git
touch /var/lib/git/update-mirrors.log
exec 3>&1 4>&2; trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>/var/lib/git/update-mirrors.log 2>&1
fi
echo ""
echo ""
echo "############################################################################"
echo ""
date
echo ""
cd /var/lib/git/
for DIR in `ls -d */ |grep -v '.git/$'`
do
cd /var/lib/git/${DIR}
for MIR in `ls -d *.git/`
do
cd /var/lib/git/${DIR}${MIR}
if [ "`grep 'url' config |grep git`" != "" ]; then
echo -n "Updating "
pwd
git remote update
DATE="`git log --date=local |head -6 |grep Date |sed 's/Date: //g'`"
DATE2="`date -d\"${DATE}\" +%Y%m%d%H%M.%S`"
touch -a -m -t ${DATE2} packed-refs
for FILE in `find refs/heads/ -maxdepth 1 -type f`
do
touch -a -m -t ${DATE2} ${FILE}
done
fi
done
done
cd /var/lib/git/
for DIR in `ls -d *.git/`
do
cd /var/lib/git/${DIR}
if [ "`grep 'url' config |grep git`" != "" ]; then
echo -n "Updating "
pwd
git remote update
DATE="`git log --date=local |head -6 |grep Date |sed 's/Date: //g'`"
DATE2="`date -d\"${DATE}\" +%Y%m%d%H%M.%S`"
touch -a -m -t ${DATE2} packed-refs
for FILE in `find refs/heads/ -maxdepth 1 -type f`
do
touch -a -m -t ${DATE2} ${FILE}
done
fi
done
rm -rf /var/cache/cgit/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment