Skip to content

Commit

Permalink
feat(rpm): add support for verify scriptlet (#788)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicholas Jackson <nicholas.jackson@zii.aero>
  • Loading branch information
nickajacks1 and Nicholas Jackson authored Feb 21, 2024
1 parent 0b1bc17 commit d0d7c60
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestRPMSpecific(t *testing.T) {
testNames := []string{
"release",
"directories",
"verify",
}
for _, name := range testNames {
for _, arch := range formatArchs[format] {
Expand Down
1 change: 1 addition & 0 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ type RPM struct {
type RPMScripts struct {
PreTrans string `yaml:"pretrans,omitempty" json:"pretrans,omitempty" jsonschema:"title=pretrans script"`
PostTrans string `yaml:"posttrans,omitempty" json:"posttrans,omitempty" jsonschema:"title=posttrans script"`
Verify string `yaml:"verify,omitempty" json:"verify,omitempty" jsonschema:"title=verify script"`
}

type PackageSignature struct {
Expand Down
8 changes: 8 additions & 0 deletions rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ func addScriptFiles(info *nfpm.Info, rpm *rpmpack.RPM) error {
rpm.AddPosttrans(string(data))
}

if info.RPM.Scripts.Verify != "" {
data, err := os.ReadFile(info.RPM.Scripts.Verify)
if err != nil {
return err
}
rpm.AddVerifyScript(string(data))
}

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func exampleInfo() *nfpm.Info {
Scripts: nfpm.RPMScripts{
PreTrans: "../testdata/scripts/pretrans.sh",
PostTrans: "../testdata/scripts/posttrans.sh",
Verify: "../testdata/scripts/verify.sh",
},
},
},
Expand Down Expand Up @@ -481,6 +482,13 @@ echo "Pretrans" > /dev/null
echo "Posttrans" > /dev/null
`, data, "Posttrans script does not match")

data, err = rpm.Header.GetString(rpmutils.VERIFYSCRIPT)
require.NoError(t, err)
require.Equal(t, `#!/bin/bash
echo "Verify" > /dev/null
`, data, "Verify script does not match")
}

func TestRPMFileDoesNotExist(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testdata/acceptance/core.complex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ rpm:
scripts:
pretrans: ./testdata/acceptance/scripts/pretrans.sh
posttrans: ./testdata/acceptance/scripts/posttrans.sh
verify: ./testdata/acceptance/scripts/verify.sh
apk:
scripts:
preupgrade: ./testdata/acceptance/scripts/preupgrade.sh
Expand Down
6 changes: 6 additions & 0 deletions testdata/acceptance/rpm.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,9 @@ RUN test ! -f /etc/bar/file
RUN test -d /etc/foo
RUN test ! -d /etc/bar
RUN test ! -d /etc/baz

# ---- verify test ----
FROM min as verify
RUN rpm -V foo
RUN rm /tmp/postinstall-proof
RUN ! rpm -V foo
20 changes: 20 additions & 0 deletions testdata/acceptance/rpm.verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "foo"
arch: "${BUILD_ARCH}"
platform: "linux"
version: "v1.2.3"
maintainer: "Foo Bar"
release: "4"
description: |
Foo bar
Multiple lines
vendor: "foobar"
homepage: "https://foobar.org"
license: "MIT"
contents:
- src: ./testdata/fake
dst: /etc/foo/file
scripts:
postinstall: ./testdata/acceptance/scripts/postinstall.sh
rpm:
scripts:
verify: ./testdata/acceptance/scripts/verify.sh
3 changes: 3 additions & 0 deletions testdata/acceptance/scripts/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

test -e /tmp/postinstall-proof
3 changes: 3 additions & 0 deletions testdata/scripts/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Verify" > /dev/null
2 changes: 2 additions & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ rpm:
pretrans: ./scripts/pretrans.sh
# The posttrans script runs after all RPM package transactions / stages.
posttrans: ./scripts/posttrans.sh
# The verify script runs when verifying packages using `rpm -V`.
verify: ./scripts/verify.sh

# The package group. This option is deprecated by most distros
# but required by old distros like CentOS 5 / EL 5 and earlier.
Expand Down
6 changes: 5 additions & 1 deletion www/docs/static/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0d7c60

Please sign in to comment.