Added a way to include files in a source package that can be used during the compilation process (i.e patch files)

This commit is contained in:
CapCreeperGR 2024-04-16 21:04:19 +03:00
parent 472d21a618
commit b568d4db32
9 changed files with 192 additions and 139 deletions

View File

@ -77,7 +77,7 @@ mkdir files
5) Either copy the bpm-create script from the bpm-utils test package into your /usr/local/bin directory or install the bpm-utils.bpm package
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!
### Source Packages
@ -85,10 +85,11 @@ bpm-create <filename_without_extension>
```
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
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
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
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) 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) 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!

View File

@ -304,19 +304,6 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
}
}
} else if pkgInfo.Type == "source" {
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if header.Name == "source.sh" {
bs, err := io.ReadAll(tr)
if err != nil {
return err
}
temp := "/var/tmp/bpm_source-" + pkgInfo.Name
err = os.RemoveAll(temp)
if err != nil {
@ -327,10 +314,70 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
if err != nil {
return err
}
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if strings.HasPrefix(header.Name, "source-files/") && header.Name != "source-files/" {
extractFilename := path.Join(temp, strings.TrimPrefix(header.Name, "source-files/"))
switch header.Typeflag {
case tar.TypeDir:
if err := os.Mkdir(extractFilename, 0755); err != nil {
if !os.IsExist(err) {
return err
}
} else {
fmt.Println("Creating Directory: " + extractFilename)
}
case tar.TypeReg:
err := os.Remove(extractFilename)
if err != nil && !os.IsNotExist(err) {
return err
}
outFile, err := os.Create(extractFilename)
fmt.Println("Creating File: " + extractFilename)
if err != nil {
return err
}
if _, err := io.Copy(outFile, tr); err != nil {
return err
}
if err := os.Chmod(extractFilename, header.FileInfo().Mode()); err != nil {
return err
}
err = outFile.Close()
if err != nil {
return err
}
case tar.TypeSymlink:
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
case tar.TypeLink:
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
default:
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename)
}
}
if header.Name == "source.sh" {
bs, err := io.ReadAll(tr)
if err != nil {
return err
}
err = os.WriteFile(path.Join(temp, "source.sh"), bs, 0644)
if err != nil {
return err
}
}
}
if _, err := os.Stat(path.Join("source.sh")); os.IsNotExist(err) {
return errors.New("source.sh file could not be found in the temporary build directory")
}
if err != nil {
return err
}
fmt.Println("Running source.sh file...")
cmd := exec.Command("/usr/bin/sh", "source.sh")
cmd.Stdin = os.Stdin
@ -456,8 +503,6 @@ func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTe
if len(files) == 0 {
return errors.New("no output files for source package. Cancelling package installation")
}
}
}
} else {
return errors.New("Unknown package type: " + pkgInfo.Type)
}

View File

@ -15,7 +15,7 @@ import (
/* A simple-to-use package manager */
/* ---------------------------------- */
var bpmVer = "0.1.1"
var bpmVer = "0.1.2"
var subcommand = "help"
var subcommandArgs []string

View File

@ -7,7 +7,7 @@ fi
output=$1
if [[ ! "$output" =~ ^[a-zA-Z0-9_-]{1,}$ ]]; then
if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
exit 1
fi
@ -22,6 +22,9 @@ else
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
@ -35,10 +38,14 @@ else
exit 1
fi
echo "Creating $type package as $output.bpm"
echo "Creating $type package as $output"
if [[ "$type" == "binary" ]]; then
tar -czf "$output".bpm files/ pkg.info
tar -czf "$output" files/ pkg.info
else
tar -czf "$output".bpm source.sh pkg.info
if [ -d source-files ]; then
tar -czf "$output" source.sh source-files/ pkg.info
else
tar -czf "$output" source.sh pkg.info
fi
fi

View File

@ -1,6 +1,6 @@
name: bpm-utils
description: Utilities to create BPM packages
version: 1.2.0
version: 1.3.0
url: https://gitlab.com/bubble-package-manager/bpm/
license: GPL3
architecture: x86_64

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: bpm
description: The Bubble Package Manager
version: 0.1.1
version: 0.1.2
url: https://gitlab.com/bubble-package-manager/bpm/
license: GPL3
architecture: x86_64