View | Details | Raw Unified | Return to bug 5602
Collapse All | Expand All

(-)a/debian/README.build (+13 lines)
Line 0 Link Here
1
In order to build .deb packages, following debian packages need to be present
2
(installed): 
3
devscripts
4
pbuilder
5
dh-make
6
fakeroot
7
8
As root (or sudo) execute:
9
pbuilder create
10
11
Executing build-git-snapshot without any arguments will leave package and the
12
rest in some pbuilder dir, eg. /var/cache/pbuilder/result It is highly
13
recommended that --buildresult option is used.
(-)a/debian/build-git-snapshot (-47 / +134 lines)
Lines 1-64 Link Here
1
#!/bin/sh
1
#!/usr/bin/perl 
2
3
# Copyright 2010 Catalyst IT Ltd.
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
2
#
11
#
3
# This script will build a .deb from a git snapshot of koha.
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
4
# Don't use it for building actual versions for uploading to Debian.
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
5
#
15
#
6
# To use:
16
# You should have received a copy of the GNU General Public License along
7
# - commit any changes into git
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
8
# - run this script
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
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.
23
24
use strict;
25
use warnings;
26
27
use Getopt::Long;
28
use POSIX qw/strftime/;
9
29
10
set -e
30
my $buildresult;
31
my $distribution='squeeze-dev';
32
my $git_checks='all';
33
my $version='3.5-1~git';
34
my $auto_version=1;
35
my $need_help;
36
my $debug;
11
37
12
die()
38
GetOptions(
13
{
39
    'buildresult|r=s'   => \$buildresult,
14
    echo "$@"
40
    'distribution|D=s'  => \$distribution,
15
    exit 1
41
    'git-checks|g=s'    => \$git_checks,
42
    'version|v=s'       => \$version,
43
    'autoversion!'      => \$auto_version,
44
    'help|h'            => \$need_help,
45
    'debug|d'           => \$debug,
46
);
47
48
help_and_exit() if $need_help;
49
50
51
sub sys_command_output {
52
    my ($command) = @_;
53
54
    print "$command\n" if $debug;
55
    my $command_output;
56
    open($command_output, "-|", "$command ")
57
      or die qq{Cannot execute "$command": $!"};
58
    return map { chomp; $_ } <$command_output>;
16
}
59
}
17
60
18
everything_is_commited()
61
sub sys_command_output_screen {
19
{
62
    my ($command) = @_;
20
    if git status --short | grep -q '^'
63
21
    then
64
    print "$command\n" if $debug;
22
        return 1
65
    system($command);
23
    else
24
        return 0
25
    fi
26
}
66
}
27
67
28
latest_sha1() {
68
sub everything_is_committed {
29
    git rev-parse --short=8 HEAD
69
    my $filter;
70
    for ($git_checks) {
71
        $_ eq "none"
72
          and return 1;
73
74
        $_ eq "modified"
75
          and $filter = "no",
76
              last;
77
78
        $_ eq "all"
79
          and $filter = "normal",
80
              last;
81
82
	    help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'");
83
    }
84
    my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}");
85
86
    return !$has_changes;
30
}
87
}
31
88
32
newversion() {
89
sub help_and_exit {
33
    printf '3.5-1~git%s.%s' $(date +%Y%m%d%H%M%S) $(latest_sha1)
90
	my $msg = shift;
91
	if ($msg) {
92
    	print "$msg\n\n";
93
    }
94
    print <<EOH;
95
This builds Koha deb packages, from a git snapshot. It's not suitable for
96
making upstreamable verions, but handy for your own local packages.
97
98
Options:
99
    --buildresult, -r
100
        the location that the resulting .deb, .changes, etc. will be placed in.
101
        Default is whatever pdebuild uses.
102
    --distribution, -D
103
        the distribution value to set in the changelog when editing it. Default
104
        is 'squeeze-dev'.
105
    --git-checks, -g
106
        what level of git checks are run to determine if the working copy is
107
        clean enough. One of 'all' (any changes are bad), 'modified' (only
108
        tracked files with untracked changes will cause an error), and 'none'
109
        (checking git status is skipped totally.) Default is 'all'.
110
    --version, -v
111
        the version string for the resulting package. Default is '3.5-1~git'.
112
    --(no)autoversion
113
        whether or not to use the date and git commit ID in the version value.
114
        Default is to include it.
115
    --debug, -d
116
EOH
117
    exit;
34
}
118
}
35
119
36
adjust_debian_changelog() {
120
sub latest_sha1 {
37
    dch --force-distribution -D squeeze-dev -v "$1" \
121
    return sys_command_output("git rev-parse --short=8 HEAD");
38
        "Building git snapshot."
39
    dch -r "Building git snapshot."
40
}
122
}
41
123
42
reset_debian_changelog() {
124
sub adjust_debian_changelog {
43
    git checkout -- debian/changelog
125
    my ($newversion) = @_;
126
127
    sys_command_output( qq{dch --force-distribution -D "$distribution" -v "$newversion" "Building git snapshot."} );
128
    sys_command_output( qq{dch -r "Building git snapshot."} );
44
}
129
}
45
130
46
build_package() {
131
sub reset_debian_changelog {
47
    git archive --format=tar --prefix="koha-$1/" HEAD | 
132
    sys_command_output( qq{git checkout -- debian/changelog} );
48
        gzip -9 > "../koha_$1.tar.gz"
49
    pdebuild $2
50
}
133
}
51
134
52
if ! everything_is_commited
135
sub build_package {
53
then
136
    my ($newversion) = @_;
54
    die "cannot build: uncommited changes"
137
    sys_command_output( qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.tar.gz"} );
55
fi
138
56
139
    my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : "";
57
version="$(newversion)"
140
    sys_command_output_screen( "pdebuild $pdebuildopts" );
58
if [ -n "$1" ]
141
}
59
then
142
60
    pdebuildopts="--buildresult $1"
143
everything_is_committed() or die "cannot build: uncommited changes";
61
fi
144
62
adjust_debian_changelog "$version"
145
my $newversion = $auto_version
63
build_package "$version" "$pdebuildopts"
146
  ? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1())
64
reset_debian_changelog
147
  : $version;
148
149
adjust_debian_changelog( $newversion );
150
build_package( $newversion );
151
reset_debian_changelog();
152
65
- 

Return to bug 5602