-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdate-hook-cgibin.pl
More file actions
executable file
·34 lines (25 loc) · 990 Bytes
/
update-hook-cgibin.pl
File metadata and controls
executable file
·34 lines (25 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl
use warnings;
use strict;
# Read the first few bytes of HTTP POST data (if present), to crudely check
# whether the received event pertains to the gh-pages branch.
read STDIN, my $payload, 256;
print "Content-Type: text/plain\015\012Content-Length: 4\015\012\015\012ok\015\012";
chdir "/var/www/www.luga.de/htdocs" or exit;
exit unless defined $payload and $payload =~ /gh-pages/;
exit unless -M ".git" > 30/86400;
# Only update once in thirty seconds.
my $pid = fork();
exit if not defined $pid; # fork() didn't work
exit if $pid; # this is the parent
# Sanitize environment (in fear of Shellshock related issues)
%ENV = ();
exec "bash", "-c", <<'EOF';
{
git reset --hard origin/gh-pages
git fetch
git diff gh-pages origin/gh-pages
git merge origin/gh-pages
} 2>&1 | head -n 10000 | mail -s "luga push-hook triggered $(date +'%Y-%m-%d %H:%M')" joerg@luga.de
EOF
# The "head -n 10000" part truncates excessively long diffs to 10000 lines.