Multiple improvements to the BPM-Utils

This commit is contained in:
CapCreeperGR 2024-07-01 13:45:50 +03:00
parent 6b82675582
commit 5d868579af
2 changed files with 50 additions and 25 deletions

View File

@ -1,39 +1,53 @@
#!/bin/bash #!/bin/bash
while getopts "ksa:" o; do
case "${o}" in
a) ARCH="$OPTARG";;
k) KEEP=true;;
s) SKIPCHECK=true;;
*) exit 1;;
esac
done
PACKAGE="${@:$OPTIND:1}"
DIR="$PWD" DIR="$PWD"
ARCH="$2"
if [ -z "$ARCH" ]; then if [ -z "$ARCH" ]; then
ARCH=$(uname -m) ARCH=$(uname -m)
fi fi
if ! [ -f "$1" ]; then if ! [ -f "$PACKAGE" ]; then
echo "$1 is not a path to a file" echo "$PACKAGE is not a path to a file"
exit 1 exit 1
fi fi
if ! file "$1" | grep -q 'gzip compressed data'; then if ! file "$PACKAGE" | grep -q 'gzip compressed data'; then
echo "$1 is not a BPM package" echo "$PACKAGE is not a BPM package"
exit 1 exit 1
fi fi
if ! tar -tf "$1" | grep -q 'source.sh'; then if ! tar -tf "$PACKAGE" | grep -q 'source.sh'; then
echo "$1 is not a BPM source package" echo "$PACKAGE is not a BPM source package"
exit 1 exit 1
fi fi
echo "$Converting $1..." echo "$Converting $PACKAGE..."
PKGINFO_FILE=$(tar -axf "$1" pkg.info -O) PKGINFO_FILE=$(tar -axf "$PACKAGE" pkg.info -O)
declare -A PKGINFO declare -A PKGINFO
while read line; do while read line; do
PKGINFO[$(echo -n "$line" | cut -d":" -f1 | xargs)]=$(echo -n "$line" | cut -d":" -f2 | xargs) PKGINFO[$(echo -n "$line" | cut -d":" -f1 | xargs)]=$(echo -n "$line" | cut -d":" -f2 | xargs)
done < <(tar -axf "$1" pkg.info -O) done < <(tar -axf "$PACKAGE" pkg.info -O)
TEMPDIR="/var/tmp/bpm_source_${PKGINFO[name]}" TEMPDIR="/var/tmp/bpm_source_${PKGINFO[name]}"
if [ -d "$TEMPDIR" ]; then if [ -d "$TEMPDIR" ] && [ -z "$KEEP" ]; then
rm -rf "$TEMPDIR" rm -rf "$TEMPDIR"
fi fi
mkdir -p "$TEMPDIR" mkdir -p "$TEMPDIR"
mkdir -p "$TEMPDIR"/source mkdir -p "$TEMPDIR"/source
mkdir -p "$TEMPDIR"/output mkdir -p "$TEMPDIR"/output
tar -xf "$1" -C "$TEMPDIR" source.sh tar -xf "$PACKAGE" -C "$TEMPDIR" source.sh
if tar -xf "$PACKAGE" -C "$TEMPDIR" source-files &> /dev/null; then
mv "$TEMPDIR"/source-files/* "$TEMPDIR"/
rm -d "$TEMPDIR"/source-files
fi
cd "$TEMPDIR" cd "$TEMPDIR"
@ -56,7 +70,7 @@ set +a
if [[ $(type -t prepare) == function ]]; then if [[ $(type -t prepare) == function ]]; then
echo "Running prepare() function..." echo "Running prepare() function..."
fakeroot bash -e -c prepare bash -e -c prepare
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to run prepare() function in source.sh" echo "Failed to run prepare() function in source.sh"
exit 1 exit 1
@ -65,39 +79,42 @@ fi
cd "$BPM_SOURCE" cd "$BPM_SOURCE"
if [[ $(type -t build) == function ]]; then if [[ $(type -t build) == function ]]; then
echo "Running build() function..." echo "Running build() function..."
fakeroot bash -e -c build bash -e -c build
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to run build() function in source.sh" echo "Failed to run build() function in source.sh"
exit 1 exit 1
fi fi
fi fi
cd "$BPM_SOURCE" cd "$BPM_SOURCE"
if [[ $(type -t check) == function ]]; then if [[ $(type -t check) == function ]] && [ -z "$SKIPCHECK" ]; then
echo "Running check() function..." echo "Running check() function..."
fakeroot bash -e -c check check
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to run check() function in source.sh" echo "Failed to run check() function in source.sh"
exit 1 exit 1
fi fi
fi fi
cd "$BPM_SOURCE"
if ! [[ $(type -t package) == function ]]; then if ! [[ $(type -t package) == function ]]; then
echo "Failed to locate package() function in source.sh" echo "Failed to locate package() function in source.sh"
exit 1 exit 1
fi fi
echo "Running package() function..." echo "Running package() function..."
fakeroot bash -e -c package touch "$TEMPDIR"/fakeroot_file
fakeroot -s "$TEMPDIR"/fakeroot_file bash -e -c package
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to run package() function in source.sh" echo "Failed to run package() function in source.sh"
exit 1 exit 1
fi fi
cd "$BPM_WORKDIR" cd "$BPM_WORKDIR"
mv output/ files/
touch pkg.info touch pkg.info
echo "${PKGINFO_FILE}" > pkg.info echo "${PKGINFO_FILE}" > pkg.info
sed -i "s/architecture:.*/architecture: ${ARCH}/g" pkg.info sed -i "s/architecture:.*/architecture: ${ARCH}/g" pkg.info
sed -i 's/type:.*/type: binary/g' pkg.info sed -i 's/type:.*/type: binary/g' pkg.info
tar -czpf "$BPM_PKG_NAME".tar.gz files pkg.info fakeroot -i "$TEMPDIR"/fakeroot_file -s "$TEMPDIR"/fakeroot_file tar -czpf "$BPM_PKG_NAME".tar.gz pkg.info output --transform 's/output/files/'
mv "$BPM_PKG_NAME".tar.gz "$DIR"/"$BPM_PKG_NAME"-"$ARCH".bpm mv "$BPM_PKG_NAME".tar.gz "$DIR"/"$BPM_PKG_NAME"-"$BPM_PKG_VERSION"-"$ARCH".bpm
echo "Package conversion complete!" echo "Package conversion complete!"
rm -rf "$TEMPDIR" root if [ -z "$KEEP" ]; then
rm -rf "$TEMPDIR"
fi

