mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3f1c52202 | ||
|
|
b568d4db32 | ||
|
|
472d21a618 | ||
|
|
a9283037d8 |
@@ -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!
|
||||||
+146
-49
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -130,10 +129,16 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
split[1] = strings.Trim(split[1], " ")
|
split[1] = strings.Trim(split[1], " ")
|
||||||
switch split[0] {
|
switch split[0] {
|
||||||
case "name":
|
case "name":
|
||||||
|
if strings.Contains(split[1], " ") {
|
||||||
|
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
||||||
|
}
|
||||||
pkgInfo.Name = split[1]
|
pkgInfo.Name = split[1]
|
||||||
case "description":
|
case "description":
|
||||||
pkgInfo.Description = split[1]
|
pkgInfo.Description = split[1]
|
||||||
case "version":
|
case "version":
|
||||||
|
if strings.Contains(split[1], " ") {
|
||||||
|
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
||||||
|
}
|
||||||
pkgInfo.Version = split[1]
|
pkgInfo.Version = split[1]
|
||||||
case "url":
|
case "url":
|
||||||
pkgInfo.Url = split[1]
|
pkgInfo.Url = split[1]
|
||||||
@@ -192,7 +197,7 @@ func CreateInfoFile(pkgInfo PackageInfo) string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallPackage(filename, installDir string, force bool) error {
|
func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTempDir bool) error {
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -205,13 +210,17 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tr := tar.NewReader(archive)
|
tr := tar.NewReader(archive)
|
||||||
|
var oldFiles []string
|
||||||
var files []string
|
var files []string
|
||||||
pkgInfo, err := ReadPackage(filename)
|
pkgInfo, err := ReadPackage(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if IsPackageInstalled(pkgInfo.Name, installDir) {
|
||||||
|
oldFiles = GetPackageFiles(pkgInfo.Name, installDir)
|
||||||
|
}
|
||||||
if !force {
|
if !force {
|
||||||
if pkgInfo.Arch != GetArch() {
|
if pkgInfo.Arch != "any" && pkgInfo.Arch != GetArch() {
|
||||||
return errors.New("cannot install a package with a different architecture")
|
return errors.New("cannot install a package with a different architecture")
|
||||||
}
|
}
|
||||||
if unresolved := CheckDependencies(pkgInfo, installDir); len(unresolved) != 0 {
|
if unresolved := CheckDependencies(pkgInfo, installDir); len(unresolved) != 0 {
|
||||||
@@ -294,6 +303,16 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if pkgInfo.Type == "source" {
|
} else if pkgInfo.Type == "source" {
|
||||||
|
temp := "/var/tmp/bpm_source-" + pkgInfo.Name
|
||||||
|
err = os.RemoveAll(temp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Mkdir(temp, 0755)
|
||||||
|
fmt.Println("Creating temp directory at: " + temp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
header, err := tr.Next()
|
header, err := tr.Next()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
@@ -302,13 +321,47 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if header.Name == "source.sh" {
|
if strings.HasPrefix(header.Name, "source-files/") && header.Name != "source-files/" {
|
||||||
bs, err := io.ReadAll(tr)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
temp, err := os.MkdirTemp("/var/tmp/", "bpm_source-")
|
if _, err := io.Copy(outFile, tr); err != nil {
|
||||||
fmt.Println("Creating temp directory at: " + temp)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -316,12 +369,41 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return 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")
|
||||||
|
}
|
||||||
|
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")
|
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
|
||||||
@@ -352,6 +434,10 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
fmt.Println("Creating Directory: " + extractFilename)
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
}
|
}
|
||||||
} else if d.Type().IsRegular() {
|
} else if d.Type().IsRegular() {
|
||||||
|
err := os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
outFile, err := os.Create(extractFilename)
|
outFile, err := os.Create(extractFilename)
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
files = append(files, relFilename)
|
files = append(files, relFilename)
|
||||||
@@ -385,6 +471,10 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
||||||
files = append(files, relFilename)
|
files = append(files, relFilename)
|
||||||
err = os.Symlink(link, extractFilename)
|
err = os.Symlink(link, extractFilename)
|
||||||
@@ -397,7 +487,41 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if binaryPkgFromSrc {
|
||||||
|
compiledDir := path.Join(installDir, "var/lib/bpm/compiled/")
|
||||||
|
err = os.MkdirAll(compiledDir, 755)
|
||||||
|
compiledInfo := PackageInfo{}
|
||||||
|
compiledInfo = *pkgInfo
|
||||||
|
compiledInfo.Type = "binary"
|
||||||
|
compiledInfo.Arch = GetArch()
|
||||||
|
err = os.WriteFile(path.Join(compiledDir, "pkg.info"), []byte(CreateInfoFile(compiledInfo)), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
sed := fmt.Sprintf("s/%s/files/", strings.Replace(strings.TrimPrefix(path.Join(temp, "/output/"), "/"), "/", `\/`, -1))
|
||||||
|
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.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = compiledDir
|
||||||
|
fmt.Printf("running command: %s %s\n", cmd.Path, strings.Join(cmd.Args, " "))
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Remove(path.Join(compiledDir, "pkg.info"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !keepTempDir {
|
||||||
|
err := os.RemoveAll(temp)
|
||||||
|
if err != nil {
|
||||||
|
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)
|
||||||
@@ -405,6 +529,10 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
slices.Sort(files)
|
slices.Sort(files)
|
||||||
slices.Reverse(files)
|
slices.Reverse(files)
|
||||||
|
|
||||||
|
filesDiff := slices.DeleteFunc(oldFiles, func(f string) bool {
|
||||||
|
return slices.Contains(files, f)
|
||||||
|
})
|
||||||
|
|
||||||
installedDir := path.Join(installDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(installDir, "var/lib/bpm/installed/")
|
||||||
err = os.MkdirAll(installedDir, 755)
|
err = os.MkdirAll(installedDir, 755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -460,6 +588,16 @@ func InstallPackage(filename, installDir string, force bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if len(filesDiff) != 0 {
|
||||||
|
fmt.Println("Removing obsolete files")
|
||||||
|
for _, f := range filesDiff {
|
||||||
|
err := os.RemoveAll(path.Join(installDir, f))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("Removing: " + path.Join(installDir, f))
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,44 +852,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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,12 +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"
|
||||||
"path"
|
|
||||||
"slices"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,33 +15,25 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.0.9"
|
var bpmVer = "0.1.3"
|
||||||
|
|
||||||
|
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if os.Getuid() != 0 {
|
|
||||||
fmt.Println("BPM needs to be run with superuser permissions")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
resolveCommand()
|
resolveCommand()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getArgs() []string {
|
|
||||||
return os.Args[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
type commandType uint8
|
type commandType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -53,15 +43,10 @@ const (
|
|||||||
list
|
list
|
||||||
install
|
install
|
||||||
remove
|
remove
|
||||||
cleanup
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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":
|
||||||
@@ -72,23 +57,18 @@ func getCommandType() commandType {
|
|||||||
return install
|
return install
|
||||||
case "remove":
|
case "remove":
|
||||||
return remove
|
return remove
|
||||||
case "cleanup":
|
|
||||||
return cleanup
|
|
||||||
default:
|
default:
|
||||||
return help
|
return help
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -105,7 +85,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())
|
||||||
@@ -115,9 +94,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)
|
||||||
}
|
}
|
||||||
@@ -135,8 +114,11 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case install:
|
case install:
|
||||||
flags, i := resolveFlags()
|
if os.Getuid() != 0 {
|
||||||
files := getArgs()[1+i:]
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
files := subcommandArgs
|
||||||
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
|
||||||
@@ -152,8 +134,8 @@ func resolveCommand() {
|
|||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
verb = "build"
|
verb = "build"
|
||||||
}
|
}
|
||||||
if !slices.Contains(flags, "f") {
|
if !forceInstall {
|
||||||
if 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
|
||||||
}
|
}
|
||||||
@@ -168,7 +150,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] ")
|
||||||
@@ -184,7 +169,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 + ")")
|
||||||
@@ -203,11 +188,7 @@ func resolveCommand() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := bpm_utils.RemovePackage(pkgInfo.Name, rootDir)
|
} else if !yesAll {
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not remove current version of the package\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
} else if !slices.Contains(flags, "y") {
|
|
||||||
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')
|
||||||
@@ -217,21 +198,24 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bpm_utils.InstallPackage(file, rootDir, slices.Contains(flags, "f"))
|
err = bpm_utils.InstallPackage(file, rootDir, forceInstall, buildSource, keepTempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
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" {
|
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 **")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case remove:
|
case remove:
|
||||||
flags, i := resolveFlags()
|
if os.Getuid() != 0 {
|
||||||
packages := getArgs()[1+i:]
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
packages := subcommandArgs
|
||||||
if len(packages) == 0 {
|
if len(packages) == 0 {
|
||||||
fmt.Println("No packages were given")
|
fmt.Println("No packages were given")
|
||||||
return
|
return
|
||||||
@@ -244,7 +228,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')
|
||||||
@@ -261,6 +248,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]...")
|
||||||
@@ -268,45 +260,74 @@ func resolveCommand() {
|
|||||||
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 | shows information on an installed package")
|
||||||
fmt.Println("-> bpm list [-n, -l] | lists all installed packages. -n shows the number of packages. -l lists package names only")
|
fmt.Println("-> bpm list [-n, -l] | lists all installed packages")
|
||||||
fmt.Println("-> bpm install [-y, -f] <files...> | installs the following files. -y skips the confirmation prompt. -f skips dependency and architecture checking")
|
fmt.Println(" -n shows the number of packages")
|
||||||
fmt.Println("-> bpm remove [-y] <packages...> | removes the following packages. -y skips the confirmation prompt")
|
fmt.Println(" -l lists package names only")
|
||||||
fmt.Println("-> bpm cleanup | removes all unneeded dependencies")
|
fmt.Println("-> bpm install [-y, -f, -b] <files...> | installs the following files")
|
||||||
|
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("-> bpm remove [-y] <packages...> | removes the following packages")
|
||||||
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
|
//fmt.Println("-> bpm cleanup | removes all unneeded dependencies")
|
||||||
fmt.Println("\033[1m----------------\033[0m")
|
fmt.Println("\033[1m----------------\033[0m")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveFlags() ([]string, int) {
|
func resolveFlags() {
|
||||||
flags := getArgs()[1:]
|
// List flags
|
||||||
var ret []string
|
listFlagSet := flag.NewFlagSet("List flags", flag.ExitOnError)
|
||||||
for _, flag := range flags {
|
listFlagSet.Usage = printHelp
|
||||||
if strings.HasPrefix(flag, "-") {
|
listFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
f := strings.TrimPrefix(flag, "-")
|
listFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
switch getCommandType() {
|
listFlagSet.BoolVar(&pkgListNumbers, "n", false, "List the number of all packages installed with BPM")
|
||||||
default:
|
listFlagSet.BoolVar(&pkgListNames, "l", false, "List the names of all packages installed with BPM")
|
||||||
log.Fatalf("Invalid flag " + flag)
|
// Info flags
|
||||||
case list:
|
infoFlagSet := flag.NewFlagSet("Info flags", flag.ExitOnError)
|
||||||
v := [...]string{"l", "n"}
|
infoFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
if !slices.Contains(v[:], f) {
|
infoFlagSet.Usage = printHelp
|
||||||
log.Fatalf("Invalid flag " + flag)
|
// Install flags
|
||||||
}
|
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
||||||
ret = append(ret, f)
|
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
case install:
|
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
v := [...]string{"y", "f"}
|
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
||||||
if !slices.Contains(v[:], f) {
|
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
||||||
log.Fatalf("Invalid flag " + flag)
|
installFlagSet.BoolVar(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||||
}
|
installFlagSet.Usage = printHelp
|
||||||
ret = append(ret, f)
|
// Remove flags
|
||||||
case remove:
|
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||||
v := [...]string{"y"}
|
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
if !slices.Contains(v[:], f) {
|
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
log.Fatalf("Invalid flag " + flag)
|
removeFlagSet.Usage = printHelp
|
||||||
}
|
if len(os.Args[1:]) <= 0 {
|
||||||
ret = append(ret, f)
|
subcommand = "help"
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
break
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret, len(ret)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -7,13 +7,28 @@ fi
|
|||||||
|
|
||||||
output=$1
|
output=$1
|
||||||
|
|
||||||
|
if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
|
||||||
|
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
type="binary"
|
||||||
|
|
||||||
echo "Creating package with the name $output..."
|
echo "Creating package with the name $output..."
|
||||||
|
|
||||||
if [ -d files ]; then
|
if [ -d files ]; then
|
||||||
echo "files/ directory found"
|
echo "files/ directory found"
|
||||||
else
|
else
|
||||||
echo "files/ directory not found in $PWD"
|
if [ -f source.sh ]; then
|
||||||
|
type="source"
|
||||||
|
echo "source.sh file found"
|
||||||
|
if [ -d source-files ]; then
|
||||||
|
echo "source-files/ directory found"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "files/ directory or source.sh file not found in $PWD"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f pkg.info ]; then
|
if [ -f pkg.info ]; then
|
||||||
@@ -23,6 +38,14 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Creating $output.bpm package..."
|
echo "Creating $type package as $output"
|
||||||
|
|
||||||
tar -czf $output.bpm files/ pkg.info
|
if [[ "$type" == "binary" ]]; then
|
||||||
|
tar -czf "$output" files/ pkg.info
|
||||||
|
else
|
||||||
|
if [ -d source-files ]; then
|
||||||
|
tar -czf "$output" source.sh source-files/ pkg.info
|
||||||
|
else
|
||||||
|
tar -czf "$output" source.sh pkg.info
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Arguments missing! Try 'bpm-setup <directory> <binary/source>'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
output=$1
|
||||||
|
type=$2
|
||||||
|
|
||||||
|
if [[ ! "$output" =~ ^[a-zA-Z0-9_-]{1,}$ ]]; then
|
||||||
|
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$type" != "binary" ]] && [[ "$type" != "source" ]]; then
|
||||||
|
echo "Invalid package type! Package type must be either 'binary' or 'source'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -pv $output
|
||||||
|
cd $output
|
||||||
|
|
||||||
|
if [[ "$type" == "binary" ]]; then
|
||||||
|
cat > pkg.info << EOF
|
||||||
|
name: package_name
|
||||||
|
description: Package Description
|
||||||
|
version: 1.0
|
||||||
|
url: your package's website/repository url. Optonal
|
||||||
|
license: your package's license. Optional
|
||||||
|
architecture: $(uname -m)
|
||||||
|
type: binary
|
||||||
|
EOF
|
||||||
|
mkdir -pv files
|
||||||
|
echo "Package directory created successfully!"
|
||||||
|
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
||||||
|
echo "Add your binaries under the files/ directory. For example a binary called 'my_binary' should go under files/usr/bin/my_binary"
|
||||||
|
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
||||||
|
else
|
||||||
|
cat > pkg.info << EOF
|
||||||
|
name: package_name
|
||||||
|
description: Package Description
|
||||||
|
version: 1.0
|
||||||
|
url: your package's website/repository url. Optional
|
||||||
|
license: your package's license. Optional
|
||||||
|
architecture: any
|
||||||
|
type: source
|
||||||
|
EOF
|
||||||
|
cat > source.sh << 'EOF'
|
||||||
|
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
|
# BPM expects there to be an 'output' directory under the root of the temporary directory after this script finishes executing, otherwise your program may not be correctly installed
|
||||||
|
# It is recommended you create the 'output' directory along with a 'source' directory in the root of the temporary directory like this
|
||||||
|
echo "Compiling my_program..."
|
||||||
|
# Creating 'source' and 'output' directory variables
|
||||||
|
source=$(pwd)/source
|
||||||
|
output=$(pwd)/output
|
||||||
|
# Creating the 'source' and 'output' directories
|
||||||
|
mkdir $source
|
||||||
|
mkdir $output
|
||||||
|
# Downloading files
|
||||||
|
git clone https://myrepo.com/repo.git source
|
||||||
|
EOF
|
||||||
|
echo "Package directory created successfully!"
|
||||||
|
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
||||||
|
echo "Add your compilation code in the source.sh file. Follow the instructions on the template file on how to do properly compile your program"
|
||||||
|
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
||||||
|
fi
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
name: bpm-utils
|
name: bpm-utils
|
||||||
description: Utilities to create BPM packages
|
description: Utilities to create BPM packages
|
||||||
version: 1.0.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,6 +1,6 @@
|
|||||||
name: bpm
|
name: bpm
|
||||||
description: The Bubble Package Manager
|
description: The Bubble Package Manager
|
||||||
version: 0.0.9
|
version: 0.1.3
|
||||||
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