--- /dev/null
+#!/usr/bin/perl
+#
+# Script to build Debian packages.
+#
+use strict;
+use warnings;
+use Getopt::Long;
+use File::Temp qw/tempdir/;
+use Cwd;
+
+my $svn = "/usr/bin/svn";
+my $dpkgsource = "/usr/bin/dpkg-source";
+my $cowpoke = "/usr/bin/cowpoke";
+my $rsync = "/usr/bin/rsync";
+my $debsign = "/usr/bin/debsign";
+my @debsign_opts = ();
+
+my $buildhost = "wowbagger.internal.michaelhowe.org";
+
+my $arch = 'amd64';
+my $dist = 'squeeze';
+
+my $path = $ARGV[0];
+
+unless( $path ){
+ die "Error - no path specified\n";
+}
+
+my $workingdir = getcwd();
+
+my $exportdir = tempdir( CLEANUP => 1 );
+
+my @exportcmd = ( $svn, 'export', $path, "$exportdir/export" );
+print "Running '@exportcmd'\n";
+system( @exportcmd ) == 0
+ or die "Could not run svn export: $!";
+
+chdir( $exportdir )
+ or die "Can't chdir to $exportdir: $!";
+
+my @sourcecmd = ( $dpkgsource, "-b", "$exportdir/export" );
+
+system( @sourcecmd ) ==0
+ or die "Could not run dpkg-source: $!";
+
+print "Built in $exportdir\n";
+
+chdir( $workingdir );
+
+my ( $dscfile ) = glob( "$exportdir/*.dsc" );
+my $remote_uploaddir = "cowbuilder-incoming/$$";
+warn "Statically defined /home/michael!";
+my $remote_outputdir = "/home/michael/cowbuilder-outgoing/$$"; # FIXME
+
+$ENV{INCOMING_DIR} = $remote_uploaddir;
+my $resdirname = "${arch}_${dist}_RESULT_DIR";
+
+$ENV{$resdirname} = "$remote_outputdir";
+my @cowpokecmd = ( $cowpoke, "--arch=$arch", "--dist=$dist", $dscfile );
+print "Running @cowpokecmd";
+system( @cowpokecmd ) == 0
+ or die "Could not run cowpoke: $!";
+
+my $local_outputdir = tempdir( DIR => $workingdir );
+
+my @rsynccmd = ( $rsync, "-az", "$buildhost:$remote_outputdir/", "$local_outputdir/" );
+print "Running @rsynccmd\n";
+system( @rsynccmd ) == 0
+ or die "Could not run rsync: $!";
+
+# Clean up remote side:
+# Note that this currently won't work
+#my @sshcleanupcmd = ( $ssh, "rm", "-rf", $remote_outputdir );
+
+my @changefiles = glob( "$local_outputdir/*.changes" );
+
+foreach my $changefile ( @changefiles ){
+ my @debsigncmd = ( $debsign, @debsign_opts, $changefile );
+ system( @debsigncmd ) == 0
+ or warn "Could not sign changes file $changefile: $!";
+}