2020-02-21 02:11:56 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// mkpkg builds the Tailscale rpm and deb packages.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-07 20:38:33 +00:00
|
|
|
"flag"
|
2020-02-21 02:11:56 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/goreleaser/nfpm"
|
|
|
|
_ "github.com/goreleaser/nfpm/deb"
|
|
|
|
_ "github.com/goreleaser/nfpm/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{}
|
2021-05-05 04:58:39 +00:00
|
|
|
if len(s) == 0 {
|
|
|
|
return ret, nil
|
|
|
|
}
|
2020-02-21 02:11:56 +00:00
|
|
|
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]
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2020-05-04 20:10:14 +00:00
|
|
|
func parseEmptyDirs(s string) []string {
|
|
|
|
// 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, ",")
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:11:56 +00:00
|
|
|
func main() {
|
2022-04-07 20:38:33 +00:00
|
|
|
out := flag.String("out", "", "output file to write")
|
|
|
|
name := flag.String("name", "tailscale", "package name")
|
|
|
|
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")
|
|
|
|
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")
|
|
|
|
postinst := flag.String("postinst", "", "debian postinst script path")
|
|
|
|
prerm := flag.String("prerm", "", "debian prerm script path")
|
|
|
|
postrm := flag.String("postrm", "", "debian postrm script path")
|
|
|
|
replaces := flag.String("replaces", "", "package which this package replaces, if any")
|
|
|
|
depends := flag.String("depends", "", "comma-separated list of packages this package depends on")
|
|
|
|
flag.Parse()
|
2020-02-21 02:11:56 +00:00
|
|
|
|
|
|
|
filesMap, err := parseFiles(*files)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Parsing --files: %v", err)
|
|
|
|
}
|
|
|
|
configsMap, err := parseFiles(*configFiles)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Parsing --configs: %v", err)
|
|
|
|
}
|
2020-05-04 20:10:14 +00:00
|
|
|
emptyDirList := parseEmptyDirs(*emptyDirs)
|
2020-02-21 02:11:56 +00:00
|
|
|
info := nfpm.WithDefaults(&nfpm.Info{
|
2022-04-07 20:05:04 +00:00
|
|
|
Name: *name,
|
2020-02-21 02:11:56 +00:00
|
|
|
Arch: *goarch,
|
|
|
|
Platform: "linux",
|
|
|
|
Version: *version,
|
|
|
|
Maintainer: "Tailscale Inc <info@tailscale.com>",
|
2022-04-07 20:05:04 +00:00
|
|
|
Description: *description,
|
2020-02-21 02:11:56 +00:00
|
|
|
Homepage: "https://www.tailscale.com",
|
|
|
|
License: "MIT",
|
|
|
|
Overridables: nfpm.Overridables{
|
2020-05-04 20:10:14 +00:00
|
|
|
EmptyFolders: emptyDirList,
|
|
|
|
Files: filesMap,
|
|
|
|
ConfigFiles: configsMap,
|
2020-03-04 00:35:57 +00:00
|
|
|
Scripts: nfpm.Scripts{
|
|
|
|
PostInstall: *postinst,
|
|
|
|
PreRemove: *prerm,
|
|
|
|
PostRemove: *postrm,
|
|
|
|
},
|
2020-02-21 02:11:56 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-04-05 01:38:02 +00:00
|
|
|
if len(*depends) != 0 {
|
|
|
|
info.Overridables.Depends = strings.Split(*depends, ",")
|
|
|
|
}
|
2020-03-03 21:38:18 +00:00
|
|
|
if *replaces != "" {
|
|
|
|
info.Overridables.Replaces = []string{*replaces}
|
|
|
|
info.Overridables.Conflicts = []string{*replaces}
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:11:56 +00:00
|
|
|
switch *pkgType {
|
|
|
|
case "deb":
|
|
|
|
info.Section = "net"
|
|
|
|
info.Priority = "extra"
|
|
|
|
case "rpm":
|
|
|
|
info.Overridables.RPM.Group = "Network"
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg, err := nfpm.Get(*pkgType)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Getting packager for %q: %v", *pkgType, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.Create(*out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Creating output file %q: %v", *out, err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
if err := pkg.Package(info, f); err != nil {
|
|
|
|
log.Fatalf("Creating package %q: %v", *out, err)
|
|
|
|
}
|
|
|
|
}
|