Updated source.default, updated bpm-package and added bpm-convert

source.default now uses the new PKGBUILD-like structure
bpm-package now accepts a '-c' flag that creates an additional binary package from a source package
bpm-convert creates a binary package from a source package
This commit is contained in:
CapCreeperGR 2024-05-30 14:23:14 +03:00
parent ede04e3aba
commit a3a97efd59
4 changed files with 144 additions and 24 deletions

View File

@ -48,7 +48,7 @@ bpm-package <filename.bpm>
3) If you would like to bundle patches or other files with your source package place them in the 'source-files' directory. They will be extracted to the same location as the source.sh file during compilation
4) You need to edit your 'source.sh' file, the default source.sh template should explain the basic process of compiling your program
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) When you are done making your source.sh script run the following to create a package archive
6) When you are done making your source.sh script run the following to create a package archive. You may also append the -c flag to compile the package and create a binary package as well
```
bpm-package <filename.bpm>
```

101
bpm-convert Executable file
View File

@ -0,0 +1,101 @@
#!/bin/bash
DIR="$PWD"
if ! [ -f "$1" ]; then
echo "$1 is not a path to a file"
exit 1
fi
if ! file "$1" | grep -q 'gzip compressed data'; then
echo "$1 is not a BPM package"
exit 1
fi
if ! tar -tf "$1" | grep -q 'source.sh'; then
echo "$1 is not a BPM source package"
exit 1
fi
echo "$Converting $1..."
PKGINFO_FILE=$(tar -axf "$1" pkg.info -O)
declare -A PKGINFO
while read line; do
PKGINFO[$(echo -n "$line" | cut -d":" -f1 | xargs)]=$(echo -n "$line" | cut -d":" -f2 | xargs)
done < <(tar -axf "$1" pkg.info -O)
TEMPDIR="/var/tmp/bpm_source_${PKGINFO[name]}"
if [ -d "$TEMPDIR" ]; then
rm -rf "$TEMPDIR"
fi
mkdir -p "$TEMPDIR"
mkdir -p "$TEMPDIR"/source
mkdir -p "$TEMPDIR"/output
tar -xf "$1" -C "$TEMPDIR" source.sh
cd "$TEMPDIR"
export BPM_PKG_NAME="${PKGINFO[name]}"
export BPM_PKG_DESC="${PKGINFO[description]}"
export BPM_PKG_VERSION="${PKGINFO[version]}"
export BPM_PKG_URL="${PKGINFO[url]}"
export BPM_PKG_ARCH="${PKGINFO[architecture]}"
IFS=',' read -r -a BPM_PKG_DEPENDS <<< "${PKGINFO[depends]}"
IFS=',' read -r -a BPM_PKG_MAKE_DEPENDS <<< "${PKGINFO[make_depends]}"
export BPM_PKG_DEPENDS
export BPM_PKG_MAKE_DEPENDS
export BPM_WORKDIR="$TEMPDIR"
export BPM_SOURCE="$TEMPDIR"/source
export BPM_OUTPUT="$TEMPDIR"/output
source source.sh
if [[ $(type -t prepare) == function ]]; then
echo "Running prepare() function..."
export -f prepare
fakeroot bash -e -c prepare
if [ $? -ne 0 ]; then
echo "Failed to run prepare() function in source.sh"
exit 1
fi
fi
cd "$BPM_SOURCE"
if [[ $(type -t build) == function ]]; then
echo "Running build() function..."
export -f build
fakeroot bash -e -c build
if [ $? -ne 0 ]; then
echo "Failed to run build() function in source.sh"
exit 1
fi
fi
cd "$BPM_SOURCE"
if [[ $(type -t check) == function ]]; then
echo "Running check() function..."
export -f check
fakeroot bash -e -c check
if [ $? -ne 0 ]; then
echo "Failed to run check() function in source.sh"
exit 1
fi
fi
if ! [[ $(type -t package) == function ]]; then
echo "Failed to locate package() function in source.sh"
exit 1
fi
echo "Running package() function..."
export -f package
fakeroot bash -e -c package
if [ $? -ne 0 ]; then
echo "Failed to run package() function in source.sh"
exit 1
fi
cd "$BPM_WORKDIR"
mv output/ files/
touch pkg.info
echo "${PKGINFO_FILE}" > pkg.info
sed -i "s/architecture:.*/architecture: $(uname -m)/g" pkg.info
sed -i 's/type:.*/type: binary/g' pkg.info
tar -czpf "$BPM_PKG_NAME".tar.gz files pkg.info
mv "$BPM_PKG_NAME".tar.gz "$DIR"/"$BPM_PKG_NAME"-"$(uname -m)".bpm
echo "Package conversion complete!"
rm -rf "$TEMPDIR" root

View File

@ -5,7 +5,14 @@ then
exit 1
fi
output=$1
while getopts "c" flag; do
case "$flag" in
c) CONVERT=true;;
*) exit 1;;
esac
done
output="${@:$OPTIND:1}"
if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
@ -67,3 +74,7 @@ fi
echo "Creating $type package as $output"
tar -czf "$output" "${toCompress[@]}"
if "$CONVERT" && [[ "$type" == "source" ]]; then
bpm-convert "$output"
fi

View File

@ -1,24 +1,32 @@
# 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 ${NAME}..."
# Creating SOURCE and OUTPUT variables
SOURCE="$(pwd)"/source
OUTPUT="$(pwd)"/output
# Creating the 'source' and 'output' directories
mkdir "$SOURCE"
mkdir "$OUTPUT"
# Creating DOWNLOAD and FILENAME variables
DOWNLOAD="https://www.my-url.com/file.tar.gz"
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
DOWNLOAD="https://wwww.my-url.com/file.tar.gz"
FILENAME="${DOWNLOAD##*/}"
# Downloading files
wget "$DOWNLOAD"
# Extracting archive into 'source'
tar -xvf "$FILENAME" --strip-components=1 -C "$SOURCE"
# Changing directory into 'source'
cd "$SOURCE"
# Configuring and compiling ${NAME}
./configure --prefix=/usr
make
make install DESTDIR="$OUTPUT"
echo "${NAME} compilation complete!"
# The prepare function is executed in the root of the temp directory
# This function is used for downloading files and putting them into the correct location
prepare() {
wget "$DOWNLOAD"
tar -xvf nano-"$FILENAME" --strip-components=1 -C "$BPM_SOURCE"
}
# The build function is executed in the source directory
# This function is used to compile the source code
build() {
./configure --prefix=/usr
make
}
# The check function is executed in the source directory
# This function is used to run tests to verify the package has been compiled correctly
check() {
make check
}
# The package function is executed in the source directory
# This function is used to move the compiled files into the output directory
package() {
make DESTDIR="$BPM_OUTPUT" install
}