From 503328bf11ff12144baca3e9bdef7499d8c0f6a2 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 26 Sep 2022 14:38:14 -0700 Subject: [PATCH] Add scripts to package --- build.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/build.go b/build.go index f645dd0..03b64c5 100644 --- a/build.go +++ b/build.go @@ -66,6 +66,18 @@ type BuildVars struct { Sources []string `sh:"sources"` Checksums []string `sh:"checksums"` Backup []string `sh:"backup"` + Scripts Scripts `sh:"scripts"` +} + +type Scripts struct { + PreInstall string `sh:"preinstall"` + PostInstall string `sh:"postinstall"` + PreRemove string `sh:"preremove"` + PostRemove string `sh:"postinstall"` + PreUpgrade string `sh:"preupgrade"` + PostUpgrade string `sh:"postupgrade"` + PreTrans string `sh:"pretrans"` + PostTrans string `sh:"posttrans"` } func buildCmd(c *cli.Context) error { @@ -221,6 +233,8 @@ func buildPackage(ctx context.Context, script string, mgr manager.Manager) ([]st }, } + setScripts(&vars, pkgInfo, filepath.Dir(script)) + if pkgInfo.Arch == "arm" { pkgInfo.Arch = checkARMVariant() } @@ -393,6 +407,42 @@ func checkARMVariant() string { } } +func setScripts(vars *BuildVars, info *nfpm.Info, scriptDir string) { + if vars.Scripts.PreInstall != "" { + info.Scripts.PreInstall = filepath.Join(scriptDir, vars.Scripts.PreInstall) + } + + if vars.Scripts.PostInstall != "" { + info.Scripts.PostInstall = filepath.Join(scriptDir, vars.Scripts.PostInstall) + } + + if vars.Scripts.PreRemove != "" { + info.Scripts.PreRemove = filepath.Join(scriptDir, vars.Scripts.PreRemove) + } + + if vars.Scripts.PostRemove != "" { + info.Scripts.PostRemove = filepath.Join(scriptDir, vars.Scripts.PostRemove) + } + + if vars.Scripts.PreUpgrade != "" { + info.ArchLinux.Scripts.PreUpgrade = filepath.Join(scriptDir, vars.Scripts.PreUpgrade) + info.APK.Scripts.PreUpgrade = filepath.Join(scriptDir, vars.Scripts.PreUpgrade) + } + + if vars.Scripts.PostUpgrade != "" { + info.ArchLinux.Scripts.PostUpgrade = filepath.Join(scriptDir, vars.Scripts.PostUpgrade) + info.APK.Scripts.PostUpgrade = filepath.Join(scriptDir, vars.Scripts.PostUpgrade) + } + + if vars.Scripts.PreTrans != "" { + info.RPM.Scripts.PreTrans = filepath.Join(scriptDir, vars.Scripts.PreTrans) + } + + if vars.Scripts.PostTrans != "" { + info.RPM.Scripts.PostTrans = filepath.Join(scriptDir, vars.Scripts.PostTrans) + } +} + func uniq(ss ...*[]string) { for _, s := range ss { slices.Sort(*s)