View File

@ -5,9 +5,11 @@ then
exit 1 exit 1
fi fi
while getopts "ca:" flag; do while getopts "cska:" flag; do
case "$flag" in case "$flag" in
c) CONVERT=true;; c) CONVERT=true;;
k) KEEP=true;;
s) SKIPCHECK=true;;
a) ARCHITECTURE="${OPTARG}";; a) ARCHITECTURE="${OPTARG}";;
*) exit 1;; *) exit 1;;
esac esac
@ -73,9 +75,15 @@ else
fi fi
echo "Creating $type package as $output" echo "Creating $type package as $output"
tar -c --owner=0 --group=0 --no-same-owner -zf "$output" "${toCompress[@]}"
tar -czf "$output" "${toCompress[@]}"
if [ ! -z "$CONVERT" ] && "$CONVERT" && [[ "$type" == "source" ]]; then if [ ! -z "$CONVERT" ] && "$CONVERT" && [[ "$type" == "source" ]]; then
bpm-convert "$output" "$ARCHITECTURE" args=()
if ! [ -z "$KEEP" ]; then
args+=("-a" "$ARCHITECTURE")
fi
if ! [ -z "$SKIPCHECK" ]; then
args+=("-s")
fi
bpm-convert "${args[@]}" -a "$ARCHITECTURE" "$output"
fi fi