Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packaging/linux/deb/debroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
)

const (
DebHelperCompat = "11"
// DebHelperCompat is the debhelper compatibility level used for all deb
// targets. It is bounded by the debhelper version of the oldest supported
// target, Ubuntu 20.04 (focal), which ships debhelper 12.10.
DebHelperCompat = "12"
StandardsVersion = "4.7.4"
customSystemdPostinstFile = "custom_systemd_postinst.sh.partial"
BinariesPath = "/usr/bin"
Expand Down
2 changes: 1 addition & 1 deletion packaging/linux/deb/debroot_package_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestDebrootPackageFiles(t *testing.T) {
assert.Assert(t, mkfile != nil, "expected Debian rules to be generated")

content := string(mkfile.Data)
assert.Equal(t, strings.Count(content, "override_dh_fixperms:"), 1)
assert.Equal(t, strings.Count(content, "execute_after_dh_fixperms:"), 1)
assert.Equal(t, strings.Count(content, "override_dh_installsystemd:"), 1)
})
}
10 changes: 5 additions & 5 deletions packaging/linux/deb/debroot_subpackage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ func TestDebrootSubPackageOptArtifact(t *testing.T) {
))
})

t.Run("opt permissions enable the fixperms override", func(t *testing.T) {
t.Run("opt permissions enable the fixperms hook", func(t *testing.T) {
mkfile, err := findMkfile(t, def.ToPB(), filepath.Join("/debian", "rules"))
assert.NilError(t, err)
assert.Assert(t, mkfile != nil, "expected rules to be generated")
assert.Assert(t, cmp.Contains(string(mkfile.Data), "override_dh_fixperms"))
assert.Assert(t, cmp.Contains(string(mkfile.Data), "execute_after_dh_fixperms"))
})

t.Run("ownership and capabilities are applied by the supplemental package postinst", func(t *testing.T) {
Expand Down Expand Up @@ -710,11 +710,11 @@ func TestDebrootSubPackageRulesOverridePerms(t *testing.T) {
assert.Assert(t, mkfile != nil)

content := string(mkfile.Data)
assert.Assert(t, cmp.Contains(content, "override_dh_fixperms"))
assert.Assert(t, cmp.Contains(content, "execute_after_dh_fixperms"))
assert.Assert(t, cmp.Contains(content, "fix_perms.sh"))
})

t.Run("no perms no override", func(t *testing.T) {
t.Run("no perms no hook", func(t *testing.T) {
ctx := t.Context()
spec := &dalec.Spec{
Name: "example",
Expand Down Expand Up @@ -747,7 +747,7 @@ func TestDebrootSubPackageRulesOverridePerms(t *testing.T) {
assert.Assert(t, mkfile != nil)

content := string(mkfile.Data)
assert.Assert(t, !bytes.Contains(mkfile.Data, []byte("override_dh_fixperms")), "should not contain fixperms override when no custom perms: %s", content)
assert.Assert(t, !bytes.Contains(mkfile.Data, []byte("execute_after_dh_fixperms")), "should not contain fixperms hook when no custom perms: %s", content)
})
}

Expand Down
11 changes: 4 additions & 7 deletions packaging/linux/deb/template_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (w *rulesWrapper) Envs() fmt.Stringer {
return b
}

func (w *rulesWrapper) OverridePerms() fmt.Stringer {
func (w *rulesWrapper) ExecuteAfterFixPerms() fmt.Stringer {
b := &strings.Builder{}

checkPerms := func(cfgs map[string]dalec.ArtifactConfig) bool {
Expand Down Expand Up @@ -117,12 +117,9 @@ func (w *rulesWrapper) OverridePerms() fmt.Stringer {
}

if fixPerms {
// Normally this should be `execute_after_dh_fixperms`, however this doesn't
// work on Ubuntu 18.04.
// Instead we need to override dh_fixperms and run it ourselves and then
// our extra script.
b.WriteString("override_dh_fixperms:\n")
b.WriteString("\tdh_fixperms\n")
// Run our script after dh_fixperms so the custom permissions are not
// reset by it.
b.WriteString("execute_after_dh_fixperms:\n")
b.WriteString("\tdebian/dalec/fix_perms.sh\n\n")
}

Expand Down
50 changes: 25 additions & 25 deletions packaging/linux/deb/template_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,106 +234,106 @@ Depends: ${misc:Depends},
}
}

func TestRules_OverridePerms(t *testing.T) {
func TestRules_ExecuteAfterFixPerms(t *testing.T) {
tests := []struct {
name string
artifacts dalec.Artifacts
expected string
}{
{
name: "default permissions emit no override",
name: "default permissions emit no hook",
artifacts: dalec.Artifacts{
Binaries: map[string]dalec.ArtifactConfig{"example": {}},
},
},
{
name: "artifact permissions emit an override",
name: "artifact permissions emit a hook",
artifacts: dalec.Artifacts{
Binaries: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "config file permissions emit an override",
name: "config file permissions emit a hook",
artifacts: dalec.Artifacts{
ConfigFiles: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "manpage permissions emit an override",
name: "manpage permissions emit a hook",
artifacts: dalec.Artifacts{
Manpages: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "header permissions emit an override",
name: "header permissions emit a hook",
artifacts: dalec.Artifacts{
Headers: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "license permissions emit an override",
name: "license permissions emit a hook",
artifacts: dalec.Artifacts{
Licenses: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "documentation permissions emit an override",
name: "documentation permissions emit a hook",
artifacts: dalec.Artifacts{
Docs: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "library permissions emit an override",
name: "library permissions emit a hook",
artifacts: dalec.Artifacts{
Libs: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "libexec permissions emit an override",
name: "libexec permissions emit a hook",
artifacts: dalec.Artifacts{
Libexec: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "data file permissions emit an override",
name: "data file permissions emit a hook",
artifacts: dalec.Artifacts{
DataDirs: map[string]dalec.ArtifactConfig{"example": {Permissions: 0o750}},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "config directory permissions emit an override",
name: "config directory permissions emit a hook",
artifacts: dalec.Artifacts{
Directories: &dalec.CreateArtifactDirectories{
Config: map[string]dalec.ArtifactDirConfig{"example": {Mode: 0o750}},
},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
{
name: "state directory permissions emit an override",
name: "state directory permissions emit a hook",
artifacts: dalec.Artifacts{
Directories: &dalec.CreateArtifactDirectories{
State: map[string]dalec.ArtifactDirConfig{"example": {Mode: 0o700}},
},
},
expected: "override_dh_fixperms:\n\tdh_fixperms\n\tdebian/dalec/fix_perms.sh\n\n",
expected: "execute_after_dh_fixperms:\n\tdebian/dalec/fix_perms.sh\n\n",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
w := newRulesWrapper(test.artifacts)

actual := w.OverridePerms().String()
actual := w.ExecuteAfterFixPerms().String()

assert.Equal(t, actual, test.expected)
})
Expand Down
2 changes: 1 addition & 1 deletion packaging/linux/deb/templates/debian_rules.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ override_dh_auto_configure: fix_generators
override_dh_dwz:
@# https://salsa.debian.org/go-team/packages/dh-golang/-/commit/831f3a9dccc14f63f21d3dfac0c0d0e0c25b4084

{{ .OverridePerms }}
{{ .ExecuteAfterFixPerms }}

{{ .OverrideSystemd }}

Expand Down
4 changes: 4 additions & 0 deletions website/content/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ build:
echo " dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info" >> debian/rules
```

Dalec uses debhelper compatibility level 12, so besides `override_dh_<command>` targets you can also add
`execute_before_dh_<command>` and `execute_after_dh_<command>` hook targets, which run extra commands before or
after a debhelper command instead of replacing it.

Note that at the point your build steps are run some of the rules have already been applied.
This is considered a "break glass" way to work around issues when building on Debian-based distributions.
Overriding some rules, such as `dh_install`, will also interfere with dalec functionality.
Expand Down
Loading