From e1d4fdfabac294336b65bd6b4422092465e5910d Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 18 Nov 2016 17:05:49 -0500 Subject: [PATCH] cron: Add script to update production web site checkout. --- cron/cron.d/website-update | 1 + cron/scripts/website-update.sh | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 cron/cron.d/website-update create mode 100755 cron/scripts/website-update.sh diff --git a/cron/cron.d/website-update b/cron/cron.d/website-update new file mode 100644 index 00000000..1842cc08 --- /dev/null +++ b/cron/cron.d/website-update @@ -0,0 +1 @@ +*/5 * * * * www $HOME/website/cron/scripts/website-update.sh diff --git a/cron/scripts/website-update.sh b/cron/scripts/website-update.sh new file mode 100755 index 00000000..3387e29c --- /dev/null +++ b/cron/scripts/website-update.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +set -e +set -u + +LOCKDIR="/tmp/website-update.$(id -u)" +SITEDIR=~/website +PRODUCTION_BRANCH=master +DB_FILE=~/Database/conservancy-website.sqlite3 +DB_SCRIPT=~bkuhn/django-supporters-list.sql + +git_rev_name() { + git rev-parse --abbrev-ref --symbolic-full-name "$@" +} + +if ! mkdir "$LOCKDIR"; then + test -d "$LOCKDIR" + exit $? +fi +trap 'rmdir "$LOCKDIR"' 0 INT TERM QUIT + +exitcode=0 +if [ "$DB_SCRIPT" -nt "$DB_FILE" ]; then + sqlite3 "$DB_FILE" <"$DB_SCRIPT" || exitcode=$? +fi + +# If the checkout is not on the production branch, +# assume maintenance is happening and stop. +cd "$SITEDIR" +if [ "$(git_rev_name HEAD)" != "$PRODUCTION_BRANCH" ]; then + exit "$exitcode" +fi + +# Abort if the production branch isn't tracking a remote branch. +if ! git_upstream="$(git_rev_name '@{upstream}' 2>/dev/null)"; then + exit 3 +fi + +IFS=/ read git_remote git_refspec <