Added 'Binary Output' and 'Compilation Directory' config options and parameters, removed test packages and added other small improvements

This commit is contained in:
CapCreeperGR 2024-07-07 22:02:57 +03:00
parent 124802ecc1
commit f9ef17cd66
11 changed files with 26 additions and 48 deletions

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) {

View File

@ -505,7 +505,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
@ -683,6 +683,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 +829,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

24
main.go
View File

@ -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.1"
var subcommand = "help" var subcommand = "help"
var subcommandArgs []string var subcommandArgs []string
@ -139,6 +139,10 @@ func resolveCommand() {
fmt.Println("----------------") 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 +317,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 +353,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.

View File

@ -1,3 +0,0 @@
---
compilation_env: []
silent_compilation: false

View File

@ -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.

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.

View File

@ -1,5 +0,0 @@
name: hello
description: A simple hello world program
version: 1.0
architecture: x86_64
type: binary