Skip to content

Commit

Permalink
fix: improve apk packager
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 7, 2023
1 parent 48fbc96 commit ab21009
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"io"
"net/mail"
"os"
"sort"
"strings"
"sync/atomic"
"text/template"
Expand Down Expand Up @@ -343,18 +344,21 @@ func createBuilderControl(info *nfpm.Info, size int64, dataDigest []byte) func(t
// bin/echo 'running preinstall.sh' // do stuff here
//
// exit 0
for script, dest := range map[string]string{
info.Scripts.PreInstall: ".pre-install",
info.APK.Scripts.PreUpgrade: ".pre-upgrade",
info.Scripts.PostInstall: ".post-install",
info.APK.Scripts.PostUpgrade: ".post-upgrade",
info.Scripts.PreRemove: ".pre-deinstall",
info.Scripts.PostRemove: ".post-deinstall",
} {
if script != "" {
if err := newScriptInsideTarGz(tw, script, dest); err != nil {
return err
}
scripts := map[string]string{
".pre-install": info.Scripts.PreInstall,
".pre-upgrade": info.APK.Scripts.PreUpgrade,
".post-install": info.Scripts.PostInstall,
".post-upgrade": info.APK.Scripts.PostUpgrade,
".pre-deinstall": info.Scripts.PreRemove,
".post-deinstall": info.Scripts.PostRemove,
}
for _, name := range keys(scripts) {
path := scripts[name]
if path == "" {
continue
}
if err := newScriptInsideTarGz(tw, path, name); err != nil {
return err
}
}

Expand Down Expand Up @@ -508,3 +512,12 @@ func writeControl(w io.Writer, data controlData) error {
})
return template.Must(tmpl.Parse(controlTemplate)).Execute(w, data)
}

func keys(m map[string]string) []string {
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}

0 comments on commit ab21009

Please sign in to comment.