mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 02:26:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
721414679d | ||
|
|
c20e74203c | ||
|
|
23f9a13939 | ||
|
|
1d41236740 | ||
|
|
e445863dca | ||
|
|
f9ef17cd66 | ||
|
|
124802ecc1 |
@@ -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
|
||||
@@ -15,15 +15,16 @@ BPM is still in very early development. It should not be installed on any system
|
||||
|
||||
## Build from source
|
||||
|
||||
BPM requires go 1.22 or above to be built properly
|
||||
|
||||
```sh
|
||||
git clone https://gitlab.com/bubble-package-manager/bpm.git
|
||||
cd bpm
|
||||
mkdir build
|
||||
go build -o ./build/bpm capcreepergr.me/bpm
|
||||
- Download `go` from your package manager or from the go website
|
||||
- Download `make` from your package manager
|
||||
- Run the following command to compile the project
|
||||
```
|
||||
make
|
||||
```
|
||||
- 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
|
||||
|
||||
|
||||
+6
-1
@@ -8,11 +8,16 @@ import (
|
||||
type BPMConfigStruct struct {
|
||||
CompilationEnv []string `yaml:"compilation_env"`
|
||||
SilentCompilation bool `yaml:"silent_compilation"`
|
||||
BinaryOutputDir string `yaml:"binary_output_dir"`
|
||||
CompilationDir string `yaml:"compilation_dir"`
|
||||
}
|
||||
|
||||
var BPMConfig BPMConfigStruct = BPMConfigStruct{
|
||||
CompilationEnv: make([]string, 0),
|
||||
SilentCompilation: false}
|
||||
SilentCompilation: false,
|
||||
BinaryOutputDir: "/var/lib/bpm/compiled/",
|
||||
CompilationDir: "/var/tmp/",
|
||||
}
|
||||
|
||||
func ReadConfig() {
|
||||
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||
|
||||
+30
-71
@@ -481,6 +481,21 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
|
||||
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) {
|
||||
var files []string
|
||||
if !IsPackageInstalled(pkgInfo.Name, rootDir) {
|
||||
@@ -505,7 +520,7 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
|
||||
}
|
||||
tr := tar.NewReader(archive)
|
||||
|
||||
temp := "/var/tmp/bpm_source-" + pkgInfo.Name
|
||||
temp := path.Join(BPMConfig.CompilationDir, "bpm_source-"+pkgInfo.Name)
|
||||
err = os.RemoveAll(temp)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
@@ -668,7 +683,6 @@ if [ $? -ne 0 ]; then
|
||||
echo "Failed to run package() function in source.sh"
|
||||
fi
|
||||
`
|
||||
|
||||
err = os.WriteFile(path.Join(temp, "run.sh"), []byte(runScript), 0644)
|
||||
if err != nil {
|
||||
return err, nil
|
||||
@@ -683,6 +697,8 @@ fi
|
||||
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 65534, Gid: 65534}
|
||||
cmd.Dir = temp
|
||||
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)
|
||||
if err != nil {
|
||||
@@ -827,7 +843,7 @@ fi
|
||||
return err, nil
|
||||
}
|
||||
if binaryPkgFromSrc {
|
||||
compiledDir := path.Join(rootDir, "var/lib/bpm/compiled/")
|
||||
compiledDir := path.Join(BPMConfig.BinaryOutputDir)
|
||||
err = os.MkdirAll(compiledDir, 0755)
|
||||
compiledInfo := PackageInfo{}
|
||||
compiledInfo = *pkgInfo
|
||||
@@ -922,6 +938,9 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
||||
}
|
||||
files = i
|
||||
} 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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1126,80 +1145,20 @@ func GetSourceScript(filename string) (string, error) {
|
||||
}
|
||||
|
||||
func CheckDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
||||
unresolved := make([]string, len(pkgInfo.Depends))
|
||||
copy(unresolved, pkgInfo.Depends)
|
||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||
if _, err := os.Stat(installedDir); err != nil {
|
||||
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)
|
||||
}
|
||||
var unresolved []string
|
||||
for _, dependency := range pkgInfo.Depends {
|
||||
if !IsPackageInstalled(dependency, rootDir) {
|
||||
unresolved = append(unresolved, dependency)
|
||||
}
|
||||
}
|
||||
return unresolved
|
||||
}
|
||||
|
||||
func CheckMakeDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
||||
unresolved := make([]string, len(pkgInfo.MakeDepends))
|
||||
copy(unresolved, pkgInfo.MakeDepends)
|
||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||
if _, err := os.Stat(installedDir); err != nil {
|
||||
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)
|
||||
}
|
||||
var unresolved []string
|
||||
for _, dependency := range pkgInfo.MakeDepends {
|
||||
if !IsPackageInstalled(dependency, "/") {
|
||||
unresolved = append(unresolved, dependency)
|
||||
}
|
||||
}
|
||||
return unresolved
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
compilation_env: []
|
||||
silent_compilation: false
|
||||
compilation_dir: "/var/tmp/"
|
||||
binary_output_dir: "/var/lib/bpm/compiled/"
|
||||
@@ -1,4 +1,4 @@
|
||||
module capcreepergr.me/bpm
|
||||
module gitlab.com/bubble-package-manager/bpm
|
||||
|
||||
go 1.22
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"capcreepergr.me/bpm/bpm_utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"gitlab.com/bubble-package-manager/bpm/bpm_utils"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
/* A simple-to-use package manager */
|
||||
/* ---------------------------------- */
|
||||
|
||||
var bpmVer = "0.3.0"
|
||||
var bpmVer = "0.3.2"
|
||||
|
||||
var subcommand = "help"
|
||||
var subcommandArgs []string
|
||||
@@ -135,10 +135,16 @@ func resolveCommand() {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not read package\nError: %s\n", err)
|
||||
}
|
||||
if !yesAll {
|
||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
|
||||
fmt.Println("----------------")
|
||||
}
|
||||
verb := "install"
|
||||
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"
|
||||
}
|
||||
if !forceInstall {
|
||||
@@ -313,19 +319,21 @@ func printHelp() {
|
||||
fmt.Println("\033[1m---- Command List ----\033[0m")
|
||||
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(" -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(" -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(" -n lists only the names of installed packages")
|
||||
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("-> bpm install [-R, -y, -f, -o, -c, -b, -k] <files...> | installs the following files")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
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(" -k keeps the temp directory created by BPM after source package installation")
|
||||
fmt.Println(" -o=<path> set the binary package output directory (defaults to /var/lib/bpm/compiled)")
|
||||
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(" -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("-> 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")
|
||||
@@ -347,6 +355,8 @@ func resolveFlags() {
|
||||
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
||||
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
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(&skipCheck, "s", false, "Skip check function during 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.
|
||||
@@ -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.
@@ -1,5 +0,0 @@
|
||||
name: hello
|
||||
description: A simple hello world program
|
||||
version: 1.0
|
||||
architecture: x86_64
|
||||
type: binary
|
||||
Reference in New Issue
Block a user