Bug 18376 - authority framework creation fails under Plack
[koha.git] / debian / build-git-snapshot
blob1e1505d7d49c6de1a29a4f19a472ed0f4126a07f
1 #!/usr/bin/perl
3 # Copyright 2010 Catalyst IT Ltd.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 # Written by Robin Sheat <robin@catalyst.net.nz> and
21 # Srdjan Jankovic <srdjan@catalyst.net.nz>
22 # Based on an sh version by Lars Wirzenius.
24 use strict;
25 use warnings;
27 use Getopt::Long;
28 use POSIX qw/strftime/;
30 my $basetgz;
31 my $buildresult;
32 my $distribution='squeeze-dev';
33 my $git_checks='all';
34 my $version='16.06~git';
35 my $auto_version=1;
36 my $need_help;
37 my $debug;
39 GetOptions(
40 'basetgz|b=s' => \$basetgz,
41 'buildresult|r=s' => \$buildresult,
42 'distribution|D=s' => \$distribution,
43 'git-checks|g=s' => \$git_checks,
44 'version|v=s' => \$version,
45 'autoversion!' => \$auto_version,
46 'help|h' => \$need_help,
47 'debug|d' => \$debug,
50 help_and_exit() if $need_help;
53 sub sys_command_output {
54 my ($command) = @_;
56 print "$command\n" if $debug;
57 my $command_output;
58 open($command_output, "-|", "$command ")
59 or die qq{Cannot execute "$command": $!"};
60 return map { chomp; $_ } <$command_output>;
63 sub sys_command_output_screen {
64 my ($command) = @_;
66 print "$command\n" if $debug;
67 system($command) == 0 or die "Command '$command' returns an error ($?)\n";
70 sub everything_is_committed {
71 my $filter;
72 for ($git_checks) {
73 $_ eq "none"
74 and return 1;
76 $_ eq "modified"
77 and $filter = "no",
78 last;
80 $_ eq "all"
81 and $filter = "normal",
82 last;
84 help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'");
86 my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}");
88 return !$has_changes;
91 sub help_and_exit {
92 my $msg = shift;
93 if ($msg) {
94 print "$msg\n\n";
96 print <<EOH;
97 This builds Koha deb packages, from a git snapshot. It's not suitable for
98 making upstreamable verions, but handy for your own local packages.
100 Options:
101 --buildresult, -r
102 the location that the resulting .deb, .changes, etc. will be placed in.
103 Default is whatever pdebuild uses.
104 --distribution, -D
105 the distribution value to set in the changelog when editing it. Default
106 is 'squeeze-dev'.
107 --git-checks, -g
108 what level of git checks are run to determine if the working copy is
109 clean enough. One of 'all' (any changes are bad), 'modified' (only
110 tracked files with untracked changes will cause an error), and 'none'
111 (checking git status is skipped totally.) Default is 'all'.
112 --version, -v
113 the version string for the resulting package. Default is '$version'.
114 --(no)autoversion
115 whether or not to use the date and git commit ID in the version value.
116 Default is to include it.
117 --debug, -d
119 exit;
122 sub latest_sha1 {
123 return sys_command_output("git rev-parse --short=8 HEAD");
126 sub adjust_debian_changelog {
127 my ($newversion) = @_;
129 sys_command_output( qq{dch --force-distribution -D "$distribution" -v "$newversion" "Building git snapshot."} );
130 sys_command_output( qq{dch -r "Building git snapshot."} );
133 sub reset_debian_changelog {
134 sys_command_output( qq{git checkout -- debian/changelog} );
137 sub build_package {
138 my ($newversion) = @_;
139 sys_command_output( qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.tar.gz"} );
141 my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : "";
142 my $pdebuildbasetgz = $basetgz ? "-- --basetgz /var/cache/pbuilder/" . $basetgz . ".tgz" : "";
143 sys_command_output_screen( "pdebuild $pdebuildbasetgz $pdebuildopts" );
146 everything_is_committed() or die "cannot build: uncommited changes";
148 my $newversion = $auto_version
149 ? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1())
150 : $version;
152 adjust_debian_changelog( $newversion );
153 build_package( $newversion );
154 reset_debian_changelog();