From 76af1279d9a4ab574d87e93466166b7b210c2bad Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 7 Oct 2013 01:53:18 +0200 Subject: Move test site hooks into separate file Put the code for creating the test instance into a separate hook file in order to make the other files less convoluted. diff --git a/libexec/post-receive.d/01-git-export b/libexec/post-receive.d/01-git-export index 171f05f..37994e2 100755 --- a/libexec/post-receive.d/01-git-export +++ b/libexec/post-receive.d/01-git-export @@ -19,26 +19,4 @@ export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' prefix='/home/plugins' -# -# Check whether the "test" branch of the "site.git" repository has been updated. -# -if [ "${PWD##*/}" = 'site.git' ] -then - forty_zeros=$(printf '%.40d' '0') - - while read old new ref - do - if [ "$ref" = 'refs/heads/test' ] - then - if [ "$new" != "$forty_zeros" ] - then - "$prefix/bin/git-export" -b 'test' "$PWD" - else - rm -rf "$prefix/exported/site-test" - fi - break - fi - done -fi - exec "$prefix/bin/git-export" "$PWD" diff --git a/libexec/post-receive.d/04-build-web-site b/libexec/post-receive.d/04-build-web-site index 6338968..7c178cf 100755 --- a/libexec/post-receive.d/04-build-web-site +++ b/libexec/post-receive.d/04-build-web-site @@ -19,37 +19,17 @@ export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' prefix='/home/plugins' repository=${PWD##*/} -plugins_repository='nagios-plugins.git' -web_repository='site.git' -prod_branch='master' -test_branch='test' -test_directory="$prefix/web/test" +web_repositories='nagios-plugins.git site.git' +web_branch='master' -if [ "$repository" = "$plugins_repository" ] \ - || [ "$repository" = "$web_repository" ] -then - forty_zeros=$(printf '%.40d' '0') - - while read old new ref - do - branch=${ref#refs/heads/} - - if [ "$branch" = "$prod_branch" ] - then - "$prefix/bin/build-web-site" >'/dev/null' - elif [ "$repository" = "$web_repository" ] \ - && [ "$branch" = "$test_branch" ] - then - if [ "$new" != "$forty_zeros" ] - then - "$prefix/bin/build-web-site" -t >'/dev/null' - else - rm -rf "$test_directory"/* - fi - cat >>"$test_directory/robots.txt" <<-'EOF' - User-agent: * - Disallow: / - EOF - fi - done -fi +for web_repository in $web_repositories +do + if [ "$repository" = "$web_repository" ] + then + while read old new ref + do + test "${ref#refs/heads/}" = "$web_branch" \ + && exec "$prefix/bin/build-web-site" >'/dev/null' + done + fi +done diff --git a/libexec/post-receive.d/04-build-web-test b/libexec/post-receive.d/04-build-web-test new file mode 100755 index 0000000..39974a5 --- /dev/null +++ b/libexec/post-receive.d/04-build-web-test @@ -0,0 +1,51 @@ +#!/bin/sh +# +# Copyright (c) 2013 Nagios Plugins Development Team +# +# Originally written by Holger Weiss . +# +# This file is free software; the Nagios Plugins Development Team gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY, to the extent permitted by law; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +set -e +set -u + +export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' + +prefix='/home/plugins' +test_directory="$prefix/web/test" + +# +# Check whether the "test" branch of the "site.git" repository has been updated. +# +if [ "${PWD##*/}" = 'site.git' ] +then + forty_zeros=$(printf '%.40d' '0') + + while read old new ref + do + if [ "$ref" = 'refs/heads/test' ] + then + if [ "$new" != "$forty_zeros" ] + then + "$prefix/bin/git-export" -b 'test' "$PWD" + "$prefix/bin/build-web-site" -t >'/dev/null' + else + rm -rf "$prefix/exported/site-test" + rm -rf "$test_directory"/* + fi + + # Always put a robots.txt into the $test_directory. + cat >>"$test_directory/robots.txt" <<-'EOF' + User-agent: * + Disallow: / + EOF + break + fi + done +fi -- cgit v0.10-9-g596f