Skip to content

Commit 676ac4d

Browse files
author
qount25
committed
Generating debian files used when building a deb package with pbuilder
1 parent 0a1c5f2 commit 676ac4d

File tree

7 files changed

+137
-15
lines changed

7 files changed

+137
-15
lines changed

lib/pgpm/deb/builder.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def initialize(spec)
1313
def build
1414
puts "build()"
1515
prepare
16-
#generate_deb_src_files
17-
create_container
16+
generate_deb_src_files
17+
#create_container
1818
#run_pbuilder
1919
#copy_build_from_container
2020
#cleanup
@@ -54,11 +54,13 @@ def create_container
5454
end
5555

5656
def generate_deb_src_files
57-
@spec.generate_rules
58-
@spec.generate_control
59-
@spec.generate_licence
60-
@spec.generate_version
61-
# save generated content into actual files
57+
puts "Generating debian files..."
58+
Dir.mkdir "#{@pgpm_dir}/debian"
59+
[:changelog, :control, :copyright, :files, :rules].each do |f|
60+
puts " -> #{@pgpm_dir}/debian/#{f}"
61+
File.write "#{@pgpm_dir}/debian/#{f}", @spec.generate(f)
62+
end
63+
File.chmod 0740, "#{@pgpm_dir}/debian/rules" # rules file must be executable
6264
end
6365

6466
def run_pbuilder

lib/pgpm/deb/spec.rb

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "digest"
44
require "open-uri"
5+
require "erb"
56

67
module Pgpm
78
module Deb
@@ -19,23 +20,54 @@ def sources
1920
@package.sources
2021
end
2122

22-
def generate_control
23+
def generate(template_name)
24+
fn = "#{__dir__}/templates/#{template_name}.erb"
25+
raise "No such template: #{fn}" unless File.exist?(fn)
26+
erb = ERB.new(File.read(fn))
27+
erb.result(binding)
2328
end
2429

25-
def generate_rules
30+
def deps
31+
["postgresql-#{postgres_version}"]
2632
end
2733

28-
def generate_licence
34+
def build_deps
35+
[
36+
"postgresql-#{postgres_version}",
37+
"build-essential",
38+
"postgresql-#{postgres_version}",
39+
"postgresql-server-dev-#{postgres_version}",
40+
"postgresql-common"
41+
]
2942
end
3043

31-
def generate_version
44+
def postgres_version
45+
17
3246
end
3347

34-
private
48+
def source_version
49+
@package.version.to_s
50+
end
51+
52+
def source_name
53+
@package.name
54+
end
55+
56+
def deb_version
57+
"0.1.0"
58+
end
59+
60+
def arch
61+
"amd64"
62+
end
63+
64+
def description
65+
@package.description
66+
end
3567

36-
def unpack?(src)
37-
src = src.name if src.respond_to?(:name)
38-
src.to_s.end_with?(".tar.gz") || src.to_s.end_with?(".tar.xz")
68+
# Whatever is returned from this method gets added to the "rules" file.
69+
def rules_amendments
70+
"#"
3971
end
4072

4173
end

lib/pgpm/deb/templates/changelog.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= source_name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium
2+
3+
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
4+
5+
-- PGPM Debian maintainer <debian[email protected]> Fri, 21 Feb 2025 21:08:08 +0000

lib/pgpm/deb/templates/control.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Source: <%= source_name %>-<%= source_version %>
2+
Section: libs
3+
Priority: optional
4+
Maintainer: PGPM Debian maintainer <debian[email protected]>
5+
Rules-Requires-Root: no
6+
Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %>
7+
Standards-Version: 4.6.2
8+
9+
Package: <%= source_name %>-<%= deb_version %>
10+
Depends: <%= deps.join(", ") %>
11+
Section: libdevel
12+
Architecture: <%= arch %>
13+
Description: <%= description %>

lib/pgpm/deb/templates/copyright.erb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Source: <url://example.com>
3+
Upstream-Name: <%= source_name %>-<%= source_version %>
4+
Upstream-Contact: <preferred name and address to reach the upstream project>
5+
6+
Files:
7+
*
8+
Copyright:
9+
<years> <put author's name and email here>
10+
<years> <likewise for another author>
11+
License: <special license>
12+
<Put the license of the package here indented by 1 space>
13+
<This follows the format of Description: lines in control file>
14+
.
15+
<Including paragraphs>
16+
17+
# If you want to use GPL v2 or later for the /debian/* files use
18+
# the following clauses, or change it to suit. Delete these two lines
19+
Files:
20+
debian/*
21+
Copyright:
22+
2025 PGPM Debian maintainer <debian[email protected]>
23+
License: GPL-2+
24+
This package is free software; you can redistribute it and/or modify
25+
it under the terms of the GNU General Public License as published by
26+
the Free Software Foundation; either version 2 of the License, or
27+
(at your option) any later version.
28+
.
29+
This package is distributed in the hope that it will be useful,
30+
but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+
GNU General Public License for more details.
33+
.
34+
You should have received a copy of the GNU General Public License
35+
along with this program. If not, see <https://www.gnu.org/licenses/>
36+
Comment:
37+
On Debian systems, the complete text of the GNU General
38+
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
39+
40+
# Please also look if there are files or directories which have a
41+
# different copyright/license attached and list them here.
42+
# Please avoid picking licenses with terms that are more restrictive than the
43+
# packaged work, as it may make Debian's contributions unacceptable upstream.
44+
#
45+
# If you need, there are some extra license texts available in two places:
46+
# /usr/share/debhelper/dh_make/licenses/
47+
# /usr/share/common-licenses/
48+

lib/pgpm/deb/templates/files.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= source_name %>-<%= source_version %>_0-1_source.buildinfo libs optional

lib/pgpm/deb/templates/rules.erb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/make -f
2+
3+
# See debhelper(7) (uncomment to enable).
4+
# Output every command that modifies files on the build system.
5+
#export DH_VERBOSE = 1
6+
7+
8+
# See FEATURE AREAS in dpkg-buildflags(1).
9+
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
10+
11+
# See ENVIRONMENT in dpkg-buildflags(1).
12+
# Package maintainers to append CFLAGS.
13+
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
14+
# Package maintainers to append LDFLAGS.
15+
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
16+
17+
18+
%:
19+
dh $@
20+
21+
<%= self.rules_amendments %>

0 commit comments

Comments
 (0)