diff options
| author | Andrew Lytvynov <awly@tailscale.com> | 2023-08-03 13:00:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-03 13:00:45 -0700 |
| commit | eb6883bb5af750420ddb572e4300a17d42e0f4cf (patch) | |
| tree | 795f79a426606b51f44234f6d80c90a93a8b521c /cmd | |
| parent | 37925b3e7a96e93faa61d8251ca50b6ab918d694 (diff) | |
| download | tailscale-eb6883bb5af750420ddb572e4300a17d42e0f4cf.tar.xz tailscale-eb6883bb5af750420ddb572e4300a17d42e0f4cf.zip | |
go.mod: upgrade nfpm to v2 (#8786)
Upgrade the nfpm package to the latest version to pick up
https://github.com/goreleaser/nfpm/commit/24a43c5ad7cfc549e8a4ec930521a97a30f26cc8.
The upgrade is from v0 to v2, so there was some breakage to fix.
Generated packages should have the same contents as before.
Updates https://github.com/tailscale/tailscale/issues/1882
Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/mkpkg/main.go | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/cmd/mkpkg/main.go b/cmd/mkpkg/main.go index cae8dac0a..5e26b07f8 100644 --- a/cmd/mkpkg/main.go +++ b/cmd/mkpkg/main.go @@ -11,35 +11,40 @@ import ( "os" "strings" - "github.com/goreleaser/nfpm" - _ "github.com/goreleaser/nfpm/deb" - _ "github.com/goreleaser/nfpm/rpm" + "github.com/goreleaser/nfpm/v2" + _ "github.com/goreleaser/nfpm/v2/deb" + "github.com/goreleaser/nfpm/v2/files" + _ "github.com/goreleaser/nfpm/v2/rpm" ) // parseFiles parses a comma-separated list of colon-separated pairs -// into a map of filePathOnDisk -> filePathInPackage. -func parseFiles(s string) (map[string]string, error) { - ret := map[string]string{} +// into files.Contents format. +func parseFiles(s string, typ string) (files.Contents, error) { if len(s) == 0 { - return ret, nil + return nil, nil } + var contents files.Contents for _, f := range strings.Split(s, ",") { fs := strings.Split(f, ":") if len(fs) != 2 { return nil, fmt.Errorf("unparseable file field %q", f) } - ret[fs[0]] = fs[1] + contents = append(contents, &files.Content{Type: files.TypeFile, Source: fs[0], Destination: fs[1]}) } - return ret, nil + return contents, nil } -func parseEmptyDirs(s string) []string { +func parseEmptyDirs(s string) files.Contents { // strings.Split("", ",") would return []string{""}, which is not suitable: // this would create an empty dir record with path "", breaking the package if s == "" { return nil } - return strings.Split(s, ",") + var contents files.Contents + for _, d := range strings.Split(s, ",") { + contents = append(contents, &files.Content{Type: files.TypeDir, Destination: d}) + } + return contents } func main() { @@ -48,7 +53,7 @@ func main() { description := flag.String("description", "The easiest, most secure, cross platform way to use WireGuard + oauth2 + 2FA/SSO", "package description") goarch := flag.String("arch", "amd64", "GOARCH this package is for") pkgType := flag.String("type", "deb", "type of package to build (deb or rpm)") - files := flag.String("files", "", "comma-separated list of files in src:dst form") + regularFiles := flag.String("files", "", "comma-separated list of files in src:dst form") configFiles := flag.String("configs", "", "like --files, but for files marked as user-editable config files") emptyDirs := flag.String("emptydirs", "", "comma-separated list of empty directories") version := flag.String("version", "0.0.0", "version of the package") @@ -60,15 +65,20 @@ func main() { recommends := flag.String("recommends", "", "comma-separated list of packages this package recommends") flag.Parse() - filesMap, err := parseFiles(*files) + filesList, err := parseFiles(*regularFiles, files.TypeFile) if err != nil { log.Fatalf("Parsing --files: %v", err) } - configsMap, err := parseFiles(*configFiles) + configsList, err := parseFiles(*configFiles, files.TypeConfig) if err != nil { log.Fatalf("Parsing --configs: %v", err) } emptyDirList := parseEmptyDirs(*emptyDirs) + contents := append(filesList, append(configsList, emptyDirList...)...) + contents, err = files.PrepareForPackager(contents, 0, *pkgType, false) + if err != nil { + log.Fatalf("Building package contents: %v", err) + } info := nfpm.WithDefaults(&nfpm.Info{ Name: *name, Arch: *goarch, @@ -79,9 +89,7 @@ func main() { Homepage: "https://www.tailscale.com", License: "MIT", Overridables: nfpm.Overridables{ - EmptyFolders: emptyDirList, - Files: filesMap, - ConfigFiles: configsMap, + Contents: contents, Scripts: nfpm.Scripts{ PostInstall: *postinst, PreRemove: *prerm, |
