Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpm): add support for verify scriptlet #788

Merged
merged 1 commit into from
Feb 21, 2024
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
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 @@
rpm.AddPosttrans(string(data))
}

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

Check warning on line 348 in rpm/rpm.go

View check run for this annotation

Codecov / codecov/patch

rpm/rpm.go#L348

Added line #L348 was not covered by tests
}
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.

Loading