mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
497c94cbc0 | ||
|
|
d086b4a639 | ||
|
|
3e8b247e83 | ||
|
|
c8fc1b902c | ||
|
|
6472a113cf | ||
|
|
d3f1c52202 | ||
|
|
b568d4db32 |
@@ -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!
|
||||||
+573
-173
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -26,6 +25,7 @@ type PackageInfo struct {
|
|||||||
License string
|
License string
|
||||||
Arch string
|
Arch string
|
||||||
Type string
|
Type string
|
||||||
|
Keep []string
|
||||||
Depends []string
|
Depends []string
|
||||||
MakeDepends []string
|
MakeDepends []string
|
||||||
Provides []string
|
Provides []string
|
||||||
@@ -101,6 +101,167 @@ func ReadPackage(filename string) (*PackageInfo, error) {
|
|||||||
return nil, errors.New("pkg.info not found in archive")
|
return nil, errors.New("pkg.info not found in archive")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadPackageScripts(filename string) (map[string]string, error) {
|
||||||
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
archive, err := gzip.NewReader(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tr := tar.NewReader(archive)
|
||||||
|
ret := make(map[string]string)
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if header.Name == "pre_install.sh" {
|
||||||
|
bs, _ := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[header.Name] = string(bs)
|
||||||
|
} else if header.Name == "post_install.sh" {
|
||||||
|
bs, _ := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[header.Name] = string(bs)
|
||||||
|
} else if header.Name == "pre_update.sh" {
|
||||||
|
bs, _ := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[header.Name] = string(bs)
|
||||||
|
} else if header.Name == "post_update.sh" {
|
||||||
|
bs, _ := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[header.Name] = string(bs)
|
||||||
|
} else if header.Name == "post_remove.sh" {
|
||||||
|
bs, _ := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[header.Name] = string(bs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = archive.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Operation uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
Install Operation = 0
|
||||||
|
Update = 1
|
||||||
|
Remove = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExecutePackageScripts(filename, rootDir string, operation Operation, postOperation bool) error {
|
||||||
|
pkgInfo, err := ReadPackage(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
scripts, err := ReadPackageScripts(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
run := func(name, content string) error {
|
||||||
|
temp, err := os.CreateTemp("", name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = temp.WriteString(content)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := exec.Command("/bin/bash", temp.Name())
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = rootDir
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
||||||
|
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))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
||||||
|
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()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if operation == Install {
|
||||||
|
if val, ok := scripts["pre_install.sh"]; !postOperation && ok {
|
||||||
|
err := run("pre_install.sh", val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if val, ok := scripts["post_install.sh"]; postOperation && ok {
|
||||||
|
err := run("post_install.sh", val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if operation == Update {
|
||||||
|
if val, ok := scripts["pre_update.sh"]; !postOperation && ok {
|
||||||
|
err := run("pre_update.sh", val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if val, ok := scripts["post_update.sh"]; postOperation && ok {
|
||||||
|
err := run("post_update.sh", val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if operation == Remove {
|
||||||
|
if val, ok := scripts["post_remove.sh"]; postOperation && ok {
|
||||||
|
err := run("post_remove.sh", val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) {
|
func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) {
|
||||||
pkgInfo := PackageInfo{
|
pkgInfo := PackageInfo{
|
||||||
Name: "",
|
Name: "",
|
||||||
@@ -110,6 +271,7 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
License: "",
|
License: "",
|
||||||
Arch: "",
|
Arch: "",
|
||||||
Type: "",
|
Type: "",
|
||||||
|
Keep: nil,
|
||||||
Depends: nil,
|
Depends: nil,
|
||||||
MakeDepends: nil,
|
MakeDepends: nil,
|
||||||
Provides: nil,
|
Provides: nil,
|
||||||
@@ -149,6 +311,9 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
pkgInfo.Arch = split[1]
|
pkgInfo.Arch = split[1]
|
||||||
case "type":
|
case "type":
|
||||||
pkgInfo.Type = split[1]
|
pkgInfo.Type = split[1]
|
||||||
|
case "keep":
|
||||||
|
pkgInfo.Keep = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
||||||
|
pkgInfo.Keep = stringSliceRemoveEmpty(pkgInfo.Keep)
|
||||||
case "depends":
|
case "depends":
|
||||||
pkgInfo.Depends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
pkgInfo.Depends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
||||||
pkgInfo.Depends = stringSliceRemoveEmpty(pkgInfo.Depends)
|
pkgInfo.Depends = stringSliceRemoveEmpty(pkgInfo.Depends)
|
||||||
@@ -176,7 +341,7 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
return &pkgInfo, nil
|
return &pkgInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInfoFile(pkgInfo PackageInfo) string {
|
func CreateInfoFile(pkgInfo PackageInfo, keepSourceFields bool) string {
|
||||||
ret := ""
|
ret := ""
|
||||||
ret = ret + "name: " + pkgInfo.Name + "\n"
|
ret = ret + "name: " + pkgInfo.Name + "\n"
|
||||||
ret = ret + "description: " + pkgInfo.Description + "\n"
|
ret = ret + "description: " + pkgInfo.Description + "\n"
|
||||||
@@ -189,9 +354,15 @@ func CreateInfoFile(pkgInfo PackageInfo) string {
|
|||||||
}
|
}
|
||||||
ret = ret + "architecture: " + pkgInfo.Arch + "\n"
|
ret = ret + "architecture: " + pkgInfo.Arch + "\n"
|
||||||
ret = ret + "type: " + pkgInfo.Type + "\n"
|
ret = ret + "type: " + pkgInfo.Type + "\n"
|
||||||
|
if len(pkgInfo.Keep) > 0 {
|
||||||
|
ret = ret + "keep (" + strconv.Itoa(len(pkgInfo.Keep)) + "): " + strings.Join(pkgInfo.Keep, ",") + "\n"
|
||||||
|
}
|
||||||
if len(pkgInfo.Depends) > 0 {
|
if len(pkgInfo.Depends) > 0 {
|
||||||
ret = ret + "depends (" + strconv.Itoa(len(pkgInfo.Depends)) + "): " + strings.Join(pkgInfo.Depends, ",") + "\n"
|
ret = ret + "depends (" + strconv.Itoa(len(pkgInfo.Depends)) + "): " + strings.Join(pkgInfo.Depends, ",") + "\n"
|
||||||
}
|
}
|
||||||
|
if len(pkgInfo.MakeDepends) > 0 && keepSourceFields {
|
||||||
|
ret = ret + "make_depends (" + strconv.Itoa(len(pkgInfo.MakeDepends)) + "): " + strings.Join(pkgInfo.MakeDepends, ",") + "\n"
|
||||||
|
}
|
||||||
if len(pkgInfo.Provides) > 0 {
|
if len(pkgInfo.Provides) > 0 {
|
||||||
ret = ret + "provides (" + strconv.Itoa(len(pkgInfo.Provides)) + "): " + strings.Join(pkgInfo.Provides, ",") + "\n"
|
ret = ret + "provides (" + strconv.Itoa(len(pkgInfo.Provides)) + "): " + strings.Join(pkgInfo.Provides, ",") + "\n"
|
||||||
}
|
}
|
||||||
@@ -217,7 +388,8 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if IsPackageInstalled(pkgInfo.Name, installDir) {
|
packageInstalled := IsPackageInstalled(pkgInfo.Name, installDir)
|
||||||
|
if packageInstalled {
|
||||||
oldFiles = GetPackageFiles(pkgInfo.Name, installDir)
|
oldFiles = GetPackageFiles(pkgInfo.Name, installDir)
|
||||||
}
|
}
|
||||||
if !force {
|
if !force {
|
||||||
@@ -228,8 +400,18 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", "))
|
return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkgInfo.Type == "binary" {
|
if pkgInfo.Type == "binary" {
|
||||||
|
if !packageInstalled {
|
||||||
|
err = ExecutePackageScripts(filename, installDir, Install, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = ExecutePackageScripts(filename, installDir, Update, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
seenHardlinks := make(map[string]string)
|
seenHardlinks := make(map[string]string)
|
||||||
for {
|
for {
|
||||||
header, err := tr.Next()
|
header, err := tr.Next()
|
||||||
@@ -240,7 +422,8 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(header.Name, "files/") && header.Name != "files/" {
|
if strings.HasPrefix(header.Name, "files/") && header.Name != "files/" {
|
||||||
extractFilename := path.Join(installDir, strings.TrimPrefix(header.Name, "files/"))
|
trimmedName := strings.TrimPrefix(header.Name, "files/")
|
||||||
|
extractFilename := path.Join(installDir, trimmedName)
|
||||||
switch header.Typeflag {
|
switch header.Typeflag {
|
||||||
case tar.TypeDir:
|
case tar.TypeDir:
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
@@ -252,6 +435,13 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
fmt.Println("Creating Directory: " + extractFilename)
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
}
|
}
|
||||||
case tar.TypeReg:
|
case tar.TypeReg:
|
||||||
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
|
if slices.Contains(pkgInfo.Keep, trimmedName) {
|
||||||
|
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
||||||
|
files = append(files, trimmedName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
err := os.Remove(extractFilename)
|
err := os.Remove(extractFilename)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
@@ -304,6 +494,16 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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 {
|
||||||
@@ -312,151 +512,237 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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" {
|
if header.Name == "source.sh" {
|
||||||
bs, err := io.ReadAll(tr)
|
bs, err := io.ReadAll(tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
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
|
|
||||||
}
|
|
||||||
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
|
||||||
}
|
}
|
||||||
fmt.Println("Running source.sh file...")
|
}
|
||||||
cmd := exec.Command("/usr/bin/sh", "source.sh")
|
}
|
||||||
cmd.Stdin = os.Stdin
|
if _, err := os.Stat(path.Join(temp, "source.sh")); os.IsNotExist(err) {
|
||||||
cmd.Stdout = os.Stdout
|
return errors.New("source.sh file could not be found in the temporary build directory")
|
||||||
cmd.Stderr = os.Stderr
|
}
|
||||||
cmd.Dir = temp
|
if err != nil {
|
||||||
err = cmd.Run()
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
fmt.Println("Running source.sh file...")
|
||||||
}
|
if !packageInstalled {
|
||||||
if _, err := os.Stat(path.Join(temp, "/output/")); err != nil {
|
err = ExecutePackageScripts(filename, installDir, Install, false)
|
||||||
if os.IsNotExist(err) {
|
if err != nil {
|
||||||
return errors.New("Output directory not be found at " + path.Join(temp, "/output/"))
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = ExecutePackageScripts(filename, installDir, Update, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd := exec.Command("/bin/bash", "-e", "source.sh")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = temp
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", installDir))
|
||||||
|
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))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
||||||
|
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()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(temp, "/output/")); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return errors.New("Output directory not be found at " + path.Join(temp, "/output/"))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("Copying all files...")
|
||||||
|
err = filepath.WalkDir(path.Join(temp, "/output/"), func(fullpath string, d fs.DirEntry, err error) error {
|
||||||
|
relFilename, err := filepath.Rel(path.Join(temp, "/output/"), fullpath)
|
||||||
|
if relFilename == "." {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
extractFilename := path.Join(installDir, relFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d.Type() == os.ModeDir {
|
||||||
|
files = append(files, relFilename+"/")
|
||||||
|
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
} else {
|
||||||
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
}
|
}
|
||||||
fmt.Println("Copying all files...")
|
} else if d.Type().IsRegular() {
|
||||||
err = filepath.WalkDir(path.Join(temp, "/output/"), func(fullpath string, d fs.DirEntry, err error) error {
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
relFilename, err := filepath.Rel(path.Join(temp, "/output/"), fullpath)
|
if slices.Contains(pkgInfo.Keep, relFilename) {
|
||||||
if relFilename == "." {
|
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
||||||
|
files = append(files, relFilename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
extractFilename := path.Join(installDir, relFilename)
|
}
|
||||||
if err != nil {
|
err := os.Remove(extractFilename)
|
||||||
return err
|
if err != nil && !os.IsNotExist(err) {
|
||||||
}
|
return err
|
||||||
if d.Type() == os.ModeDir {
|
}
|
||||||
files = append(files, relFilename+"/")
|
outFile, err := os.Create(extractFilename)
|
||||||
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
if !os.IsExist(err) {
|
files = append(files, relFilename)
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
|
||||||
}
|
|
||||||
} else if d.Type().IsRegular() {
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
outFile, err := os.Create(extractFilename)
|
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
|
||||||
files = append(files, relFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := os.Open(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(outFile, f); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
info, err := os.Stat(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Chmod(extractFilename, info.Mode()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = outFile.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if d.Type() == os.ModeSymlink {
|
|
||||||
link, err := os.Readlink(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
|
||||||
files = append(files, relFilename)
|
|
||||||
err = os.Symlink(link, extractFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if binaryPkgFromSrc {
|
f, err := os.Open(fullpath)
|
||||||
compiledDir := path.Join(installDir, "var/lib/bpm/compiled/")
|
if err != nil {
|
||||||
err = os.MkdirAll(compiledDir, 755)
|
return err
|
||||||
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+".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 {
|
if _, err := io.Copy(outFile, f); err != nil {
|
||||||
err := os.RemoveAll(temp)
|
return err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(files) == 0 {
|
info, err := os.Stat(fullpath)
|
||||||
return errors.New("no output files for source package. Cancelling package installation")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.Chmod(extractFilename, info.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = outFile.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if d.Type() == os.ModeSymlink {
|
||||||
|
link, err := os.Readlink(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
||||||
|
files = append(files, relFilename)
|
||||||
|
err = os.Symlink(link, extractFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
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, false)), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
scripts, err := ReadPackageScripts(filename)
|
||||||
|
for key, val := range scripts {
|
||||||
|
err = os.WriteFile(path.Join(compiledDir, key), []byte(val), 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"))
|
||||||
|
for key := range scripts {
|
||||||
|
err = os.Remove(path.Join(compiledDir, key))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
||||||
@@ -515,6 +801,25 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scripts, err := ReadPackageScripts(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if val, ok := scripts["post_remove.sh"]; ok {
|
||||||
|
f, err = os.Create(path.Join(pkgDir, "post_remove.sh"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = f.WriteString(val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = archive.Close()
|
err = archive.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -525,8 +830,77 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
|
|||||||
}
|
}
|
||||||
if len(filesDiff) != 0 {
|
if len(filesDiff) != 0 {
|
||||||
fmt.Println("Removing obsolete files")
|
fmt.Println("Removing obsolete files")
|
||||||
|
var symlinks []string
|
||||||
for _, f := range filesDiff {
|
for _, f := range filesDiff {
|
||||||
fmt.Println("Removing: " + path.Join(installedDir, f))
|
f = path.Join(installDir, f)
|
||||||
|
lstat, err := os.Lstat(f)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if lstat.Mode() == os.ModeSymlink {
|
||||||
|
symlinks = append(symlinks, f)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stat, err := os.Stat(f)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if stat.IsDir() {
|
||||||
|
dir, err := os.ReadDir(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(dir) == 0 {
|
||||||
|
fmt.Println("Removing: " + f)
|
||||||
|
err := os.Remove(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Removing: " + f)
|
||||||
|
err := os.Remove(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range symlinks {
|
||||||
|
f = path.Join(installDir, f)
|
||||||
|
_, err := os.Lstat(f)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = filepath.EvalSymlinks(f)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err := os.Remove(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !packageInstalled {
|
||||||
|
err = ExecutePackageScripts(filename, installDir, Install, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = ExecutePackageScripts(filename, installDir, Update, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -746,10 +1120,26 @@ func setPackageInfo(pkg, contents, rootDir string) error {
|
|||||||
func RemovePackage(pkg, rootDir string) error {
|
func RemovePackage(pkg, rootDir string) error {
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
pkgInfo := GetPackageInfo(pkg, rootDir, false)
|
||||||
|
if pkgInfo == nil {
|
||||||
|
return errors.New("could not get package info")
|
||||||
|
}
|
||||||
files := GetPackageFiles(pkg, rootDir)
|
files := GetPackageFiles(pkg, rootDir)
|
||||||
|
var symlinks []string
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
file = path.Join(rootDir, file)
|
file = path.Join(rootDir, file)
|
||||||
stat, err := os.Lstat(file)
|
lstat, err := os.Lstat(file)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if lstat.Mode() == os.ModeSymlink {
|
||||||
|
symlinks = append(symlinks, file)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stat, err := os.Stat(file)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -776,6 +1166,57 @@ func RemovePackage(pkg, rootDir string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, file := range symlinks {
|
||||||
|
file = path.Join(rootDir, file)
|
||||||
|
_, err := os.Lstat(file)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = filepath.EvalSymlinks(file)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err := os.Remove(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(pkgDir, "post_remove.sh")); err == nil {
|
||||||
|
cmd := exec.Command("/bin/bash", path.Join(pkgDir, "post_remove.sh"))
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = rootDir
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
||||||
|
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))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
||||||
|
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()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
err := os.RemoveAll(pkgDir)
|
err := os.RemoveAll(pkgDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -783,44 +1224,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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.1.1"
|
var bpmVer = "0.2.0"
|
||||||
|
|
||||||
var subcommand = "help"
|
var subcommand = "help"
|
||||||
var subcommandArgs []string
|
var subcommandArgs []string
|
||||||
@@ -43,7 +45,7 @@ const (
|
|||||||
list
|
list
|
||||||
install
|
install
|
||||||
remove
|
remove
|
||||||
cleanup
|
file
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCommandType() commandType {
|
func getCommandType() commandType {
|
||||||
@@ -58,12 +60,11 @@ func getCommandType() commandType {
|
|||||||
return install
|
return install
|
||||||
case "remove":
|
case "remove":
|
||||||
return remove
|
return remove
|
||||||
case "cleanup":
|
case "file":
|
||||||
return cleanup
|
return file
|
||||||
default:
|
default:
|
||||||
return help
|
return help
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveCommand() {
|
func resolveCommand() {
|
||||||
@@ -83,7 +84,7 @@ func resolveCommand() {
|
|||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info, true))
|
||||||
if n == len(packages)-1 {
|
if n == len(packages)-1 {
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,7 @@ func resolveCommand() {
|
|||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info, true))
|
||||||
if n == len(packages)-1 {
|
if n == len(packages)-1 {
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
}
|
}
|
||||||
@@ -132,7 +133,7 @@ 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))
|
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
verb := "install"
|
verb := "install"
|
||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
@@ -148,14 +149,14 @@ func resolveCommand() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
if unresolved := bpm_utils.CheckMakeDependencies(pkgInfo, rootDir); len(unresolved) != 0 {
|
if unresolved := bpm_utils.CheckMakeDependencies(pkgInfo, "/"); len(unresolved) != 0 {
|
||||||
fmt.Printf("skipping... cannot %s package (%s) due to missing make dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
fmt.Printf("skipping... cannot %s package (%s) due to missing make dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
fmt.Println("Warning: Installing to " + rootDir)
|
fmt.Println("Warning: Operating in " + rootDir)
|
||||||
}
|
}
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
@@ -230,10 +231,10 @@ func resolveCommand() {
|
|||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo))
|
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
fmt.Println("Warning: Installing to " + rootDir)
|
fmt.Println("Warning: Operating in " + rootDir)
|
||||||
}
|
}
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
@@ -251,30 +252,81 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
||||||
}
|
}
|
||||||
|
case file:
|
||||||
|
files := subcommandArgs
|
||||||
|
if len(files) == 0 {
|
||||||
|
fmt.Println("No files were given to get which packages manage it")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
absFile, err := filepath.Abs(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get absolute path of %s", file)
|
||||||
|
}
|
||||||
|
stat, err := os.Stat(absFile)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Fatalf(absFile + " does not exist!")
|
||||||
|
}
|
||||||
|
pkgs, err := bpm_utils.GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(absFile, rootDir) {
|
||||||
|
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||||
|
}
|
||||||
|
absFile, err = filepath.Rel(rootDir, absFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||||
|
}
|
||||||
|
absFile = strings.TrimPrefix(absFile, "/")
|
||||||
|
if stat.IsDir() {
|
||||||
|
absFile = absFile + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
var pkgList []string
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if slices.Contains(bpm_utils.GetPackageFiles(pkg, rootDir), absFile) {
|
||||||
|
pkgList = append(pkgList, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(pkgList) == 0 {
|
||||||
|
fmt.Println(absFile + " is not managed by any packages")
|
||||||
|
} else {
|
||||||
|
fmt.Println(absFile + " is managed by the following packages:")
|
||||||
|
for _, pkg := range pkgList {
|
||||||
|
fmt.Println("- " + pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
printHelp()
|
printHelp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printHelp() {
|
func printHelp() {
|
||||||
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]...")
|
||||||
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
||||||
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 [-R] | shows information on an installed package")
|
||||||
fmt.Println("-> bpm list [-n, -l] | lists all installed packages")
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
|
fmt.Println("-> bpm list [-R, -n, -l] | lists all installed packages")
|
||||||
|
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -n shows the number of packages")
|
fmt.Println(" -n shows the number of packages")
|
||||||
fmt.Println(" -l lists package names only")
|
fmt.Println(" -l lists package names only")
|
||||||
fmt.Println("-> bpm install [-y, -f, -b] <files...> | installs the following files")
|
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(" -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(" -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(" -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 [-R, -y] <packages...> | removes the following packages")
|
||||||
|
fmt.Println(" -R=<root_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 cleanup | removes all unneeded dependencies")
|
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("\033[1m----------------\033[0m")
|
fmt.Println("\033[1m----------------\033[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,6 +355,11 @@ func resolveFlags() {
|
|||||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
removeFlagSet.Usage = printHelp
|
removeFlagSet.Usage = printHelp
|
||||||
|
// File flags
|
||||||
|
// Remove flags
|
||||||
|
fileFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||||
|
fileFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
fileFlagSet.Usage = printHelp
|
||||||
if len(os.Args[1:]) <= 0 {
|
if len(os.Args[1:]) <= 0 {
|
||||||
subcommand = "help"
|
subcommand = "help"
|
||||||
} else {
|
} else {
|
||||||
@@ -332,47 +389,12 @@ func resolveFlags() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
subcommandArgs = removeFlagSet.Args()
|
subcommandArgs = removeFlagSet.Args()
|
||||||
|
} else if getCommandType() == file {
|
||||||
|
err := fileFlagSet.Parse(subcommandArgs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subcommandArgs = fileFlagSet.Args()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func resolveFlags() ([]string, int) {
|
|
||||||
flags := getArgs()[1:]
|
|
||||||
var ret []string
|
|
||||||
for _, flag := range flags {
|
|
||||||
if strings.HasPrefix(flag, "-") {
|
|
||||||
f := strings.TrimPrefix(flag, "-")
|
|
||||||
switch getCommandType() {
|
|
||||||
default:
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
case list:
|
|
||||||
v := [...]string{"l", "n"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
case install:
|
|
||||||
v := [...]string{"y", "f", "b", "k"}
|
|
||||||
if !slices.Contains(v[:], f) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
case remove:
|
|
||||||
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) {
|
|
||||||
log.Fatalf("Invalid flag " + flag)
|
|
||||||
}
|
|
||||||
ret = append(ret, f)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret, len(ret)
|
|
||||||
}*/
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ $# -eq 0 ]
|
|
||||||
then
|
|
||||||
echo "No output package name given!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output=$1
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
type="binary"
|
|
||||||
|
|
||||||
echo "Creating package with the name $output..."
|
|
||||||
|
|
||||||
if [ -d files ]; then
|
|
||||||
echo "files/ directory found"
|
|
||||||
else
|
|
||||||
if [ -f source.sh ]; then
|
|
||||||
type="source"
|
|
||||||
echo "source.sh file found"
|
|
||||||
else
|
|
||||||
echo "files/ directory or source.sh file not found in $PWD"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f pkg.info ]; then
|
|
||||||
echo "pkg.info file found"
|
|
||||||
else
|
|
||||||
echo "pkg.info file not found in $PWD"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Creating $type package as $output.bpm"
|
|
||||||
|
|
||||||
if [[ "$type" == "binary" ]]; then
|
|
||||||
tar -czf "$output".bpm files/ pkg.info
|
|
||||||
else
|
|
||||||
tar -czf "$output".bpm source.sh pkg.info
|
|
||||||
fi
|
|
||||||
@@ -1,66 +1,154 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ $# -lt 2 ]; then
|
|
||||||
echo "Arguments missing! Try 'bpm-setup <directory> <binary/source>'"
|
usage () {
|
||||||
|
echo "------BPM-Setup options------"
|
||||||
|
echo "bpm-setup -D <directory> | Path to package directory"
|
||||||
|
echo "bpm-setup -y | Skips confirmation prompt"
|
||||||
|
echo "bpm-setup -n <name> | Set the package name (Defaults to \"package-name\")"
|
||||||
|
echo "bpm-setup -d <description> | Set the package description (Defaults to \"Default package description\")"
|
||||||
|
echo "bpm-setup -v <version> | Set the package version (Defaults to \"1.0\")"
|
||||||
|
echo "bpm-setup -u <url> | Set the package URL (Optional)"
|
||||||
|
echo "bpm-setup -l <licenses> | Set the package licenses (Optional)"
|
||||||
|
echo "bpm-setup -t <binary/source> | Set the package type to binary or source (Defaults to binary)"
|
||||||
|
echo "bpm-setup -s <source template file> | Use a default template file (Defaults to /etc/bpm-utils/source.default)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
NAME="package-name"
|
||||||
|
DESCRIPTION="Default package description"
|
||||||
|
VERSION="1.0"
|
||||||
|
#URL="https://my.project.url/ (Optional)"
|
||||||
|
#LICENSE="Your project's license (Optional)"
|
||||||
|
TYPE="binary"
|
||||||
|
SOURCE_FILE="/etc/bpm-utils/source.default"
|
||||||
|
|
||||||
|
while getopts "D:n:d:v:u:l:t:s:y" o; do
|
||||||
|
case "${o}" in
|
||||||
|
D)
|
||||||
|
DIRECTORY="${OPTARG}"
|
||||||
|
;;
|
||||||
|
y)
|
||||||
|
CONFIRM=yes
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
NAME="${OPTARG}"
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
DESCRIPTION="${OPTARG}"
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
VERSION="${OPTARG}"
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
URL="${OPTARG}"
|
||||||
|
;;
|
||||||
|
l)
|
||||||
|
LICENSE="${OPTARG}"
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
TYPE="${OPTARG}"
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
SOURCE_FILE="$(realpath ${OPTARG})"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${DIRECTORY}" ]; then
|
||||||
|
echo "Required directory argument missing. Try 'bpm-setup -D <directory> [other options...]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
output=$1
|
if [[ ! "${DIRECTORY}" == "/"* ]]; then
|
||||||
type=$2
|
DIRECTORY="${PWD}/${DIRECTORY}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! "$output" =~ ^[a-zA-Z0-9_-]{1,}$ ]]; then
|
if [ -e "${DIRECTORY}" ]; then
|
||||||
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
|
echo "This path already exists"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$type" != "binary" ]] && [[ "$type" != "source" ]]; then
|
if [[ "$TYPE" != "binary" ]] && [[ "$TYPE" != "source" ]]; then
|
||||||
echo "Invalid package type! Package type must be either 'binary' or 'source'"
|
echo "Invalid package type! Package type must be either 'binary' or 'source'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -pv $output
|
|
||||||
cd $output
|
|
||||||
|
|
||||||
if [[ "$type" == "binary" ]]; then
|
if [ -z "${CONFIRM}" ]; then
|
||||||
cat > pkg.info << EOF
|
echo "Setting up package working directory at ${DIRECTORY} with the following information:"
|
||||||
name: package_name
|
echo "Package name: $NAME"
|
||||||
description: Package Description
|
echo "Package description: $DESCRIPTION"
|
||||||
version: 1.0
|
echo "Package version: $VERSION"
|
||||||
url: your package's website/repository url. Optonal
|
if [ -z "${URL}" ]; then
|
||||||
license: your package's license. Optional
|
echo "Package URL: Not set"
|
||||||
architecture: $(uname -m)
|
else
|
||||||
type: binary
|
echo "Package URL: $URL"
|
||||||
EOF
|
fi
|
||||||
|
if [ -z "${LICENSE}" ]; then
|
||||||
|
echo "Package license: Not set"
|
||||||
|
else
|
||||||
|
echo "Package license: $LICENSE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Package type: $TYPE"
|
||||||
|
read -p "Create package directory? [y/N]: " CREATE
|
||||||
|
case $CREATE in
|
||||||
|
[Yy]* )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Exiting bpm-setup..."
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! mkdir -pv $DIRECTORY; then
|
||||||
|
echo "Could not create $DIRECTORY!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $DIRECTORY
|
||||||
|
|
||||||
|
touch pkg.info
|
||||||
|
echo "name: ${NAME}" >> pkg.info
|
||||||
|
echo "description: ${DESCRIPTION}" >> pkg.info
|
||||||
|
echo "version: ${VERSION}" >> pkg.info
|
||||||
|
if [ ! -z "${URL}" ]; then echo "url: ${URL}" >> pkg.info; fi
|
||||||
|
if [ ! -z "${LICENSE}" ]; then echo "license: ${LICENSE}" >> pkg.info; fi
|
||||||
|
|
||||||
|
if [[ "$TYPE" == "binary" ]]; then
|
||||||
|
echo "architecture: $(uname -m)" >> pkg.info
|
||||||
|
echo "type: binary" >> pkg.info
|
||||||
mkdir -pv files
|
mkdir -pv files
|
||||||
echo "Package directory created successfully!"
|
echo "Package directory created successfully!"
|
||||||
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
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 "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"
|
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
||||||
else
|
else
|
||||||
cat > pkg.info << EOF
|
echo "architecture: any" >> pkg.info
|
||||||
name: package_name
|
echo "type: source" >> pkg.info
|
||||||
description: Package Description
|
mkdir -pv source-files
|
||||||
version: 1.0
|
if [ -f "${SOURCE_FILE}" ]; then
|
||||||
url: your package's website/repository url. Optional
|
touch source.temp
|
||||||
license: your package's license. Optional
|
cat "${SOURCE_FILE}" > source.temp
|
||||||
architecture: any
|
export NAME DESCRIPTION VERSION URL LICENSE TYPE
|
||||||
type: source
|
envsubst '$NAME:$DESCRIPTION:$VERSION:$URL:$LICENSE:$TYPE' < source.temp > source.sh
|
||||||
EOF
|
rm source.temp
|
||||||
cat > source.sh << 'EOF'
|
else
|
||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
echo "Source file at ${SOURCE_FILE} does not exist! Creating empty source.sh instead..."
|
||||||
# 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
|
touch source.sh
|
||||||
# It is recommended you create the 'output' directory along with a 'source' directory in the root of the temporary directory like this
|
fi
|
||||||
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 "Package directory created successfully!"
|
||||||
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
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 "Add your compilation code in the source.sh file. Follow the instructions on the template file on how to properly create your compilation script"
|
||||||
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
echo "You can add additional files that will be used during compilation to the 'source-files' directory"
|
||||||
|
echo "You can turn your package into a .bpm file use the 'bpm-package <filename>' command"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
name: bpm-utils
|
name: bpm-utils
|
||||||
description: Utilities to create BPM packages
|
description: Utilities to create BPM packages
|
||||||
version: 1.2.0
|
version: 2.0.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: any
|
||||||
type: binary
|
keep: etc/bpm-utils/source.default
|
||||||
|
type: binary
|
||||||
|
|||||||
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.1.1
|
version: 0.2.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
|
||||||
|
|||||||
Reference in New Issue
Block a user