Implements pre/post install scripts

This commit is contained in:
Stephen McQuay 2018-03-05 23:26:16 -08:00
parent 56eebc8c34
commit 509433dd3d
Signed by untrusted user: sm
GPG Key ID: 4E4B72F479BA3CE5

View File

@ -10,6 +10,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
@ -69,6 +70,14 @@ func Install(root string, pkgs []string) error {
} }
return errors.Wrap(err, "verifying pkg contents") return errors.Wrap(err, "verifying pkg contents")
} }
if err := script(root, m, "pre-install"); err != nil {
return errors.Wrap(err, "pre-install")
}
if err := script(root, m, "post-install"); err != nil {
return errors.Wrap(err, "pre-install")
}
} }
return errors.New("NYI") return errors.New("NYI")
} }
@ -252,3 +261,14 @@ type close struct {
func (close) Close() error { func (close) Close() error {
return nil return nil
} }
func script(root string, m pm.Meta, name string) error {
bin := filepath.Join(root, installed, string(m.Name), "bin", name)
if !fs.Exists(bin) {
return nil
}
cmd := exec.Command(bin)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}