Skip to content

Commit

Permalink
chore: rpm: re-enable scriptlets processing
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Nov 25, 2024
1 parent 55f7836 commit 69b6308
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/dpkg/dpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (d *Deb) createDebconfFile(name, variable string) error {
// createScripts generates and writes the scripts for the Deb package.
// It takes no parameters and returns an error if there was an issue
// generating or writing the scripts.
func (d *Deb) createScripts() error {
func (d *Deb) addScriptlets() error {
scripts := map[string]string{
"preinst": d.PKGBUILD.PreInst,
"postinst": d.PKGBUILD.PostInst,
Expand Down Expand Up @@ -257,7 +257,7 @@ func (d *Deb) createDebResources() error {
return err
}

if err := d.createScripts(); err != nil {
if err := d.addScriptlets(); err != nil {
return err
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (r *RPM) BuildPackage(artifactsPath string) error {
return err
}

r.addScriptlets(rpm)

cleanFilePath := filepath.Clean(pkgFilePath)

rpmFile, err := os.Create(cleanFilePath)
Expand Down Expand Up @@ -213,6 +215,28 @@ func addContentsToRPM(contents []*utils.FileContent, rpm *rpmpack.RPM) error {
return nil
}

// addScriptlets adds pre-install, post-install, pre-remove and post-remove
// scripts from the PKGBUILD to the RPM package if they are defined.
//
// It takes a pointer to the rpmpack.RPM instance as a parameter.
func (r *RPM) addScriptlets(rpm *rpmpack.RPM) {
if r.PKGBUILD.PreInst != "" {
rpm.AddPrein(r.PKGBUILD.PreInst)
}

if r.PKGBUILD.PostInst != "" {
rpm.AddPostin(r.PKGBUILD.PostInst)
}

if r.PKGBUILD.PreRm != "" {
rpm.AddPreun(r.PKGBUILD.PreRm)
}

if r.PKGBUILD.PostRm != "" {
rpm.AddPostun(r.PKGBUILD.PostRm)
}
}

// asRPMDirectory creates an RPMFile object for a directory based on the provided FileContent.
// It retrieves the directory's modification time and sets the appropriate fields in the RPMFile.
func asRPMDirectory(content *utils.FileContent) *rpmpack.RPMFile {
Expand Down

0 comments on commit 69b6308

Please sign in to comment.