mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 05:07:33 +00:00
go.mod: upgrade nfpm to v2 (#8786)
Upgrade the nfpm package to the latest version to pick up
24a43c5ad7
.
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>
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user