Skip to content

Commit 4002927

Browse files
authored
Include scripts in the generated packages (#9)
This commit will add a new flag `-s ./directory/` to look for preinstall.sh, postinstall.sh, preremove.sh, postremove.sh scripts and include them to the generated packages. This works with .deb, .rpm and .apk packages. Make sure to write scripts that work in all distro.
1 parent a033515 commit 4002927

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

.github/workflows/vulncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
go-version: [ 1.23.5 ]
17+
go-version: [ 1.23.8 ]
1818
steps:
1919
- name: Check out code into the Go module directory
2020
uses: actions/checkout@v4

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module github.com/minio/pkger
22

33
go 1.23.0
44

5-
toolchain go1.23.5
5+
toolchain go1.23.8
66

77
require (
88
github.com/alecthomas/kingpin v2.2.6+incompatible
9-
github.com/goreleaser/nfpm/v2 v2.41.2
9+
github.com/goreleaser/nfpm/v2 v2.41.3
1010
github.com/json-iterator/go v1.1.12
1111
)
1212

@@ -17,7 +17,7 @@ require (
1717
github.com/Masterminds/semver/v3 v3.3.1 // indirect
1818
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
1919
github.com/Microsoft/go-winio v0.6.2 // indirect
20-
github.com/ProtonMail/go-crypto v1.1.5 // indirect
20+
github.com/ProtonMail/go-crypto v1.1.6 // indirect
2121
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
2222
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
2323
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
@@ -37,7 +37,7 @@ require (
3737
github.com/huandu/xstrings v1.5.0 // indirect
3838
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3939
github.com/kevinburke/ssh_config v1.2.0 // indirect
40-
github.com/klauspost/compress v1.17.11 // indirect
40+
github.com/klauspost/compress v1.18.0 // indirect
4141
github.com/klauspost/pgzip v1.2.6 // indirect
4242
github.com/mitchellh/copystructure v1.2.0 // indirect
4343
github.com/mitchellh/reflectwalk v1.0.2 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSC
1313
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
1414
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
1515
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
16-
github.com/ProtonMail/go-crypto v1.1.5 h1:eoAQfK2dwL+tFSFpr7TbOaPNUbPiJj4fLYwwGE1FQO4=
17-
github.com/ProtonMail/go-crypto v1.1.5/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
16+
github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw=
17+
github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
1818
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
1919
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
2020
github.com/ProtonMail/gopenpgp/v2 v2.7.1 h1:Awsg7MPc2gD3I7IFac2qE3Gdls0lZW8SzrFZ3k1oz0s=
@@ -75,8 +75,8 @@ github.com/goreleaser/chglog v0.6.2 h1:qroqdMHzwoAPTHHzJtbCfYbwg/yWJrNQApZ6IQAq8
7575
github.com/goreleaser/chglog v0.6.2/go.mod h1:BP0xQQc6B8aM+4dhvSLlVTv0rvhuOF0JacDO1+h7L3U=
7676
github.com/goreleaser/fileglob v1.3.0 h1:/X6J7U8lbDpQtBvGcwwPS6OpzkNVlVEsFUVRx9+k+7I=
7777
github.com/goreleaser/fileglob v1.3.0/go.mod h1:Jx6BoXv3mbYkEzwm9THo7xbr5egkAraxkGorbJb4RxU=
78-
github.com/goreleaser/nfpm/v2 v2.41.2 h1:yOjpPlft5zpMPusbIWICphycIjE5orpY/IyMbkBbIJU=
79-
github.com/goreleaser/nfpm/v2 v2.41.2/go.mod h1:zvk0z+wsPKe7Qdsp7z0ZJ9asnbwwhJUEsdOsPkgVC1E=
78+
github.com/goreleaser/nfpm/v2 v2.41.3 h1:IRRsqv5NgiCKUy57HjQgfVBFb44VH8+r1mWeEF8OuA4=
79+
github.com/goreleaser/nfpm/v2 v2.41.3/go.mod h1:0t54RfPX6/iKANsVLbB3XgtfQXzG1nS4HmSavN92qVY=
8080
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
8181
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
8282
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
@@ -87,8 +87,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
8787
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
8888
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
8989
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
90-
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
91-
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
90+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
91+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
9292
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
9393
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
9494
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

main.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024, MinIO, Inc.
2+
* Copyright (C) 2020-2025, MinIO, Inc.
33
*
44
* This code is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Affero General Public License, version 3,
@@ -63,6 +63,9 @@ var (
6363
Enum("deb", "rpm", "apk", "deb,rpm,apk")
6464
releaseDir = app.Flag("releaseDir", "Release directory (that contains os-arch specific dirs) to pick up binaries to package, defaults to `appName+\"-release\"`").
6565
Short('d').String()
66+
scriptsDir = app.Flag("scriptsDir", "Directory that contains package scripts (preinstall.sh, postinstall.sh, preremove.sh and postremove.sh), defaults to the current directory").
67+
Default("./").
68+
Short('s').String()
6669
)
6770

6871
const tmpl = `name: "{{ .App }}"
@@ -88,6 +91,10 @@ contents:
8891
- src: minio.service
8992
dst: /lib/systemd/system/minio.service
9093
{{end}}
94+
scripts:
95+
{{- range $name, $path := .Scripts }}
96+
{{ $name }}: "{{ $path }}"
97+
{{- end }}
9198
`
9299

93100
type dlInfo struct {
@@ -421,7 +428,7 @@ func main() {
421428
}
422429

423430
semVerTag := semVerRelease(*release)
424-
if err := doPackage(*appName, *release, *packager); err != nil {
431+
if err := doPackage(*appName, *release, *packager, *scriptsDir); err != nil {
425432
if !*ignoreMissingArch {
426433
kingpin.Fatalf(err.Error())
427434
} else {
@@ -457,6 +464,8 @@ type releaseTmpl struct {
457464
Arch string
458465
Release string
459466
SemVerRelease string
467+
468+
Scripts map[string]string
460469
}
461470

462471
const (
@@ -493,7 +502,7 @@ func semVerRelease(release string) string {
493502
}
494503

495504
// nolint:funlen
496-
func doPackage(appName, release, packager string) error {
505+
func doPackage(appName, release, packager, scriptsDir string) error {
497506
mtmpl, err := template.New("minio").Parse(tmpl)
498507
if err != nil {
499508
return err
@@ -548,6 +557,18 @@ func doPackage(appName, release, packager string) error {
548557
high performance infrastructure for machine learning, analytics and application
549558
data workloads.`
550559
}(),
560+
Scripts: func() (scripts map[string]string) {
561+
scripts = make(map[string]string)
562+
for _, s := range []string{"preinstall", "postinstall", "preremove", "postremove"} {
563+
path := filepath.Join(scriptsDir, s+".sh")
564+
if _, err := os.Stat(path); err == nil {
565+
scripts[s] = path
566+
} else if !os.IsNotExist(err) {
567+
fmt.Printf("unable to access to %s: %s \n", path, err)
568+
}
569+
}
570+
return
571+
}(),
551572
OS: "linux",
552573
Arch: arch,
553574
Release: release,

0 commit comments

Comments
 (0)