Browse Source

WIP - Add install package

pull/1/head
Tovi Jaeschke-Rogers 4 years ago
parent
commit
300fadce37
4 changed files with 99 additions and 6 deletions
  1. +2
    -0
      Client/Package/CreatePackage.go
  2. +29
    -0
      Client/Package/InstallPackage.go
  3. +26
    -6
      Client/main.go
  4. +42
    -0
      Helper/CheckRoot.go

+ 2
- 0
Client/Package/CreatePackage.go View File

@ -129,6 +129,8 @@ func CreatePackage() error {
Filesystem.CopyFile(file, filepath.Join(tmpDir, file))
}
// TODO: Add dependancy management here
e = Archive.TarGzip(tmpDir, pkgNameVersion+".tar.gz")
if e != nil {
return e


+ 29
- 0
Client/Package/InstallPackage.go View File

@ -0,0 +1,29 @@
package Package
import (
"errors"
"fmt"
"os"
"PackageManager/Archive"
)
func InstallPackage(pkgs []string) error {
var (
pkg string
e error
)
for _, pkg = range pkgs {
_, e = os.Stat(pkg)
if os.IsNotExist(e) {
return errors.New(fmt.Sprintf("Invalid package %s", pkg))
}
}
for _, pkg = range pkgs {
e = Archive.UntarGzip(pkg, "/")
}
return nil
}

+ 26
- 6
Client/main.go View File

@ -8,18 +8,27 @@ import (
"PackageManager/Client/Filesystem"
"PackageManager/Client/Package"
"PackageManager/Color"
"PackageManager/Helper"
)
func main() {
var (
updateFilesytemFlag bool
updateFilesytemFlagLong bool
createPackageFlag bool
createPackageFlagLong bool
updateFilesytemFlag bool
updateFilesytemFlagLong bool
createPackageFlag bool
createPackageFlagLong bool
installLocalPackageFlag bool
installLocalPackageFlagLong bool
e error
)
e = Helper.CheckRoot()
if e != nil {
fmt.Println(Color.Fatal(e))
return
}
e = Database.InitDB()
if e != nil {
panic(e)
@ -27,10 +36,13 @@ func main() {
// Initialise flags
flag.BoolVar(&updateFilesytemFlag, "Uf", false, "Update filesystem database")
flag.BoolVar(&updateFilesytemFlagLong, "update-filesystem", false, "Update filesystem database")
flag.BoolVar(&updateFilesytemFlagLong, "-update-filesystem", false, "Update filesystem database")
flag.BoolVar(&createPackageFlag, "Cp", false, "Create package")
flag.BoolVar(&createPackageFlagLong, "create-package", false, "Create Package")
flag.BoolVar(&createPackageFlagLong, "-create-package", false, "Create Package")
flag.BoolVar(&installLocalPackageFlag, "Il", false, "Install local package")
flag.BoolVar(&installLocalPackageFlagLong, "-install-local-package", false, "Install local Package")
flag.Parse()
@ -51,6 +63,14 @@ func main() {
return
}
if installLocalPackageFlag || installLocalPackageFlagLong {
e = Package.InstallPackage(flag.Args())
if e != nil {
panic(e)
}
return
}
flag.Usage()
fmt.Println(Color.Fatal("Nothing to do"))


+ 42
- 0
Helper/CheckRoot.go View File

@ -0,0 +1,42 @@
package Helper
import (
"errors"
"os/exec"
"strconv"
)
func CheckRoot() error {
var (
cmd *exec.Cmd
output []byte
i int
e error
)
// TODO Make cross platform
cmd = exec.Command("id", "-u")
output, e = cmd.Output()
if e != nil {
return e
}
// output has trailing \n
// need to remove the \n
// otherwise it will cause error for strconv.Atoi
// log.Println(output[:len(output)-1])
// 0 = root, 501 = non-root user
i, e = strconv.Atoi(string(output[:len(output)-1]))
if e != nil {
return e
}
if i != 0 {
return errors.New("Please run as root")
}
return nil
}

Loading…
Cancel
Save