Skip to content

Instantly share code, notes, and snippets.

@jeantessier
Last active Jan 30, 2019
Embed
What would you like to do?
This CGI script in Perl can be the target of a GitHub webhook to automatically pull the latest version from the repo.
#!/usr/bin/perl
use Digest::SHA qw(hmac_sha1_hex);
open(KEYFILE, "gitpull.secret");
chomp($secret = <KEYFILE>);
close(KEYFILE);
print "Content-type: text/plain\n";
print "\n";
if (defined $ENV{'CONTENT_LENGTH'}) {
$contents = "";
read (STDIN, $contents, $ENV{'CONTENT_LENGTH'});
$digest = "sha1=" . hmac_sha1_hex($contents, $secret);
if ($digest == $ENV{'HTTP_X_HUB_SIGNATURE'}) {
print "OK\n";
print "\n";
print "git pull\n";
print `git pull`;
} else {
print "No match!\n";
}
} else {
print "No payload!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment