mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8fc1b902c | ||
|
|
6472a113cf | ||
|
|
d3f1c52202 |
+51
-46
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -372,18 +371,39 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(path.Join("source.sh")); os.IsNotExist(err) {
|
if _, err := os.Stat(path.Join(temp, "source.sh")); os.IsNotExist(err) {
|
||||||
return errors.New("source.sh file could not be found in the temporary build directory")
|
return errors.New("source.sh file could not be found in the temporary build directory")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Running source.sh file...")
|
fmt.Println("Running source.sh file...")
|
||||||
cmd := exec.Command("/usr/bin/sh", "source.sh")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := exec.Command("/bin/bash", "-e", "source.sh")
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Dir = temp
|
cmd.Dir = temp
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
||||||
|
depends := make([]string, len(pkgInfo.Depends))
|
||||||
|
copy(depends, pkgInfo.Depends)
|
||||||
|
for i := 0; i < len(depends); i++ {
|
||||||
|
depends[i] = fmt.Sprintf("\"%s\"", depends[i])
|
||||||
|
}
|
||||||
|
makeDepends := make([]string, len(pkgInfo.MakeDepends))
|
||||||
|
copy(makeDepends, pkgInfo.MakeDepends)
|
||||||
|
for i := 0; i < len(makeDepends); i++ {
|
||||||
|
makeDepends[i] = fmt.Sprintf("\"%s\"", makeDepends[i])
|
||||||
|
}
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DEPENDS=(%s)", strings.Join(depends, " ")))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_MAKE_DEPENDS=(%s)", strings.Join(makeDepends, " ")))
|
||||||
|
cmd.Env = append(cmd.Env, "BPM_PKG_TYPE=source")
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -479,7 +499,7 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sed := fmt.Sprintf("s/%s/files/", strings.Replace(strings.TrimPrefix(path.Join(temp, "/output/"), "/"), "/", `\/`, -1))
|
sed := fmt.Sprintf("s/%s/files/", strings.Replace(strings.TrimPrefix(path.Join(temp, "/output/"), "/"), "/", `\/`, -1))
|
||||||
cmd := exec.Command("/usr/bin/tar", "-czvf", compiledInfo.Name+".bpm", "pkg.info", path.Join(temp, "/output/"), "--transform", sed)
|
cmd := exec.Command("/usr/bin/tar", "-czvf", compiledInfo.Name+"-"+compiledInfo.Version+".bpm", "pkg.info", path.Join(temp, "/output/"), "--transform", sed)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@@ -571,7 +591,33 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
if len(filesDiff) != 0 {
|
if len(filesDiff) != 0 {
|
||||||
fmt.Println("Removing obsolete files")
|
fmt.Println("Removing obsolete files")
|
||||||
for _, f := range filesDiff {
|
for _, f := range filesDiff {
|
||||||
fmt.Println("Removing: " + path.Join(installedDir, f))
|
f = path.Join(installDir, f)
|
||||||
|
stat, err := os.Lstat(f)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if stat.IsDir() {
|
||||||
|
dir, err := os.ReadDir(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(dir) == 0 {
|
||||||
|
fmt.Println("Removing: " + f)
|
||||||
|
err := os.Remove(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Removing: " + f)
|
||||||
|
err := os.Remove(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -828,44 +874,3 @@ func RemovePackage(pkg, rootDir string) error {
|
|||||||
fmt.Println("Removing: " + pkgDir)
|
fmt.Println("Removing: " + pkgDir)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FixInstalledPackages(rootDir string) (map[string]error, int) {
|
|
||||||
var errs map[string]error
|
|
||||||
totalFixed := 0
|
|
||||||
pkgs, err := GetInstalledPackages(rootDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not check if installed package info files are formatted correctly\nError: %s", err.Error())
|
|
||||||
}
|
|
||||||
for _, pkg := range pkgs {
|
|
||||||
fixed := false
|
|
||||||
pkgInfo := GetPackageInfo(pkg, "/", true)
|
|
||||||
if pkgInfo.Name == "" {
|
|
||||||
errs[pkg] = errors.New("this package contains no name")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if pkgInfo.Description == "" {
|
|
||||||
pkgInfo.Description = "Default Description"
|
|
||||||
fixed = true
|
|
||||||
}
|
|
||||||
if pkgInfo.Version == "" {
|
|
||||||
errs[pkg] = errors.New("this package contains no version")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if pkgInfo.Arch == "" {
|
|
||||||
pkgInfo.Arch = GetArch()
|
|
||||||
fixed = true
|
|
||||||
}
|
|
||||||
if pkgInfo.Type == "" {
|
|
||||||
errs[pkg] = errors.New("this package contains no type")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fixed {
|
|
||||||
totalFixed++
|
|
||||||
}
|
|
||||||
err := setPackageInfo(pkg, CreateInfoFile(*pkgInfo), rootDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not check if installed package info files are formatted correctly\nError: %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return errs, totalFixed
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.1.2"
|
var bpmVer = "0.1.5"
|
||||||
|
|
||||||
var subcommand = "help"
|
var subcommand = "help"
|
||||||
var subcommandArgs []string
|
var subcommandArgs []string
|
||||||
@@ -43,7 +45,7 @@ const (
|
|||||||
list
|
list
|
||||||
install
|
install
|
||||||
remove
|
remove
|
||||||
cleanup
|
file
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCommandType() commandType {
|
func getCommandType() commandType {
|
||||||
@@ -58,12 +60,11 @@ func getCommandType() commandType {
|
|||||||
return install
|
return install
|
||||||
case "remove":
|
case "remove":
|
||||||
return remove
|
return remove
|
||||||
case "cleanup":
|
case "file":
|
||||||
return cleanup
|
return file
|
||||||
default:
|
default:
|
||||||
return help
|
return help
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveCommand() {
|
func resolveCommand() {
|
||||||
@@ -251,6 +252,53 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
||||||
}
|
}
|
||||||
|
case file:
|
||||||
|
files := subcommandArgs
|
||||||
|
if len(files) == 0 {
|
||||||
|
fmt.Println("No files were given to get which packages manage it")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
absFile, err := filepath.Abs(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get absolute path of %s", file)
|
||||||
|
}
|
||||||
|
stat, err := os.Stat(absFile)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Fatalf(absFile + " does not exist!")
|
||||||
|
}
|
||||||
|
pkgs, err := bpm_utils.GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(absFile, rootDir) {
|
||||||
|
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||||
|
}
|
||||||
|
absFile, err = filepath.Rel(rootDir, absFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||||
|
}
|
||||||
|
absFile = strings.TrimPrefix(absFile, "/")
|
||||||
|
if stat.IsDir() {
|
||||||
|
absFile = absFile + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
var pkgList []string
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if slices.Contains(bpm_utils.GetPackageFiles(pkg, rootDir), absFile) {
|
||||||
|
pkgList = append(pkgList, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(pkgList) == 0 {
|
||||||
|
fmt.Println(absFile + " is not managed by any packages")
|
||||||
|
} else {
|
||||||
|
fmt.Println(absFile + " is managed by the following packages:")
|
||||||
|
for _, pkg := range pkgList {
|
||||||
|
fmt.Println("- " + pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
printHelp()
|
printHelp()
|
||||||
}
|
}
|
||||||
@@ -263,18 +311,23 @@ func printHelp() {
|
|||||||
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
||||||
fmt.Println("\033[1m\\ Command List /\033[0m")
|
fmt.Println("\033[1m\\ Command List /\033[0m")
|
||||||
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
||||||
fmt.Println("-> bpm info | shows information on an installed package")
|
fmt.Println("-> bpm info [-R] | shows information on an installed package")
|
||||||
fmt.Println("-> bpm list [-n, -l] | lists all installed packages")
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
|
fmt.Println("-> bpm list [-R, -n, -l] | lists all installed packages")
|
||||||
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -n shows the number of packages")
|
fmt.Println(" -n shows the number of packages")
|
||||||
fmt.Println(" -l lists package names only")
|
fmt.Println(" -l lists package names only")
|
||||||
fmt.Println("-> bpm install [-y, -f, -b] <files...> | installs the following files")
|
fmt.Println("-> bpm install [-R, -y, -f, -b] <files...> | installs the following files")
|
||||||
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
fmt.Println(" -f skips dependency and architecture checking")
|
fmt.Println(" -f skips dependency and architecture checking")
|
||||||
fmt.Println(" -b creates a binary package for a source package after compilation and saves it in /var/lib/bpm/compiled")
|
fmt.Println(" -b creates a binary package for a source package after compilation and saves it in /var/lib/bpm/compiled")
|
||||||
fmt.Println(" -k keeps the temp directory created by BPM after source package installation")
|
fmt.Println(" -k keeps the temp directory created by BPM after source package installation")
|
||||||
fmt.Println("-> bpm remove [-y] <packages...> | removes the following packages")
|
fmt.Println("-> bpm remove [-R, -y] <packages...> | removes the following packages")
|
||||||
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
//fmt.Println("-> bpm cleanup | removes all unneeded dependencies")
|
fmt.Println("-> bpm file [-R] <files...> | shows what packages the following packages are managed by")
|
||||||
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
fmt.Println("\033[1m----------------\033[0m")
|
fmt.Println("\033[1m----------------\033[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,6 +356,11 @@ func resolveFlags() {
|
|||||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
removeFlagSet.Usage = printHelp
|
removeFlagSet.Usage = printHelp
|
||||||
|
// File flags
|
||||||
|
// Remove flags
|
||||||
|
fileFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||||
|
fileFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
fileFlagSet.Usage = printHelp
|
||||||
if len(os.Args[1:]) <= 0 {
|
if len(os.Args[1:]) <= 0 {
|
||||||
subcommand = "help"
|
subcommand = "help"
|
||||||
} else {
|
} else {
|
||||||
@@ -332,47 +390,12 @@ func resolveFlags() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
subcommandArgs = removeFlagSet.Args()
|
subcommandArgs = removeFlagSet.Args()
|
||||||
|
} else if getCommandType() == file {
|
||||||
|
err := fileFlagSet.Parse(subcommandArgs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subcommandArgs = fileFlagSet.Args()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func resolveFlags() ([]string, int) {
|
|
||||||
flags := getArgs()[1:]
|
|
||||||
var ret []string
|
|
||||||
for _, flag := range flags {
|
|
||||||
if strings.HasPrefix(flag, "-") {
|
|
||||||
f := strings.TrimPrefix(flag, "-")
|
|
||||||
switch getCommandType() {
|
|
||||||
default:
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
case list:
|
|
||||||
v := [...]string{"l", "n"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
case install:
|
|
||||||
v := [...]string{"y", "f", "b", "k"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
case remove:
|
|
||||||
v := [...]string{"y", "r"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
case info:
|
|
||||||
v := [...]string{"r"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret, len(ret)
|
|
||||||
}*/
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
name: bpm
|
name: bpm
|
||||||
description: The Bubble Package Manager
|
description: The Bubble Package Manager
|
||||||
version: 0.1.2
|
version: 0.1.5
|
||||||
url: https://gitlab.com/bubble-package-manager/bpm/
|
url: https://gitlab.com/bubble-package-manager/bpm/
|
||||||
license: GPL3
|
license: GPL3
|
||||||
architecture: x86_64
|
architecture: x86_64
|
||||||
|
|||||||
Reference in New Issue
Block a user