Add pre and post remove scripts for rpm and deb packages (#5150)

This commit is contained in:
Lucas Manuel Rodriguez
2022-04-19 09:32:47 -03:00
committed by GitHub
parent 5cb64edae5
commit 2e7bbf960a
3 changed files with 37 additions and 0 deletions
+1
View File
@@ -185,6 +185,7 @@ jobs:
sudo systemctl status orbit.service || true
sleep 1
done
sudo apt remove fleet-osquery -y
orbit-windows-build:
timeout-minutes: 15
+1
View File
@@ -0,0 +1 @@
* Add cleanup on `deb`/`rpm` uninstall.
+35
View File
@@ -80,6 +80,14 @@ func buildNFPM(opt Options, pkger nfpm.Packager) (string, error) {
if err := writePostInstall(opt, postInstallPath); err != nil {
return "", fmt.Errorf("write postinstall script: %w", err)
}
preRemovePath := filepath.Join(tmpDir, "preremove.sh")
if err := writePreRemove(opt, preRemovePath); err != nil {
return "", fmt.Errorf("write preremove script: %w", err)
}
postRemovePath := filepath.Join(tmpDir, "postremove.sh")
if err := writePostRemove(opt, postRemovePath); err != nil {
return "", fmt.Errorf("write postremove script: %w", err)
}
if opt.FleetCertificate != "" {
if err := writeCertificate(opt, orbitRoot); err != nil {
@@ -141,6 +149,8 @@ func buildNFPM(opt Options, pkger nfpm.Packager) (string, error) {
Contents: contents,
Scripts: nfpm.Scripts{
PostInstall: postInstallPath,
PreRemove: preRemovePath,
PostRemove: postRemovePath,
},
},
}
@@ -260,3 +270,28 @@ func writePostInstall(opt Options, path string) error {
return nil
}
func writePreRemove(opt Options, path string) error {
if err := ioutil.WriteFile(path, []byte(`#!/bin/sh
set -e
systemctl stop orbit.service
systemctl disable orbit.service
`), constant.DefaultFileMode); err != nil {
return fmt.Errorf("write file: %w", err)
}
return nil
}
func writePostRemove(opt Options, path string) error {
if err := ioutil.WriteFile(path, []byte(`#!/bin/sh
rm -rf /var/lib/orbit /var/log/orbit /usr/local/bin/orbit /etc/default/orbit /usr/lib/systemd/system/orbit.service
`), constant.DefaultFileMode); err != nil {
return fmt.Errorf("write file: %w", err)
}
return nil
}