Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add script to push a changed repository to the anonymous mirror, inte…

…nded

to be run from cron.
  • Loading branch information...
commit e2fc58f4619aa8d98bcb2fe8cdf9bd3664da6713 1 parent 12fdaab
@mhagander authored
Showing with 69 additions and 0 deletions.
  1. +24 −0 README.rst
  2. +45 −0 push_to_anon.sh
View
24 README.rst
@@ -133,3 +133,27 @@ for the git user: ::
command="/home/git/gitwrap/gitwrap.py 'Some User'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa ABCDABCD<sshkeyhere>
One row for each committer.
+
+
+anonymous mirror push script
+============================
+This script is set to push the repository (all branches) to the anonymous mirror,
+that is used for example for gitweb access. It's intended to be run from cron frequently
+(at least every 5 minutes, but every minute is even better..).
+
+The script has a simple lockfile based interlock to make sure it doesn't step on other
+instances of itself. It's probably a good idea to monitor this for stale lock files.
+
+The repository should be set up with a remote called "anonymous". This will be the
+target of the pushes.
+
+The user running the script must have an ssh private key set up with no passphrase to
+use for pushing.
+
+To run the script, simply set up a cronjob that runs: ::
+
+ /some/where/push_to_anon.sh /home/git/postgresql.git
+
+The script can be run with the ``--force`` parameter to have it send data even if it
+doesn't seem necessary. It might be a good idea to have an infrequent cronjob that
+does this.
View
45 push_to_anon.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+#
+# This script is used to push changes from gitmaster to the anonymous
+# mirror. It's designed to be run (very frequently) from cron, and will
+# run as soon as there are any refs that are newer than the last pull.
+#
+#
+# Copyright (C) 2010 PostgreSQL Global Development Group
+# Author: Magnus Hagander <magnus@hagander.net>
+#
+# Released under the PostgreSQL license
+#
+#
+#
+# Can be run with --force to push even if nothing appears to have
+# changed.
+#
+# The git repository should have a remote called "anonymous" configured.
+# All branches will be pushed.
+#
+
+if [ "$1" == "" ]; then
+ echo "Usage: push_to_anon.sh <path to git repository> [--force]"
+ exit 1
+fi
+
+set -e
+
+cd $1
+M=$(find refs -type f -newer last_anonymous_push | grep -v refs/remotes/ | wc -l)
+if [ $M -gt 0 -o "$2" == "--force" ]; then
+ # Perform push in interlock
+ if [ ! -e /tmp/.git_repo_push.lck ]; then
+ trap "rm -f /tmp/.git_repo_push.lck" INT TERM EXIT
+ touch /tmp/.git_repo_push.lck
+ touch last_anonymous_push
+ git push -q anonymous --all
+ git push -q anonymous --tags
+ rm -f /tmp/.git_repo_push.lck
+ trap - INT TERM EXIT
+ else
+ echo Push script already running.
+ fi
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.