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> |
21 |
# Based on an sh version by Lars Wirzenius. |
22 |
|
23 |
use strict; |
24 |
use warnings; |
25 |
|
26 |
use Getopt::Long; |
27 |
use POSIX qw/strftime/; |
28 |
|
29 |
my $buildresult; |
30 |
my $distribution='squeeze-dev'; |
31 |
my $git_checks='all'; |
32 |
my $version='3.3-1~git'; |
33 |
my $auto_version=1; |
34 |
my $need_help; |
35 |
my $debug; |
36 |
|
37 |
GetOptions( |
38 |
'buildresult|r=s' => \$buildresult, |
39 |
'distribution|D=s' => \$distribution, |
40 |
'git-checks|g=s' => \$git_checks, |
41 |
'version|v=s' => \$version, |
42 |
'autoversion!' => \$auto_version, |
43 |
'help|h' => \$need_help, |
44 |
'debug|d' => \$debug, |
45 |
); |
46 |
|
47 |
help_and_exit() if $need_help; |
48 |
|
9 |
|
49 |
|
10 |
set -e |
50 |
sub sys_command_output { |
|
|
51 |
my ($command) = @_; |
11 |
|
52 |
|
12 |
die() |
53 |
print "$command\n" if $debug; |
13 |
{ |
54 |
open COMMAND, "$command |" |
14 |
echo "$@" |
55 |
or die qq{Cannot execute "$command": $!"}; |
15 |
exit 1 |
56 |
return map { chomp; $_ } <COMMAND>; |
16 |
} |
57 |
} |
17 |
|
58 |
|
18 |
everything_is_commited() |
59 |
sub everything_is_committed { |
19 |
{ |
60 |
my $filter; |
20 |
if git status --short | grep -q '^' |
61 |
for ($git_checks) { |
21 |
then |
62 |
$_ eq "none" |
22 |
return 1 |
63 |
and return 1; |
23 |
else |
64 |
|
24 |
return 0 |
65 |
$_ eq "modified" |
25 |
fi |
66 |
and $filter = "no", |
|
|
67 |
last; |
68 |
|
69 |
$_ eq "all" |
70 |
and $filter = "normal", |
71 |
last; |
72 |
|
73 |
help_and_exit("$0: --git-checks/-g must be one of 'all', 'modified', or 'none'"); |
74 |
} |
75 |
my $has_changes = grep /^xxx/, sys_command_output("git status --porcelain -u${filter}"); |
76 |
|
77 |
return !$has_changes; |
26 |
} |
78 |
} |
27 |
|
79 |
|
28 |
latest_sha1() { |
80 |
sub help_and_exit { |
29 |
git rev-parse --short=8 HEAD |
81 |
my $msg = shift; |
|
|
82 |
if ($msg) { |
83 |
print "$msg\n\n"; |
84 |
} |
85 |
print <<EOH; |
86 |
This builds Koha deb packages, from a git snapshot. It's not suitable for |
87 |
making upstreamable verions, but handy for your own local packages. |
88 |
|
89 |
Options: |
90 |
--buildresult, -r |
91 |
the location that the resulting .deb, .changes, etc. will be placed in. |
92 |
Default is whatever pdebuild uses. |
93 |
--distribution, -D |
94 |
the distribution value to set in the changelog when editing it. Default |
95 |
is 'squeeze-dev'. |
96 |
--git-checks, -g |
97 |
what level of git checks are run to determine if the working copy is |
98 |
clean enough. One of 'all' (any changes are bad), 'modified' (only |
99 |
tracked files with untracked changes will cause an error), and 'none' |
100 |
(checking git status is skipped totally.) Default is 'all'. |
101 |
--version, -v |
102 |
the version string for the resulting package. Default is '3.3-1~git'. |
103 |
--(no)autoversion |
104 |
whether or not to use the date and git commit ID in the version value. |
105 |
Default is to include it. |
106 |
--debug, -d |
107 |
EOH |
108 |
exit; |
30 |
} |
109 |
} |
31 |
|
110 |
|
32 |
newversion() { |
111 |
sub latest_sha1 { |
33 |
printf '3.5-1~git%s.%s' $(date +%Y%m%d%H%M%S) $(latest_sha1) |
112 |
return sys_command_output("git rev-parse --short=8 HEAD"); |
34 |
} |
113 |
} |
35 |
|
114 |
|
36 |
adjust_debian_changelog() { |
115 |
sub adjust_debian_changelog { |
37 |
dch --force-distribution -D squeeze-dev -v "$1" \ |
116 |
my ($newversion) = @_; |
38 |
"Building git snapshot." |
117 |
|
39 |
dch -r "Building git snapshot." |
118 |
sys_command_output( qq{dch --force-distribution -D "$distribution" -v "$newversion" "Building git snapshot."} ); |
|
|
119 |
sys_command_output( qq{dch -r "Building git snapshot."} ); |
40 |
} |
120 |
} |
41 |
|
121 |
|
42 |
reset_debian_changelog() { |
122 |
sub reset_debian_changelog { |
43 |
git checkout -- debian/changelog |
123 |
sys_command_output( qq{git checkout -- debian/changelog} ); |
44 |
} |
124 |
} |
45 |
|
125 |
|
46 |
build_package() { |
126 |
sub build_package { |
47 |
git archive --format=tar --prefix="koha-$1/" HEAD | |
127 |
my ($newversion) = @_; |
48 |
gzip -9 > "../koha_$1.tar.gz" |
128 |
sys_command_output( qq{git archive --format=tar --prefix="koha-$newversion/" HEAD | gzip -9 > "../koha_$newversion.tar.gz"} ); |
49 |
pdebuild $2 |
129 |
|
|
|
130 |
my $pdebuildopts = $buildresult ? "--buildresult $buildresult" : ""; |
131 |
sys_command_output( "pdebuild $pdebuildopts" ); |
50 |
} |
132 |
} |
51 |
|
133 |
|
52 |
if ! everything_is_commited |
134 |
everything_is_committed() or die "cannot build: uncommited changes"; |
53 |
then |
135 |
|
54 |
die "cannot build: uncommited changes" |
136 |
my $newversion = $auto_version |
55 |
fi |
137 |
? sprintf ('%s%s.%s', $version, strftime("+%Y%m%d%H%M%S", localtime), latest_sha1()) |
56 |
|
138 |
: $version; |
57 |
version="$(newversion)" |
139 |
|
58 |
if [ -n "$1" ] |
140 |
adjust_debian_changelog( $newversion ); |
59 |
then |
141 |
build_package( $newversion ); |
60 |
pdebuildopts="--buildresult $1" |
142 |
reset_debian_changelog(); |
61 |
fi |
143 |
|
62 |
adjust_debian_changelog "$version" |
|
|
63 |
build_package "$version" "$pdebuildopts" |
64 |
reset_debian_changelog |
65 |
- |
|
|