Skip to content

Commit

Permalink
feat: Support for deb's config maintenance script (#317)
Browse files Browse the repository at this point in the history
* feat: Support for deb's config maintenance script

With debconf, the config script is responsible for asking any questions
necessary to configure a package [1]. Without this, we're forced to ask
questions in postinst, which is against best practices [2].

This commit adds the possibility to include a config script when using
debconf like so:

```yaml
deb:
  scripts:
    templates: ./my/templates
    config: ./my/config
```

[1] https://manpages.debian.org/jessie/debconf-doc/debconf-devel.7.en.html#THE_CONFIG_SCRIPT
[2] https://manpages.debian.org/jessie/debconf-doc/debconf-devel.7.en.html#THE_POSTINST_SCRIPT

* docs: Add info about deb config maintainer script
  • Loading branch information
joakimkarlsson committed Apr 14, 2021
1 parent 876fed4 commit 7701bb9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ func createControl(instSize int64, md5sums []byte, info *nfpm.Info) (controlTarG
fileName: "templates",
mode: 0o644,
}
specialFiles[info.Overridables.Deb.Scripts.Config] = &fileAndMode{
fileName: "config",
mode: 0o755,
}

for path, destMode := range specialFiles {
if path != "" {
Expand Down
1 change: 1 addition & 0 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ type DebTriggers struct {
type DebScripts struct {
Rules string `yaml:"rules,omitempty"`
Templates string `yaml:"templates,omitempty"`
Config string `yaml:"config,omitempty"`
}

// Scripts contains information about maintainer scripts for packages.
Expand Down
2 changes: 2 additions & 0 deletions testdata/acceptance/rules.deb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ contents:
deb:
scripts:
rules: ./testdata/acceptance/scripts/rules.sh
templates: ./testdata/acceptance/scripts/templates
config: ./testdata/acceptance/scripts/config
4 changes: 4 additions & 0 deletions testdata/acceptance/scripts/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Ok" > /tmp/config-proof

3 changes: 3 additions & 0 deletions testdata/acceptance/scripts/templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Template: templates/acceptance
Type: string
Description: A setting for acceptance tests
2 changes: 2 additions & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ deb:
rules: foo.sh
# Deb templates file, when using debconf.
templates: templates
# Deb config maintainer script for asking questions when using debconf.
config: config

# Custom deb triggers
triggers:
Expand Down

1 comment on commit 7701bb9

@vercel
Copy link

@vercel vercel bot commented on 7701bb9 Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.