2018-02-05 02:53:22 +01:00
// Package nfpm provides ways to package programs in some linux packaging
2018-01-04 13:49:15 +01:00
// formats.
2018-02-05 02:53:22 +01:00
package nfpm
2018-01-04 13:31:22 +01:00
2018-02-12 16:50:25 +01:00
import (
2022-09-12 03:31:51 +02:00
"errors"
2018-02-12 16:50:25 +01:00
"fmt"
"io"
2022-09-12 03:31:51 +02:00
"io/fs"
2018-04-10 01:04:06 +02:00
"os"
feat: allow env expansion in conflicts, suggests, recommends, depends… (#548)
* feat: allow env expansion in conflicts, suggests, recommends, depends, provides, and replaces. Ensuring empty env vars get stripped to not cause issues
* added test for boolean dependencies for rpm, deb, and apk.
* fix: fork rpmpack to make it easier to add features and adapt it
* test: fix linter issues
* test: fix ruleguard issues
2022-09-24 19:07:11 +02:00
"strings"
2018-02-12 16:50:25 +01:00
"sync"
2018-04-10 01:04:06 +02:00
2021-04-08 20:15:11 +02:00
"github.com/AlekSi/pointer"
2019-10-10 03:11:58 +02:00
"github.com/Masterminds/semver/v3"
2022-08-10 05:46:47 +02:00
"github.com/goreleaser/chglog"
2021-10-12 19:42:00 +02:00
"github.com/goreleaser/nfpm/v2/files"
2018-04-10 01:04:06 +02:00
"github.com/imdario/mergo"
2020-12-15 17:47:00 +01:00
"gopkg.in/yaml.v3"
2018-02-12 16:50:25 +01:00
)
2019-03-04 14:14:05 +01:00
// nolint: gochecknoglobals
2018-02-12 16:50:25 +01:00
var (
packagers = map [ string ] Packager { }
lock sync . Mutex
)
2020-12-15 17:47:00 +01:00
// RegisterPackager a new packager for the given format.
func RegisterPackager ( format string , p Packager ) {
2018-02-12 16:50:25 +01:00
lock . Lock ( )
2020-12-15 17:47:00 +01:00
defer lock . Unlock ( )
2018-02-12 16:50:25 +01:00
packagers [ format ] = p
2020-12-15 17:47:00 +01:00
}
// ClearPackagers clear all registered packagers, used for testing.
func ClearPackagers ( ) {
lock . Lock ( )
defer lock . Unlock ( )
packagers = map [ string ] Packager { }
2018-02-12 16:50:25 +01:00
}
2020-05-13 21:24:06 +02:00
// ErrNoPackager happens when no packager is registered for the given format.
type ErrNoPackager struct {
format string
}
func ( e ErrNoPackager ) Error ( ) string {
return fmt . Sprintf ( "no packager registered for the format %s" , e . format )
}
// Get a packager for the given format.
2018-02-12 16:50:25 +01:00
func Get ( format string ) ( Packager , error ) {
p , ok := packagers [ format ]
if ! ok {
2020-05-13 21:24:06 +02:00
return nil , ErrNoPackager { format }
2018-02-12 16:50:25 +01:00
}
return p , nil
}
2018-01-10 14:16:07 +01:00
2020-05-13 21:24:06 +02:00
// Parse decodes YAML data from an io.Reader into a configuration struct.
2018-04-10 01:04:06 +02:00
func Parse ( in io . Reader ) ( config Config , err error ) {
2021-04-15 22:25:39 +02:00
return ParseWithEnvMapping ( in , os . Getenv )
}
// ParseWithEnvMapping decodes YAML data from an io.Reader into a configuration struct.
func ParseWithEnvMapping ( in io . Reader , mapping func ( string ) string ) ( config Config , err error ) {
2018-04-10 01:04:06 +02:00
dec := yaml . NewDecoder ( in )
2020-12-15 17:47:00 +01:00
dec . KnownFields ( true )
2018-04-10 21:11:35 +02:00
if err = dec . Decode ( & config ) ; err != nil {
return
}
2021-04-15 22:25:39 +02:00
config . envMappingFunc = mapping
if config . envMappingFunc == nil {
config . envMappingFunc = func ( s string ) string { return s }
}
2018-09-14 15:48:12 +02:00
2021-01-14 19:32:10 +01:00
config . expandEnvVars ( )
2019-10-22 23:29:42 +02:00
2021-01-14 19:32:10 +01:00
WithDefaults ( & config . Info )
2021-11-06 18:10:46 +01:00
return config , nil
2021-01-14 19:32:10 +01:00
}
2020-05-13 21:24:06 +02:00
// ParseFile decodes YAML data from a file path into a configuration struct.
2018-04-10 01:04:06 +02:00
func ParseFile ( path string ) ( config Config , err error ) {
2021-04-15 22:25:39 +02:00
return ParseFileWithEnvMapping ( path , os . Getenv )
}
// ParseFileWithEnvMapping decodes YAML data from a file path into a configuration struct.
func ParseFileWithEnvMapping ( path string , mapping func ( string ) string ) ( config Config , err error ) {
2018-04-10 01:04:06 +02:00
var file * os . File
2018-09-12 18:17:59 +02:00
file , err = os . Open ( path ) //nolint:gosec
2018-04-10 01:04:06 +02:00
if err != nil {
return
}
2020-05-13 21:24:06 +02:00
defer file . Close ( ) // nolint: errcheck,gosec
2021-04-15 22:25:39 +02:00
return ParseWithEnvMapping ( file , mapping )
2018-04-10 01:04:06 +02:00
}
2020-05-13 21:24:06 +02:00
// Packager represents any packager implementation.
2018-01-10 14:16:07 +01:00
type Packager interface {
2019-10-11 22:11:28 +02:00
Package ( info * Info , w io . Writer ) error
2020-07-09 15:16:04 +02:00
ConventionalFileName ( info * Info ) string
2018-01-04 13:31:22 +01:00
}
2020-05-13 21:24:06 +02:00
// Config contains the top level configuration for packages.
2018-04-10 01:04:06 +02:00
type Config struct {
2022-07-28 14:53:34 +02:00
Info ` yaml:",inline" json:",inline" `
feat: allow env expansion in conflicts, suggests, recommends, depends… (#548)
* feat: allow env expansion in conflicts, suggests, recommends, depends, provides, and replaces. Ensuring empty env vars get stripped to not cause issues
* added test for boolean dependencies for rpm, deb, and apk.
* fix: fork rpmpack to make it easier to add features and adapt it
* test: fix linter issues
* test: fix ruleguard issues
2022-09-24 19:07:11 +02:00
Overrides map [ string ] * Overridables ` yaml:"overrides,omitempty" json:"overrides,omitempty" jsonschema:"title=overrides,description=override some fields when packaging with a specific packager,enum=apk,enum=deb,enum=rpm" `
2021-04-15 22:25:39 +02:00
envMappingFunc func ( string ) string
2018-04-10 01:04:06 +02:00
}
// Get returns the Info struct for the given packager format. Overrides
2020-05-13 21:24:06 +02:00
// for the given format are merged into the final struct.
2019-10-11 22:11:28 +02:00
func ( c * Config ) Get ( format string ) ( info * Info , err error ) {
info = & Info { }
2018-04-10 17:39:43 +02:00
// make a deep copy of info
2019-10-11 22:11:28 +02:00
if err = mergo . Merge ( info , c . Info ) ; err != nil {
2020-09-19 22:06:07 +02:00
return nil , fmt . Errorf ( "failed to merge config into info: %w" , err )
2018-04-10 01:04:06 +02:00
}
2018-04-10 17:39:43 +02:00
override , ok := c . Overrides [ format ]
2018-04-10 01:04:06 +02:00
if ! ok {
// no overrides
2019-10-11 22:11:28 +02:00
return info , nil
2018-04-10 01:04:06 +02:00
}
2019-10-11 22:11:28 +02:00
if err = mergo . Merge ( & info . Overridables , override , mergo . WithOverride ) ; err != nil {
2020-09-19 22:06:07 +02:00
return nil , fmt . Errorf ( "failed to merge overrides into info: %w" , err )
2018-04-10 01:04:06 +02:00
}
2020-12-23 01:28:32 +01:00
var contents [ ] * files . Content
for _ , f := range info . Contents {
if f . Packager == format || f . Packager == "" {
contents = append ( contents , f )
}
}
info . Contents = contents
2019-10-11 22:11:28 +02:00
return info , nil
2018-04-10 01:04:06 +02:00
}
2020-05-13 21:24:06 +02:00
// Validate ensures that the config is well typed.
2018-04-10 22:59:25 +02:00
func ( c * Config ) Validate ( ) error {
2020-12-15 17:47:00 +01:00
if err := Validate ( & c . Info ) ; err != nil {
return err
}
2018-04-10 21:11:35 +02:00
for format := range c . Overrides {
if _ , err := Get ( format ) ; err != nil {
return err
}
}
return nil
}
feat: allow env expansion in conflicts, suggests, recommends, depends… (#548)
* feat: allow env expansion in conflicts, suggests, recommends, depends, provides, and replaces. Ensuring empty env vars get stripped to not cause issues
* added test for boolean dependencies for rpm, deb, and apk.
* fix: fork rpmpack to make it easier to add features and adapt it
* test: fix linter issues
* test: fix ruleguard issues
2022-09-24 19:07:11 +02:00
func remove ( slice [ ] string , s int ) [ ] string {
return append ( slice [ : s ] , slice [ s + 1 : ] ... )
}
func ( c * Config ) expandEnvVarsStringSlice ( items [ ] string ) [ ] string {
for i , dep := range items {
val := strings . TrimSpace ( os . Expand ( dep , c . envMappingFunc ) )
items [ i ] = val
}
for i , val := range items {
if val == "" {
items = remove ( items , i )
}
}
return items
}
2021-04-15 22:25:39 +02:00
func ( c * Config ) expandEnvVars ( ) {
// Version related fields
c . Info . Release = os . Expand ( c . Info . Release , c . envMappingFunc )
c . Info . Version = os . Expand ( c . Info . Version , c . envMappingFunc )
c . Info . Prerelease = os . Expand ( c . Info . Prerelease , c . envMappingFunc )
c . Info . Arch = os . Expand ( c . Info . Arch , c . envMappingFunc )
feat: allow env expansion in conflicts, suggests, recommends, depends… (#548)
* feat: allow env expansion in conflicts, suggests, recommends, depends, provides, and replaces. Ensuring empty env vars get stripped to not cause issues
* added test for boolean dependencies for rpm, deb, and apk.
* fix: fork rpmpack to make it easier to add features and adapt it
* test: fix linter issues
* test: fix ruleguard issues
2022-09-24 19:07:11 +02:00
for or := range c . Overrides {
c . Overrides [ or ] . Conflicts = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Conflicts )
c . Overrides [ or ] . Depends = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Depends )
c . Overrides [ or ] . Replaces = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Replaces )
c . Overrides [ or ] . Recommends = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Recommends )
c . Overrides [ or ] . Provides = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Provides )
c . Overrides [ or ] . Suggests = c . expandEnvVarsStringSlice ( c . Overrides [ or ] . Suggests )
2022-02-10 00:49:37 +01:00
}
2021-04-15 22:25:39 +02:00
2022-03-18 04:07:12 +01:00
// Maintainer and vendor fields
c . Info . Maintainer = os . Expand ( c . Info . Maintainer , c . envMappingFunc )
2021-11-19 18:08:38 +01:00
c . Info . Vendor = os . Expand ( c . Info . Vendor , c . envMappingFunc )
2021-04-15 22:25:39 +02:00
// Package signing related fields
c . Info . Deb . Signature . KeyFile = os . Expand ( c . Deb . Signature . KeyFile , c . envMappingFunc )
c . Info . RPM . Signature . KeyFile = os . Expand ( c . RPM . Signature . KeyFile , c . envMappingFunc )
c . Info . APK . Signature . KeyFile = os . Expand ( c . APK . Signature . KeyFile , c . envMappingFunc )
c . Info . Deb . Signature . KeyID = pointer . ToString ( os . Expand ( pointer . GetString ( c . Deb . Signature . KeyID ) , c . envMappingFunc ) )
c . Info . RPM . Signature . KeyID = pointer . ToString ( os . Expand ( pointer . GetString ( c . RPM . Signature . KeyID ) , c . envMappingFunc ) )
c . Info . APK . Signature . KeyID = pointer . ToString ( os . Expand ( pointer . GetString ( c . APK . Signature . KeyID ) , c . envMappingFunc ) )
// Package signing passphrase
generalPassphrase := os . Expand ( "$NFPM_PASSPHRASE" , c . envMappingFunc )
c . Info . Deb . Signature . KeyPassphrase = generalPassphrase
c . Info . RPM . Signature . KeyPassphrase = generalPassphrase
c . Info . APK . Signature . KeyPassphrase = generalPassphrase
debPassphrase := os . Expand ( "$NFPM_DEB_PASSPHRASE" , c . envMappingFunc )
if debPassphrase != "" {
c . Info . Deb . Signature . KeyPassphrase = debPassphrase
}
rpmPassphrase := os . Expand ( "$NFPM_RPM_PASSPHRASE" , c . envMappingFunc )
if rpmPassphrase != "" {
c . Info . RPM . Signature . KeyPassphrase = rpmPassphrase
}
apkPassphrase := os . Expand ( "$NFPM_APK_PASSPHRASE" , c . envMappingFunc )
if apkPassphrase != "" {
c . Info . APK . Signature . KeyPassphrase = apkPassphrase
}
2021-11-30 19:56:10 +01:00
// RPM specific
c . Info . RPM . Packager = os . Expand ( c . RPM . Packager , c . envMappingFunc )
2021-04-15 22:25:39 +02:00
}
2020-05-13 21:24:06 +02:00
// Info contains information about a single package.
2018-01-04 13:31:22 +01:00
type Info struct {
2022-07-28 14:53:34 +02:00
Overridables ` yaml:",inline" json:",inline" `
Name string ` yaml:"name" json:"name" jsonschema:"title=package name" `
Arch string ` yaml:"arch" json:"arch" jsonschema:"title=target architecture,example=amd64" `
Platform string ` yaml:"platform,omitempty" json:"platform,omitempty" jsonschema:"title=target platform,example=linux,default=linux" `
Epoch string ` yaml:"epoch,omitempty" json:"epoch,omitempty" jsonschema:"title=version epoch,example=2,default=extracted from version" `
Version string ` yaml:"version" json:"version" jsonschema:"title=version,example=v1.0.2,example=2.0.1" `
VersionSchema string ` yaml:"version_schema,omitempty" json:"version_schema,omitempty" jsonschema:"title=version schema,enum=semver,enum=none,default=semver" `
Release string ` yaml:"release,omitempty" json:"release,omitempty" jsonschema:"title=version release,example=1" `
Prerelease string ` yaml:"prerelease,omitempty" json:"prerelease,omitempty" jsonschema:"title=version prerelease,default=extracted from version" `
VersionMetadata string ` yaml:"version_metadata,omitempty" json:"version_metadata,omitempty" jsonschema:"title=version metadata,example=git" `
Section string ` yaml:"section,omitempty" json:"section,omitempty" jsonschema:"title=package section,example=default" `
Priority string ` yaml:"priority,omitempty" json:"priority,omitempty" jsonschema:"title=package priority,example=extra" `
Maintainer string ` yaml:"maintainer,omitempty" json:"maintainer,omitempty" jsonschema:"title=package maintainer,example=me@example.com" `
Description string ` yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=package description" `
Vendor string ` yaml:"vendor,omitempty" json:"vendor,omitempty" jsonschema:"title=package vendor,example=MyCorp" `
Homepage string ` yaml:"homepage,omitempty" json:"homepage,omitempty" jsonschema:"title=package homepage,example=https://example.com" `
License string ` yaml:"license,omitempty" json:"license,omitempty" jsonschema:"title=package license,example=MIT" `
2022-08-10 05:46:47 +02:00
Changelog string ` yaml:"changelog,omitempty" json:"changelog,omitempty" jsonschema:"title=package changelog,example=changelog.yaml,description=see https://github.com/goreleaser/chglog for more details" `
2022-07-28 14:53:34 +02:00
DisableGlobbing bool ` yaml:"disable_globbing,omitempty" json:"disable_globbing,omitempty" jsonschema:"title=wether to disable file globbing,default=false" `
Target string ` yaml:"-" json:"-" `
2018-04-10 17:39:43 +02:00
}
2020-12-15 17:47:00 +01:00
func ( i * Info ) Validate ( ) error {
return Validate ( i )
}
2022-08-10 05:46:47 +02:00
// GetChangeLog parses the provided changelog file.
func ( i * Info ) GetChangeLog ( ) ( log * chglog . PackageChangeLog , err error ) {
// if the file does not exist chglog.Parse will just silently
// create an empty changelog but we should notify the user instead
2022-09-12 03:31:51 +02:00
if _ , err = os . Stat ( i . Changelog ) ; errors . Is ( err , fs . ErrNotExist ) {
2022-08-10 05:46:47 +02:00
return nil , err
}
entries , err := chglog . Parse ( i . Changelog )
if err != nil {
return nil , err
}
return & chglog . PackageChangeLog {
Name : i . Name ,
Entries : entries ,
} , nil
}
2021-04-23 02:36:16 +02:00
func ( i * Info ) parseSemver ( ) {
// parse the version as a semver so we can properly split the parts
// and support proper ordering for both rpm and deb
if v , err := semver . NewVersion ( i . Version ) ; err == nil {
i . Version = fmt . Sprintf ( "%d.%d.%d" , v . Major ( ) , v . Minor ( ) , v . Patch ( ) )
if i . Prerelease == "" {
i . Prerelease = v . Prerelease ( )
}
if i . VersionMetadata == "" {
i . VersionMetadata = v . Metadata ( )
}
}
}
2020-05-13 21:24:06 +02:00
// Overridables contain the field which are overridable in a package.
2018-04-10 17:39:43 +02:00
type Overridables struct {
2022-07-28 14:53:34 +02:00
Replaces [ ] string ` yaml:"replaces,omitempty" json:"replaces,omitempty" jsonschema:"title=replaces directive,example=nfpm" `
Provides [ ] string ` yaml:"provides,omitempty" json:"provides,omitempty" jsonschema:"title=provides directive,example=nfpm" `
Depends [ ] string ` yaml:"depends,omitempty" json:"depends,omitempty" jsonschema:"title=depends directive,example=nfpm" `
Recommends [ ] string ` yaml:"recommends,omitempty" json:"recommends,omitempty" jsonschema:"title=recommends directive,example=nfpm" `
Suggests [ ] string ` yaml:"suggests,omitempty" json:"suggests,omitempty" jsonschema:"title=suggests directive,example=nfpm" `
Conflicts [ ] string ` yaml:"conflicts,omitempty" json:"conflicts,omitempty" jsonschema:"title=conflicts directive,example=nfpm" `
Contents files . Contents ` yaml:"contents,omitempty" json:"contents,omitempty" jsonschema:"title=files to add to the package" `
Scripts Scripts ` yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=scripts to execute" `
RPM RPM ` yaml:"rpm,omitempty" json:"rpm,omitempty" jsonschema:"title=rpm-specific settings" `
Deb Deb ` yaml:"deb,omitempty" json:"deb,omitempty" jsonschema:"title=deb-specific settings" `
APK APK ` yaml:"apk,omitempty" json:"apk,omitempty" jsonschema:"title=apk-specific settings" `
2018-04-08 20:43:09 +02:00
}
2020-05-13 21:24:06 +02:00
// RPM is custom configs that are only available on RPM packages.
2019-07-16 01:20:57 +02:00
type RPM struct {
2022-07-28 14:53:34 +02:00
Arch string ` yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in rpm nomenclature" `
Scripts RPMScripts ` yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=rpm-specific scripts" `
Group string ` yaml:"group,omitempty" json:"group,omitempty" jsonschema:"title=package group,example=Unspecified" `
Summary string ` yaml:"summary,omitempty" json:"summary,omitempty" jsonschema:"title=package summary" `
Compression string ` yaml:"compression,omitempty" json:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=lzma,enum=xz,default=gzip:-1" `
Signature RPMSignature ` yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=rpm signature" `
Packager string ` yaml:"packager,omitempty" json:"packager,omitempty" jsonschema:"title=organization that actually packaged the software" `
2020-09-17 14:18:44 +02:00
}
2021-04-22 20:48:06 +02:00
// RPMScripts represents scripts only available on RPM packages.
type RPMScripts struct {
2022-07-28 14:53:34 +02:00
PreTrans string ` yaml:"pretrans,omitempty" json:"pretrans,omitempty" jsonschema:"title=pretrans script" `
PostTrans string ` yaml:"posttrans,omitempty" json:"posttrans,omitempty" jsonschema:"title=posttrans script" `
2021-04-22 20:48:06 +02:00
}
2021-01-14 19:32:10 +01:00
type PackageSignature struct {
2020-09-17 14:18:44 +02:00
// PGP secret key, can be ASCII-armored
2022-07-28 14:53:34 +02:00
KeyFile string ` yaml:"key_file,omitempty" json:"key_file,omitempty" jsonschema:"title=key file,example=key.gpg" `
KeyID * string ` yaml:"key_id,omitempty" json:"key_id,omitempty" jsonschema:"title=key id,example=bc8acdd415bd80b3" `
KeyPassphrase string ` yaml:"-" json:"-" ` // populated from environment variable
2020-09-17 14:18:44 +02:00
}
2021-01-14 19:32:10 +01:00
type RPMSignature struct {
2022-07-28 14:53:34 +02:00
PackageSignature ` yaml:",inline" json:",inline" `
2021-01-14 19:32:10 +01:00
}
2020-09-17 14:18:44 +02:00
type APK struct {
2022-07-28 14:53:34 +02:00
Arch string ` yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in apk nomenclature" `
Signature APKSignature ` yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=apk signature" `
Scripts APKScripts ` yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=apk scripts" `
2020-09-17 14:18:44 +02:00
}
type APKSignature struct {
2022-07-28 14:53:34 +02:00
PackageSignature ` yaml:",inline" json:",inline" `
2020-09-17 14:18:44 +02:00
// defaults to <maintainer email>.rsa.pub
2022-07-28 14:53:34 +02:00
KeyName string ` yaml:"key_name,omitempty" json:"key_name,omitempty" jsonschema:"title=key name,example=origin,default=maintainer_email.rsa.pub" `
2019-07-16 01:20:57 +02:00
}
2021-04-20 23:02:37 +02:00
type APKScripts struct {
2022-07-28 14:53:34 +02:00
PreUpgrade string ` yaml:"preupgrade,omitempty" json:"preupgrade,omitempty" jsonschema:"title=pre upgrade script" `
PostUpgrade string ` yaml:"postupgrade,omitempty" json:"postupgrade,omitempty" jsonschema:"title=post upgrade script" `
2021-04-20 23:02:37 +02:00
}
2020-05-13 21:24:06 +02:00
// Deb is custom configs that are only available on deb packages.
2019-08-31 15:21:28 +02:00
type Deb struct {
2022-07-28 14:53:34 +02:00
Arch string ` yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in deb nomenclature" `
Scripts DebScripts ` yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=scripts" `
Triggers DebTriggers ` yaml:"triggers,omitempty" json:"triggers,omitempty" jsonschema:"title=triggers" `
Breaks [ ] string ` yaml:"breaks,omitempty" json:"breaks,omitempty" jsonschema:"title=breaks" `
Signature DebSignature ` yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=signature" `
Compression string ` yaml:"compression,omitempty" json:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=xz,enum=none,default=gzip" `
Fields map [ string ] string ` yaml:"fields,omitempty" json:"fields,omitempty" jsonschema:"title=fields" `
2020-09-17 14:18:44 +02:00
}
type DebSignature struct {
2022-07-28 14:53:34 +02:00
PackageSignature ` yaml:",inline" json:",inline" `
2022-05-30 15:34:45 +02:00
// debsign, or dpkg-sig (defaults to debsign)
2022-07-28 14:53:34 +02:00
Method string ` yaml:"method,omitempty" json:"method,omitempty" jsonschema:"title=method role,enum=debsign,enum=dpkg-sig,default=debsign" `
2020-09-17 14:18:44 +02:00
// origin, maint or archive (defaults to origin)
2022-07-28 14:53:34 +02:00
Type string ` yaml:"type,omitempty" json:"type,omitempty" jsonschema:"title=signer role,enum=origin,enum=maint,enum=archive,default=origin" `
Signer string ` yaml:"signer,omitempty" json:"signer,omitempty" jsonschema:"title=signer" `
2020-07-27 18:22:06 +02:00
}
// DebTriggers contains triggers only available for deb packages.
// https://wiki.debian.org/DpkgTriggers
// https://man7.org/linux/man-pages/man5/deb-triggers.5.html
type DebTriggers struct {
2022-07-28 14:53:34 +02:00
Interest [ ] string ` yaml:"interest,omitempty" json:"interest,omitempty" jsonschema:"title=interest" `
InterestAwait [ ] string ` yaml:"interest_await,omitempty" json:"interest_await,omitempty" jsonschema:"title=interest await" `
InterestNoAwait [ ] string ` yaml:"interest_noawait,omitempty" json:"interest_noawait,omitempty" jsonschema:"title=interest noawait" `
Activate [ ] string ` yaml:"activate,omitempty" json:"activate,omitempty" jsonschema:"title=activate" `
ActivateAwait [ ] string ` yaml:"activate_await,omitempty" json:"activate_await,omitempty" jsonschema:"title=activate await" `
ActivateNoAwait [ ] string ` yaml:"activate_noawait,omitempty" json:"activate_noawait,omitempty" jsonschema:"title=activate noawait" `
2019-08-31 15:21:28 +02:00
}
2020-05-13 21:24:06 +02:00
// DebScripts is scripts only available on deb packages.
2019-08-31 15:21:28 +02:00
type DebScripts struct {
2022-07-28 14:53:34 +02:00
Rules string ` yaml:"rules,omitempty" json:"rules,omitempty" jsonschema:"title=rules" `
Templates string ` yaml:"templates,omitempty" json:"templates,omitempty" jsonschema:"title=templates" `
Config string ` yaml:"config,omitempty" json:"config,omitempty" jsonschema:"title=config" `
2019-08-31 15:21:28 +02:00
}
2020-05-13 21:24:06 +02:00
// Scripts contains information about maintainer scripts for packages.
2018-04-08 20:43:09 +02:00
type Scripts struct {
2022-07-28 14:53:34 +02:00
PreInstall string ` yaml:"preinstall,omitempty" json:"preinstall,omitempty" jsonschema:"title=pre install" `
PostInstall string ` yaml:"postinstall,omitempty" json:"postinstall,omitempty" jsonschema:"title=post install" `
PreRemove string ` yaml:"preremove,omitempty" json:"preremove,omitempty" jsonschema:"title=pre remove" `
PostRemove string ` yaml:"postremove,omitempty" json:"postremove,omitempty" jsonschema:"title=post remove" `
2018-01-04 13:31:22 +01:00
}
2018-02-12 22:15:37 +01:00
2020-05-13 21:24:06 +02:00
// ErrFieldEmpty happens when some required field is empty.
type ErrFieldEmpty struct {
field string
}
func ( e ErrFieldEmpty ) Error ( ) string {
return fmt . Sprintf ( "package %s must be provided" , e . field )
}
2018-04-05 04:13:47 +02:00
// Validate the given Info and returns an error if it is invalid.
2020-12-15 17:47:00 +01:00
func Validate ( info * Info ) ( err error ) {
2018-04-05 04:13:47 +02:00
if info . Name == "" {
2020-05-13 21:24:06 +02:00
return ErrFieldEmpty { "name" }
2018-04-05 04:13:47 +02:00
}
2021-11-06 18:04:50 +01:00
if info . Arch == "" && ( info . Deb . Arch == "" || info . RPM . Arch == "" || info . APK . Arch == "" ) {
2020-05-13 21:24:06 +02:00
return ErrFieldEmpty { "arch" }
2018-04-05 04:13:47 +02:00
}
if info . Version == "" {
2020-05-13 21:24:06 +02:00
return ErrFieldEmpty { "version" }
2018-04-05 04:13:47 +02:00
}
2020-08-20 06:00:17 +02:00
2020-12-30 20:15:16 +01:00
contents , err := files . ExpandContentGlobs ( info . Contents , info . DisableGlobbing )
if err != nil {
return err
}
info . Contents = contents
return nil
2018-04-05 04:13:47 +02:00
}
2020-05-13 21:24:06 +02:00
// WithDefaults set some sane defaults into the given Info.
2019-10-11 22:11:28 +02:00
func WithDefaults ( info * Info ) * Info {
2018-02-12 22:15:37 +01:00
if info . Platform == "" {
info . Platform = "linux"
}
2018-03-20 19:57:36 +01:00
if info . Description == "" {
info . Description = "no description given"
}
2020-12-15 17:47:00 +01:00
if info . Arch == "" {
info . Arch = "amd64"
}
if info . Version == "" {
info . Version = "v0.0.0-rc0"
}
2019-11-05 13:38:13 +01:00
2021-04-23 02:36:16 +02:00
switch info . VersionSchema {
case "none" :
// No change to the version or prerelease info set in the YAML file
break
case "semver" :
fallthrough
default :
info . parseSemver ( )
}
2018-02-12 22:15:37 +01:00
return info
}
2020-05-14 14:46:46 +02:00
2020-09-17 14:18:44 +02:00
// ErrSigningFailure is returned whenever something went wrong during
// the package signing process. The underlying error can be unwrapped
// and could be crypto-related or something that occurred while adding
// the signature to the package.
type ErrSigningFailure struct {
Err error
}
func ( s * ErrSigningFailure ) Error ( ) string {
return fmt . Sprintf ( "signing error: %v" , s . Err )
}
func ( s * ErrSigningFailure ) Unwarp ( ) error {
return s . Err
}