2 Commits
Author SHA1 Message Date
EnumDev b568d4db32 Added a way to include files in a source package that can be used during the compilation process (i.e patch files) 2024-04-16 21:04:36 +03:00
EnumDev 472d21a618 - Switched to using the flag system from the flag go package
- Added the -R flag which lets you choose a destination root directory
2024-04-13 09:23:03 +03:00
9 changed files with 316 additions and 199 deletions
+7 -6
View File
@@ -77,7 +77,7 @@ mkdir files
5) Either copy the bpm-create script from the bpm-utils test package into your /usr/local/bin directory or install the bpm-utils.bpm package 5) Either copy the bpm-create script from the bpm-utils test package into your /usr/local/bin directory or install the bpm-utils.bpm package
6) Run the following 6) Run the following
``` ```
bpm-create <filename_without_extension> bpm-create <filename.bpm>
``` ```
7) It's done! You now hopefully have a working BPM package! 7) It's done! You now hopefully have a working BPM package!
### Source Packages ### Source Packages
@@ -85,10 +85,11 @@ bpm-create <filename_without_extension>
``` ```
touch source.sh touch source.sh
``` ```
4) You are able to run bash code in this file. BPM will extract this file in a directory under /tmp and it will be ran there 4) If you would like to bundle patches or other files with your source package create a 'source-files' directory and place your files in there. They will be extracted to the same location as the source.sh file during compilation
5) Your goal is to download your program's source code with either git, wget, curl, etc. and put the binaries under a folder called 'output' in the root of the temp directory. There is a simple example script with helpful comments in the htop-src test package 5) You are able to run bash code in source.sh. BPM will extract this file in a directory under /tmp and it will be run there
6) As of this moment there is no script to automate package compression like for binary packages. You will need to create the archive manually 6) Your goal is to download your program's source code with either git, wget, curl, etc. and put the binaries under a folder called 'output' in the root of the temp directory. There is a simple example script with helpful comments in the htop-src test package
7) When you are done making your source.sh script run the following to create a package archive
``` ```
tar -czvf my_package-src.bpm pkg.info source.sh bpm-create <filename.bpm>
``` ```
7) That's it! Your source package should now be compiling correctly! 8) That's it! Your source package should now be compiling correctly!
+62 -14
View File
@@ -304,19 +304,6 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
} }
} }
} else if pkgInfo.Type == "source" { } else if pkgInfo.Type == "source" {
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if header.Name == "source.sh" {
bs, err := io.ReadAll(tr)
if err != nil {
return err
}
temp := "/var/tmp/bpm_source-" + pkgInfo.Name temp := "/var/tmp/bpm_source-" + pkgInfo.Name
err = os.RemoveAll(temp) err = os.RemoveAll(temp)
if err != nil { if err != nil {
@@ -327,10 +314,70 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
if err != nil { if err != nil {
return err return err
} }
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if strings.HasPrefix(header.Name, "source-files/") && header.Name != "source-files/" {
extractFilename := path.Join(temp, strings.TrimPrefix(header.Name, "source-files/"))
switch header.Typeflag {
case tar.TypeDir:
if err := os.Mkdir(extractFilename, 0755); err != nil {
if !os.IsExist(err) {
return err
}
} else {
fmt.Println("Creating Directory: " + extractFilename)
}
case tar.TypeReg:
err := os.Remove(extractFilename)
if err != nil && !os.IsNotExist(err) {
return err
}
outFile, err := os.Create(extractFilename)
fmt.Println("Creating File: " + extractFilename)
if err != nil {
return err
}
if _, err := io.Copy(outFile, tr); err != nil {
return err
}
if err := os.Chmod(extractFilename, header.FileInfo().Mode()); err != nil {
return err
}
err = outFile.Close()
if err != nil {
return err
}
case tar.TypeSymlink:
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
case tar.TypeLink:
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
default:
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename)
}
}
if header.Name == "source.sh" {
bs, err := io.ReadAll(tr)
if err != nil {
return err
}
err = os.WriteFile(path.Join(temp, "source.sh"), bs, 0644) err = os.WriteFile(path.Join(temp, "source.sh"), bs, 0644)
if err != nil { if err != nil {
return err return err
} }
}
}
if _, err := os.Stat(path.Join("source.sh")); os.IsNotExist(err) {
return errors.New("source.sh file could not be found in the temporary build directory")
}
if err != nil {
return err
}
fmt.Println("Running source.sh file...") fmt.Println("Running source.sh file...")
cmd := exec.Command("/usr/bin/sh", "source.sh") cmd := exec.Command("/usr/bin/sh", "source.sh")
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
@@ -453,7 +500,8 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
return err return err
} }
} }
} if len(files) == 0 {
return errors.New("no output files for source package. Cancelling package installation")
} }
} else { } else {
return errors.New("Unknown package type: " + pkgInfo.Type) return errors.New("Unknown package type: " + pkgInfo.Type)
+106 -45
View File
@@ -3,10 +3,10 @@ package main
import ( import (
"bufio" "bufio"
"capcreepergr.me/bpm/bpm_utils" "capcreepergr.me/bpm/bpm_utils"
"flag"
"fmt" "fmt"
"log" "log"
"os" "os"
"slices"
"strings" "strings"
) )
@@ -15,29 +15,25 @@ import (
/* A simple-to-use package manager */ /* A simple-to-use package manager */
/* ---------------------------------- */ /* ---------------------------------- */
var bpmVer = "0.1.0" var bpmVer = "0.1.2"
var subcommand = "help"
var subcommandArgs []string
// Flags
var rootDir = "/" var rootDir = "/"
var yesAll = false
var buildSource = false
var keepTempDir = false
var forceInstall = false
var pkgListNumbers = false
var pkgListNames = false
func main() { func main() {
/*errs, fixed := bpm_utils.FixInstalledPackages(rootDir) resolveFlags()
if len(errs) != 0 {
for pkg, err := range errs {
fmt.Printf("Package (%s) could not be read properly\nError: %s\n", pkg, err.Error())
}
fmt.Println("The aforementioned packages require manual fixing. Make sure their info files are valid in " + path.Join(rootDir, "var/lib/bpm/installed"))
os.Exit(1)
} else {
if fixed != 0 {
fmt.Println("Fixed " + strconv.Itoa(fixed) + " outdated package info files")
}
}*/
resolveCommand() resolveCommand()
} }
func getArgs() []string {
return os.Args[1:]
}
type commandType uint8 type commandType uint8
const ( const (
@@ -51,11 +47,7 @@ const (
) )
func getCommandType() commandType { func getCommandType() commandType {
if len(getArgs()) == 0 { switch subcommand {
return help
}
cmd := getArgs()[0]
switch cmd {
case "version": case "version":
return version return version
case "info": case "info":
@@ -77,12 +69,10 @@ func getCommandType() commandType {
func resolveCommand() { func resolveCommand() {
switch getCommandType() { switch getCommandType() {
case version: case version:
resolveFlags()
fmt.Println("Bubble Package Manager (BPM)") fmt.Println("Bubble Package Manager (BPM)")
fmt.Println("Version: " + bpmVer) fmt.Println("Version: " + bpmVer)
case info: case info:
_, i := resolveFlags() packages := subcommandArgs
packages := getArgs()[1+i:]
if len(packages) == 0 { if len(packages) == 0 {
fmt.Println("No packages were given") fmt.Println("No packages were given")
return return
@@ -99,7 +89,6 @@ func resolveCommand() {
} }
} }
case list: case list:
flags, _ := resolveFlags()
packages, err := bpm_utils.GetInstalledPackages(rootDir) packages, err := bpm_utils.GetInstalledPackages(rootDir)
if err != nil { if err != nil {
log.Fatalf("Could not get installed packages\nError: %s", err.Error()) log.Fatalf("Could not get installed packages\nError: %s", err.Error())
@@ -109,9 +98,9 @@ func resolveCommand() {
fmt.Println("No packages have been installed") fmt.Println("No packages have been installed")
return return
} }
if slices.Contains(flags, "n") { if pkgListNumbers {
fmt.Println(len(packages)) fmt.Println(len(packages))
} else if slices.Contains(flags, "l") { } else if pkgListNames {
for _, pkg := range packages { for _, pkg := range packages {
fmt.Println(pkg) fmt.Println(pkg)
} }
@@ -133,8 +122,7 @@ func resolveCommand() {
fmt.Println("This subcommand needs to be run with superuser permissions") fmt.Println("This subcommand needs to be run with superuser permissions")
os.Exit(0) os.Exit(0)
} }
flags, i := resolveFlags() files := subcommandArgs
files := getArgs()[1+i:]
if len(files) == 0 { if len(files) == 0 {
fmt.Println("No files were given to install") fmt.Println("No files were given to install")
return return
@@ -150,7 +138,7 @@ func resolveCommand() {
if pkgInfo.Type == "source" { if pkgInfo.Type == "source" {
verb = "build" verb = "build"
} }
if !slices.Contains(flags, "f") { if !forceInstall {
if pkgInfo.Arch != "any" && pkgInfo.Arch != bpm_utils.GetArch() { if pkgInfo.Arch != "any" && pkgInfo.Arch != bpm_utils.GetArch() {
fmt.Printf("skipping... cannot %s a package with a different architecture\n", verb) fmt.Printf("skipping... cannot %s a package with a different architecture\n", verb)
continue continue
@@ -166,7 +154,10 @@ func resolveCommand() {
} }
} }
} }
if !slices.Contains(flags, "y") { if rootDir != "/" {
fmt.Println("Warning: Installing to " + rootDir)
}
if !yesAll {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
if pkgInfo.Type == "source" { if pkgInfo.Type == "source" {
fmt.Print("Would you like to view the source.sh file of this package? [Y\\n] ") fmt.Print("Would you like to view the source.sh file of this package? [Y\\n] ")
@@ -182,7 +173,7 @@ func resolveCommand() {
} }
} }
if bpm_utils.IsPackageInstalled(pkgInfo.Name, rootDir) { if bpm_utils.IsPackageInstalled(pkgInfo.Name, rootDir) {
if !slices.Contains(flags, "y") { if !yesAll {
installedInfo := bpm_utils.GetPackageInfo(pkgInfo.Name, rootDir, false) installedInfo := bpm_utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 { if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
fmt.Println("This file contains a newer version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")") fmt.Println("This file contains a newer version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")")
@@ -201,7 +192,7 @@ func resolveCommand() {
continue continue
} }
} }
} else if !slices.Contains(flags, "y") { } else if !yesAll {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
fmt.Printf("Do you wish to %s this package? [y\\N] ", verb) fmt.Printf("Do you wish to %s this package? [y\\N] ", verb)
text, _ := reader.ReadString('\n') text, _ := reader.ReadString('\n')
@@ -211,15 +202,15 @@ func resolveCommand() {
} }
} }
err = bpm_utils.InstallPackage(file, rootDir, slices.Contains(flags, "f"), slices.Contains(flags, "b"), slices.Contains(flags, "k")) err = bpm_utils.InstallPackage(file, rootDir, forceInstall, buildSource, keepTempDir)
if err != nil { if err != nil {
if pkgInfo.Type == "source" && slices.Contains(flags, "k") { if pkgInfo.Type == "source" && keepTempDir {
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name) fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
} }
log.Fatalf("Could not install package\nError: %s\n", err) log.Fatalf("Could not install package\nError: %s\n", err)
} }
fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name) fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name)
if pkgInfo.Type == "source" && slices.Contains(flags, "k") { if pkgInfo.Type == "source" && keepTempDir {
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **") fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
} }
} }
@@ -228,8 +219,7 @@ func resolveCommand() {
fmt.Println("This subcommand needs to be run with superuser permissions") fmt.Println("This subcommand needs to be run with superuser permissions")
os.Exit(0) os.Exit(0)
} }
flags, i := resolveFlags() packages := subcommandArgs
packages := getArgs()[1+i:]
if len(packages) == 0 { if len(packages) == 0 {
fmt.Println("No packages were given") fmt.Println("No packages were given")
return return
@@ -242,7 +232,10 @@ func resolveCommand() {
} }
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo)) fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo))
fmt.Println("----------------") fmt.Println("----------------")
if !slices.Contains(flags, "y") { if rootDir != "/" {
fmt.Println("Warning: Installing to " + rootDir)
}
if !yesAll {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
fmt.Print("Do you wish to remove this package? [y\\N] ") fmt.Print("Do you wish to remove this package? [y\\N] ")
text, _ := reader.ReadString('\n') text, _ := reader.ReadString('\n')
@@ -259,6 +252,11 @@ func resolveCommand() {
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name) fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
} }
default: default:
printHelp()
}
}
func printHelp() {
fmt.Println("\033[1m------Help------\033[0m") fmt.Println("\033[1m------Help------\033[0m")
fmt.Println("\033[1m\\ Command Format /\033[0m") fmt.Println("\033[1m\\ Command Format /\033[0m")
fmt.Println("-> command format: bpm <subcommand> [-flags]...") fmt.Println("-> command format: bpm <subcommand> [-flags]...")
@@ -276,12 +274,69 @@ func resolveCommand() {
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 [-y] <packages...> | removes the following packages")
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 cleanup | removes all unneeded dependencies")
fmt.Println("\033[1m----------------\033[0m") fmt.Println("\033[1m----------------\033[0m")
}
func resolveFlags() {
// List flags
listFlagSet := flag.NewFlagSet("List flags", flag.ExitOnError)
listFlagSet.Usage = printHelp
listFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
listFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
listFlagSet.BoolVar(&pkgListNumbers, "n", false, "List the number of all packages installed with BPM")
listFlagSet.BoolVar(&pkgListNames, "l", false, "List the names of all packages installed with BPM")
// Info flags
infoFlagSet := flag.NewFlagSet("Info flags", flag.ExitOnError)
infoFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
infoFlagSet.Usage = printHelp
// Install flags
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
installFlagSet.BoolVar(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
installFlagSet.Usage = printHelp
// Remove flags
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
removeFlagSet.Usage = printHelp
if len(os.Args[1:]) <= 0 {
subcommand = "help"
} else {
subcommand = os.Args[1]
subcommandArgs = os.Args[2:]
if getCommandType() == list {
err := listFlagSet.Parse(subcommandArgs)
if err != nil {
return
}
subcommandArgs = listFlagSet.Args()
} else if getCommandType() == info {
err := infoFlagSet.Parse(subcommandArgs)
if err != nil {
return
}
subcommandArgs = infoFlagSet.Args()
} else if getCommandType() == install {
err := installFlagSet.Parse(subcommandArgs)
if err != nil {
return
}
subcommandArgs = installFlagSet.Args()
} else if getCommandType() == remove {
err := removeFlagSet.Parse(subcommandArgs)
if err != nil {
return
}
subcommandArgs = removeFlagSet.Args()
}
} }
} }
func resolveFlags() ([]string, int) { /*func resolveFlags() ([]string, int) {
flags := getArgs()[1:] flags := getArgs()[1:]
var ret []string var ret []string
for _, flag := range flags { for _, flag := range flags {
@@ -303,7 +358,13 @@ func resolveFlags() ([]string, int) {
} }
ret = append(ret, f) ret = append(ret, f)
case remove: case remove:
v := [...]string{"y"} 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) { if !slices.Contains(v[:], f) {
log.Fatalf("Invalid flag " + flag) log.Fatalf("Invalid flag " + flag)
} }
@@ -314,4 +375,4 @@ func resolveFlags() ([]string, int) {
} }
} }
return ret, len(ret) return ret, len(ret)
} }*/
Binary file not shown.
@@ -7,7 +7,7 @@ fi
output=$1 output=$1
if [[ ! "$output" =~ ^[a-zA-Z0-9_-]{1,}$ ]]; then if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!" echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
exit 1 exit 1
fi fi
@@ -22,6 +22,9 @@ else
if [ -f source.sh ]; then if [ -f source.sh ]; then
type="source" type="source"
echo "source.sh file found" echo "source.sh file found"
if [ -d source-files ]; then
echo "source-files/ directory found"
fi
else else
echo "files/ directory or source.sh file not found in $PWD" echo "files/ directory or source.sh file not found in $PWD"
exit 1 exit 1
@@ -35,10 +38,14 @@ else
exit 1 exit 1
fi fi
echo "Creating $type package as $output.bpm" echo "Creating $type package as $output"
if [[ "$type" == "binary" ]]; then if [[ "$type" == "binary" ]]; then
tar -czf "$output".bpm files/ pkg.info tar -czf "$output" files/ pkg.info
else else
tar -czf "$output".bpm source.sh pkg.info if [ -d source-files ]; then
tar -czf "$output" source.sh source-files/ pkg.info
else
tar -czf "$output" source.sh pkg.info
fi
fi fi
+1 -1
View File
@@ -1,6 +1,6 @@
name: bpm-utils name: bpm-utils
description: Utilities to create BPM packages description: Utilities to create BPM packages
version: 1.2.0 version: 1.3.0
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
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
name: bpm name: bpm
description: The Bubble Package Manager description: The Bubble Package Manager
version: 0.1.0 version: 0.1.2
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