7 Commits
15 changed files with 109 additions and 129 deletions
+38
View File
@@ -0,0 +1,38 @@
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
ifeq ($(BINDIR),)
BINDIR := $(PREFIX)/bin
endif
ifeq ($(SYSCONFDIR),)
SYSCONFDIR := $(PREFIX)/etc
endif
ifeq ($(GO),)
GO := $(shell type -a -P go | head -n 1)
endif
build:
mkdir -p build
$(GO) build -ldflags "-w" -o build/bpm gitlab.com/bubble-package-manager/bpm
install: build/bpm config/
mkdir -p $(DESTDIR)$(BINDIR)
mkdir -p $(DESTDIR)$(SYSCONFDIR)
cp build/bpm $(DESTDIR)$(BINDIR)/bpm
cp config/bpm.conf $(DESTDIR)$(SYSCONFDIR)/bpm.conf
compress: build/bpm config/
mkdir -p bpm/$(BINDIR)
mkdir -p bpm/$(SYSCONFDIR)
cp build/bpm bpm/$(BINDIR)/bpm
cp config/bpm.conf bpm/$(SYSCONFDIR)/bpm.conf
tar --owner=root --group=root -czf bpm.tar.gz bpm
rm -r bpm
run: build/bpm
build/bpm
clean:
rm -r build/
.PHONY: build
+9 -8
View File
@@ -15,15 +15,16 @@ BPM is still in very early development. It should not be installed on any system
## Build from source ## Build from source
BPM requires go 1.22 or above to be built properly - Download `go` from your package manager or from the go website
- Download `make` from your package manager
```sh - Run the following command to compile the project
git clone https://gitlab.com/bubble-package-manager/bpm.git ```
cd bpm make
mkdir build ```
go build -o ./build/bpm capcreepergr.me/bpm - Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location
```
make install PREFIX=/usr SYSCONFDIR=/etc
``` ```
You are now able to copy the executable in the ./build directory in a VM or container's /usr/bin/ directory
## How to use ## How to use
+6 -1
View File
@@ -8,11 +8,16 @@ import (
type BPMConfigStruct struct { type BPMConfigStruct struct {
CompilationEnv []string `yaml:"compilation_env"` CompilationEnv []string `yaml:"compilation_env"`
SilentCompilation bool `yaml:"silent_compilation"` SilentCompilation bool `yaml:"silent_compilation"`
BinaryOutputDir string `yaml:"binary_output_dir"`
CompilationDir string `yaml:"compilation_dir"`
} }
var BPMConfig BPMConfigStruct = BPMConfigStruct{ var BPMConfig BPMConfigStruct = BPMConfigStruct{
CompilationEnv: make([]string, 0), CompilationEnv: make([]string, 0),
SilentCompilation: false} SilentCompilation: false,
BinaryOutputDir: "/var/lib/bpm/compiled/",
CompilationDir: "/var/tmp/",
}
func ReadConfig() { func ReadConfig() {
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) { if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
+30 -71
View File
@@ -481,6 +481,21 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
return nil, files return nil, files
} }
func isSplitPackage(filename string) bool {
pkgInfo, err := ReadPackage(filename)
if err != nil {
return false
}
if pkgInfo.Type != "source" {
return false
}
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("test $(tar -tf %s | grep '^pkg.info' | wc -l) -eq 1", filename))
if err := cmd.Run(); err == nil {
return false
}
return true
}
func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) { func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
var files []string var files []string
if !IsPackageInstalled(pkgInfo.Name, rootDir) { if !IsPackageInstalled(pkgInfo.Name, rootDir) {
@@ -505,7 +520,7 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
} }
tr := tar.NewReader(archive) tr := tar.NewReader(archive)
temp := "/var/tmp/bpm_source-" + pkgInfo.Name temp := path.Join(BPMConfig.CompilationDir, "bpm_source-"+pkgInfo.Name)
err = os.RemoveAll(temp) err = os.RemoveAll(temp)
if err != nil { if err != nil {
return err, nil return err, nil
@@ -668,7 +683,6 @@ if [ $? -ne 0 ]; then
echo "Failed to run package() function in source.sh" echo "Failed to run package() function in source.sh"
fi fi
` `
err = os.WriteFile(path.Join(temp, "run.sh"), []byte(runScript), 0644) err = os.WriteFile(path.Join(temp, "run.sh"), []byte(runScript), 0644)
if err != nil { if err != nil {
return err, nil return err, nil
@@ -683,6 +697,8 @@ fi
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 65534, Gid: 65534} cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 65534, Gid: 65534}
cmd.Dir = temp cmd.Dir = temp
cmd.Env = os.Environ() cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "USER=nobody")
cmd.Env = append(cmd.Env, "HOME="+temp)
err = os.Mkdir(path.Join(temp, "source"), 0755) err = os.Mkdir(path.Join(temp, "source"), 0755)
if err != nil { if err != nil {
@@ -827,7 +843,7 @@ fi
return err, nil return err, nil
} }
if binaryPkgFromSrc { if binaryPkgFromSrc {
compiledDir := path.Join(rootDir, "var/lib/bpm/compiled/") compiledDir := path.Join(BPMConfig.BinaryOutputDir)
err = os.MkdirAll(compiledDir, 0755) err = os.MkdirAll(compiledDir, 0755)
compiledInfo := PackageInfo{} compiledInfo := PackageInfo{}
compiledInfo = *pkgInfo compiledInfo = *pkgInfo
@@ -922,6 +938,9 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
} }
files = i files = i
} else if pkgInfo.Type == "source" { } else if pkgInfo.Type == "source" {
if isSplitPackage(filename) {
return errors.New("BPM is unable to install split source packages")
}
err, i := compilePackage(pkgInfo, filename, rootDir, binaryPkgFromSrc, skipCheck, keepTempDir) err, i := compilePackage(pkgInfo, filename, rootDir, binaryPkgFromSrc, skipCheck, keepTempDir)
if err != nil { if err != nil {
return err return err
@@ -1126,80 +1145,20 @@ func GetSourceScript(filename string) (string, error) {
} }
func CheckDependencies(pkgInfo *PackageInfo, rootDir string) []string { func CheckDependencies(pkgInfo *PackageInfo, rootDir string) []string {
unresolved := make([]string, len(pkgInfo.Depends)) var unresolved []string
copy(unresolved, pkgInfo.Depends) for _, dependency := range pkgInfo.Depends {
installedDir := path.Join(rootDir, "var/lib/bpm/installed/") if !IsPackageInstalled(dependency, rootDir) {
if _, err := os.Stat(installedDir); err != nil { unresolved = append(unresolved, dependency)
return nil
}
items, err := os.ReadDir(installedDir)
if err != nil {
return nil
}
for _, item := range items {
if !item.IsDir() {
continue
}
_, err := os.Stat(path.Join(installedDir, item.Name(), "/info"))
if err != nil {
return nil
}
bs, err := os.ReadFile(path.Join(installedDir, item.Name(), "/info"))
if err != nil {
return nil
}
info, err := ReadPackageInfo(string(bs), false)
if err != nil {
return nil
}
if slices.Contains(unresolved, info.Name) {
unresolved = stringSliceRemove(unresolved, info.Name)
}
for _, prov := range info.Provides {
if slices.Contains(unresolved, prov) {
unresolved = stringSliceRemove(unresolved, prov)
}
} }
} }
return unresolved return unresolved
} }
func CheckMakeDependencies(pkgInfo *PackageInfo, rootDir string) []string { func CheckMakeDependencies(pkgInfo *PackageInfo, rootDir string) []string {
unresolved := make([]string, len(pkgInfo.MakeDepends)) var unresolved []string
copy(unresolved, pkgInfo.MakeDepends) for _, dependency := range pkgInfo.MakeDepends {
installedDir := path.Join(rootDir, "var/lib/bpm/installed/") if !IsPackageInstalled(dependency, "/") {
if _, err := os.Stat(installedDir); err != nil { unresolved = append(unresolved, dependency)
return nil
}
items, err := os.ReadDir(installedDir)
if err != nil {
return nil
}
for _, item := range items {
if !item.IsDir() {
continue
}
_, err := os.Stat(path.Join(installedDir, item.Name(), "/info"))
if err != nil {
return nil
}
bs, err := os.ReadFile(path.Join(installedDir, item.Name(), "/info"))
if err != nil {
return nil
}
info, err := ReadPackageInfo(string(bs), false)
if err != nil {
return nil
}
if slices.Contains(unresolved, info.Name) {
unresolved = stringSliceRemove(unresolved, info.Name)
}
for _, prov := range info.Provides {
if slices.Contains(unresolved, prov) {
unresolved = stringSliceRemove(unresolved, prov)
}
} }
} }
return unresolved return unresolved
+4
View File
@@ -0,0 +1,4 @@
compilation_env: []
silent_compilation: false
compilation_dir: "/var/tmp/"
binary_output_dir: "/var/lib/bpm/compiled/"
+1 -1
View File
@@ -1,4 +1,4 @@
module capcreepergr.me/bpm module gitlab.com/bubble-package-manager/bpm
go 1.22 go 1.22
+21 -11
View File
@@ -2,9 +2,9 @@ package main
import ( import (
"bufio" "bufio"
"capcreepergr.me/bpm/bpm_utils"
"flag" "flag"
"fmt" "fmt"
"gitlab.com/bubble-package-manager/bpm/bpm_utils"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@@ -17,7 +17,7 @@ import (
/* A simple-to-use package manager */ /* A simple-to-use package manager */
/* ---------------------------------- */ /* ---------------------------------- */
var bpmVer = "0.3.0" var bpmVer = "0.3.2"
var subcommand = "help" var subcommand = "help"
var subcommandArgs []string var subcommandArgs []string
@@ -135,10 +135,16 @@ func resolveCommand() {
if err != nil { if err != nil {
log.Fatalf("Could not read package\nError: %s\n", err) log.Fatalf("Could not read package\nError: %s\n", err)
} }
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true)) if !yesAll {
fmt.Println("----------------") fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
fmt.Println("----------------")
}
verb := "install" verb := "install"
if pkgInfo.Type == "source" { if pkgInfo.Type == "source" {
if _, err := os.Stat("/bin/fakeroot"); os.IsNotExist(err) {
fmt.Printf("Skipping... cannot %s package (%s) due to fakeroot not being installed")
continue
}
verb = "build" verb = "build"
} }
if !forceInstall { if !forceInstall {
@@ -313,19 +319,21 @@ func printHelp() {
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 [-R] | shows information on an installed package") fmt.Println("-> bpm info [-R] | shows information on an installed package")
fmt.Println(" -R=<root_path> lets you define the root path which will be used") fmt.Println(" -R=<path> lets you define the root path which will be used")
fmt.Println("-> bpm list [-R, -c, -n] | lists all installed packages") fmt.Println("-> bpm list [-R, -c, -n] | lists all installed packages")
fmt.Println(" -R=<root_path> lets you define the root path which will be used") fmt.Println(" -R=<path> lets you define the root path which will be used")
fmt.Println(" -c lists the amount of installed packages") fmt.Println(" -c lists the amount of installed packages")
fmt.Println(" -n lists only the names of installed packages") fmt.Println(" -n lists only the names of installed packages")
fmt.Println("-> bpm install [-R, -y, -f, -b] <files...> | installs the following files") fmt.Println("-> bpm install [-R, -y, -f, -o, -c, -b, -k] <files...> | installs the following files")
fmt.Println(" -R=<root_path> lets you define the root path which will be used") fmt.Println(" -R=<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(" -o=<path> set the binary package output directory (defaults to /var/lib/bpm/compiled)")
fmt.Println(" -k keeps the temp directory created by BPM after source package installation") fmt.Println(" -c=<path> set the compilation directory (defaults to /var/tmp)")
fmt.Println(" -b creates a binary package from a source package after compilation and saves it in the binary package output directory")
fmt.Println(" -k keeps the compilation directory created by BPM after source package installation")
fmt.Println("-> bpm remove [-R, -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(" -R=<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 file [-R] <files...> | shows what packages the following packages are managed by") 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(" -R=<root_path> lets you define the root path which will be used")
@@ -347,6 +355,8 @@ func resolveFlags() {
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError) installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root") installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts") installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
installFlagSet.StringVar(&bpm_utils.BPMConfig.BinaryOutputDir, "o", bpm_utils.BPMConfig.BinaryOutputDir, "Set the binary output directory")
installFlagSet.StringVar(&bpm_utils.BPMConfig.CompilationDir, "c", bpm_utils.BPMConfig.CompilationDir, "Set the compilation directory")
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package") installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation") installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation") installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
Binary file not shown.
@@ -1,3 +0,0 @@
---
compilation_env: []
silent_compilation: false
Binary file not shown.
@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 CapCreeperGR
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-8
View File
@@ -1,8 +0,0 @@
name: bpm
description: The Bubble Package Manager
version: 0.3.0
url: https://gitlab.com/bubble-package-manager/bpm/
license: GPL3
architecture: x86_64
type: binary
keep: etc/bpm.conf
Binary file not shown.
Binary file not shown.
-5
View File
@@ -1,5 +0,0 @@
name: hello
description: A simple hello world program
version: 1.0
architecture: x86_64
type: binary