Browse Source

Add pre/post install cmds to manifest yml

feature/create-install-pkgs
Tovi Jaeschke-Rogers 3 years ago
parent
commit
28e148b5b5
5 changed files with 38 additions and 5 deletions
  1. +1
    -0
      .gitignore
  2. +28
    -1
      Client/Package/InstallPackage.go
  3. +6
    -4
      Client/Package/Manifest.go
  4. +1
    -0
      Variables/Variables.go
  5. +2
    -0
      notes.txt

+ 1
- 0
.gitignore View File

@ -2,3 +2,4 @@
*.tar
*.tar.gz
tjpkg
test.go

+ 28
- 1
Client/Package/InstallPackage.go View File

@ -4,12 +4,30 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"PackageManager/Archive"
"PackageManager/Client/Database"
"PackageManager/Variables"
)
func runInstallCmd(cmdStr string) error {
var (
cmd *exec.Cmd
)
if cmdStr == "" {
return nil
}
cmd = exec.Command("/bin/sh", "-c", cmdStr)
cmd.Dir = Variables.RootDir
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func CheckPackageDependancies(deps map[string]string) ([]int64, error) {
var (
name, version string
@ -64,16 +82,25 @@ func InstallPackage(pkgs []string) error {
if !Variables.IgnoreDepsCheck {
depIds, e = CheckPackageDependancies(manifest.Dependancies)
if e != nil {
// TODO: Search for package on error
return e
}
}
e = runInstallCmd(manifest.PreInstallCmds)
if e != nil {
return e
}
e = Archive.ExtractArchive(pkg, Variables.RootDir)
if e != nil {
return e
}
e = runInstallCmd(manifest.PostInstallCmds)
if e != nil {
return e
}
e = Database.InsertPackage(manifest.Name, manifest.Version, depIds)
if e != nil {
return e


+ 6
- 4
Client/Package/Manifest.go View File

@ -5,10 +5,12 @@ import (
)
type Manifest struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Symlinks map[string]string `yaml:"symlinks,flow"`
Dependancies map[string]string `yaml:"dependancies,flow"`
Name string `yaml:"name"`
Version string `yaml:"version"`
Symlinks map[string]string `yaml:"symlinks,flow"`
Dependancies map[string]string `yaml:"dependancies,flow"`
PreInstallCmds string `yaml:"pre_install_cmds"`
PostInstallCmds string `yaml:"post_install_cmds"`
}
func ParseManifestFile(manifest string) (Manifest, error) {


+ 1
- 0
Variables/Variables.go View File

@ -57,6 +57,7 @@ var (
IgnoreRegexPaths []string = []string{
os.Args[0],
"^/usr/share/info/dir$",
"^/swapfile$",
"^/etc/passwd$",
"^/etc/passwd-$",


+ 2
- 0
notes.txt View File

@ -0,0 +1,2 @@
Ncurses needs a post install command
ln -sf ../share/terminfo usr/lib/terminfo

Loading…
Cancel
Save