4 Commits
4 changed files with 208 additions and 71 deletions
+4 -5
View File
@@ -8,14 +8,13 @@ BPM Utils is a package providing a number of different helper scripts for settin
## Provided Scripts ## Provided Scripts
- bpm-setup (Creates a directory with the required files for a BPM package) - bpm-setup (Creates a directory with the required files for a BPM package)
- bpm-package (Turns a BPM package directory into a .bpm archive) - bpm-package (Turns a BPM package directory into a .bpm archive)
- bpm-convert (Converts source packages to binary ones)
- create-repository-data (Generates a repository package data list for unpac)
## Installation ## Installation
Currently all BPM Utilities are simple bash scripts. This means you are able to simply clone this repository and place these scripts wherever you would like. Additionally pre-made packages are available for the following package managers: \ Currently all BPM Utilities are simple bash scripts. This means you are able to simply clone this repository and place these scripts wherever you would like
BPM: https://gitlab.com/bubble-package-manager/bpm-utils-bpm \
Pacman: https://gitlab.com/bubble-package-manager/bpm-utils-pacman
## Package Creation using BPM Utils ## Package Creation using BPM Utils
Creating a package for BPM with these utilities is simple Creating a package for BPM with these utilities is simple
+116 -62
View File
@@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
if [ -f .compilation-options ]; then
source ./.compilation-options
fi
echo "$ARCH"
while getopts "ksa:" o; do while getopts "ksa:" o; do
case "${o}" in case "${o}" in
a) ARCH="$OPTARG";; a) ARCH="$OPTARG";;
@@ -30,12 +36,32 @@ if ! tar -tf "$PACKAGE" | grep -q 'source.sh'; then
fi fi
echo "$Converting $PACKAGE..." echo "$Converting $PACKAGE..."
PKGINFO_FILE=$(tar -axf "$PACKAGE" pkg.info -O)
declare -A PKGINFO declare -A PKGINFO
while read line; do # Declare and run Read Package Information function
PKGINFO[$(echo -n "$line" | cut -d":" -f1 | xargs)]=$(echo -n "$line" | cut -d":" -f2 | xargs) function ReadPkgInfo() {
done < <(tar -axf "$PACKAGE" pkg.info -O) local BACK="$PWD"
cd "$DIR"
if [ $# -eq 0 ]; then
FILE=pkg.info
PKGINFO_FILE=$(tar -xf "$PACKAGE" pkg.info -O)
else
FILE=pkg.info."$1"
fi
if ! tar -tf "$PACKAGE" "$FILE"; then
echo "Could not find $FILE in $PACKAGE"
exit 1
fi
PKGINFO_FILE=$(tar -xf "$PACKAGE" "$FILE" -O)
while read line; do
PKGINFO[$(echo -n "$line" | cut -d":" -f1 | xargs)]=$(echo -n "$line" | cut -d":" -f2 | xargs)
done < <(tar -xf "$PACKAGE" "$FILE" -O)
cd "$BACK"
}
ReadPkgInfo
# Creating temporary compilation directory structure
TEMPDIR="/var/tmp/bpm_source_${PKGINFO[name]}" TEMPDIR="/var/tmp/bpm_source_${PKGINFO[name]}"
if [ -d "$TEMPDIR" ] && [ -z "$KEEP" ]; then if [ -d "$TEMPDIR" ] && [ -z "$KEEP" ]; then
rm -rf "$TEMPDIR" rm -rf "$TEMPDIR"
@@ -48,72 +74,100 @@ if tar -xf "$PACKAGE" -C "$TEMPDIR" source-files &> /dev/null; then
mv "$TEMPDIR"/source-files/* "$TEMPDIR"/ mv "$TEMPDIR"/source-files/* "$TEMPDIR"/
rm -d "$TEMPDIR"/source-files rm -d "$TEMPDIR"/source-files
fi fi
PACKAGE_SCRIPTS=()
while read line; do
PACKAGE_SCRIPTS+=("$line")
done < <(tar -tf "$PACKAGE" | grep -v -E 'source.sh|pkg.info|source-files')
tar -xf "$PACKAGE" -C "$TEMPDIR" ${PACKAGE_SCRIPTS[@]} &> /dev/null
cd "$TEMPDIR" cd "$TEMPDIR"
export BPM_PKG_NAME="${PKGINFO[name]}" # Declare and run Set Variables function
export BPM_PKG_DESC="${PKGINFO[description]}" function SetVariables() {
export BPM_PKG_VERSION="${PKGINFO[version]}" export BPM_PKG_NAME="${PKGINFO[name]}"
export BPM_PKG_URL="${PKGINFO[url]}" export BPM_PKG_DESC="${PKGINFO[description]}"
export BPM_PKG_ARCH="${PKGINFO[architecture]}" export BPM_PKG_VERSION="${PKGINFO[version]}"
IFS=',' read -r -a BPM_PKG_DEPENDS <<< "${PKGINFO[depends]}" export BPM_PKG_URL="${PKGINFO[url]}"
IFS=',' read -r -a BPM_PKG_MAKE_DEPENDS <<< "${PKGINFO[make_depends]}" export BPM_PKG_ARCH="${PKGINFO[architecture]}"
export BPM_PKG_DEPENDS IFS=',' read -r -a BPM_PKG_DEPENDS <<< "${PKGINFO[depends]}"
export BPM_PKG_MAKE_DEPENDS IFS=',' read -r -a BPM_PKG_MAKE_DEPENDS <<< "${PKGINFO[make_depends]}"
export BPM_WORKDIR="$TEMPDIR" export BPM_PKG_DEPENDS
export BPM_SOURCE="$TEMPDIR"/source export BPM_PKG_MAKE_DEPENDS
export BPM_OUTPUT="$TEMPDIR"/output export BPM_WORKDIR="$TEMPDIR"
export BPM_SOURCE="$TEMPDIR"/source
export BPM_OUTPUT="$TEMPDIR"/output
}
SetVariables
# Declare Run Package Function function
function RunPkgFunction() {
if [ $# -eq 0 ]; then
echo "No function name given"
exit 1
fi
func="$1"
if [[ $(type -t "$func") == function ]]; then
echo "Running ${func}() function..."
bash -e -c "$func"
if [ $? -ne 0 ]; then
echo "Failed to run ${func}() function in source.sh"
exit 1
fi
fi
}
# Read source.sh file and source functions
set -a set -a
source source.sh source source.sh
set +a set +a
if [[ $(type -t prepare) == function ]]; then
echo "Running prepare() function..."
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..."
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 ]] && [ -z "$SKIPCHECK" ]; then
echo "Running check() function..."
check
if [ $? -ne 0 ]; then
echo "Failed to run check() function in source.sh"
exit 1
fi
fi
cd "$BPM_SOURCE"
if ! [[ $(type -t package) == function ]]; then
echo "Failed to locate package() function in source.sh"
exit 1
fi
echo "Running package() function..."
touch "$TEMPDIR"/fakeroot_file
fakeroot -s "$TEMPDIR"/fakeroot_file bash -e -c package
if [ $? -ne 0 ]; then
echo "Failed to run package() function in source.sh"
exit 1
fi
cd "$BPM_WORKDIR" cd "$BPM_WORKDIR"
touch pkg.info RunPkgFunction prepare
echo "${PKGINFO_FILE}" > pkg.info
sed -i "s/architecture:.*/architecture: ${ARCH}/g" pkg.info cd "$BPM_SOURCE"
sed -i 's/type:.*/type: binary/g' pkg.info RunPkgFunction build
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"-"$BPM_PKG_VERSION"-"$ARCH".bpm cd "$BPM_SOURCE"
echo "Package conversion complete!" if [ -z "$SKIPCHECK" ]; then
RunPkgFunction check
fi
# Packaging all packages
for func in $(typeset -F | awk '{print $3}' | grep '^package'); do
cd "$BPM_SOURCE"
if [[ "$func" == "package" ]]; then
pkgname="$BPM_PKG_NAME"
ReadPkgInfo
else
pkgname="${func##package-}"
ReadPkgInfo "$pkgname"
fi
SetVariables
echo "Running ${func}() function..."
touch "$TEMPDIR"/fakeroot_file_"$pkgname"
fakeroot -s "$TEMPDIR"/fakeroot_file_"$pkgname" bash -e -c "$func"
if [ $? -ne 0 ]; then
echo "Failed to run ${func}() function in source.sh"
exit 1
fi
cd "$BPM_WORKDIR"
touch pkg.info
if [[ "$pkgname" == "$BPM_PKG_NAME" ]]; then
echo "${PKGINFO_FILE}" > pkg.info
else
echo "${PKGINFO_FILE}" > pkg.info
fi
echo "${PKGINFO_FILE}" > pkg.info
sed -i "s/architecture:.*/architecture: ${ARCH}/g" pkg.info
sed -i 's/type:.*/type: binary/g' pkg.info
fakeroot -i "$TEMPDIR"/fakeroot_file_"$pkgname" tar -czpf "$pkgname".tar.gz pkg.info ${PACKAGE_SCRIPTS[@]} output --transform 's/output/files/'
mv "$pkgname".tar.gz "$DIR"/"$pkgname"-"$BPM_PKG_VERSION"-"$ARCH".bpm
echo "Packaged ${pkgname} successfully!"
rm "$TEMPDIR"/fakeroot_file_"$pkgname"
rm -r output/
mkdir output
rm pkg.info
done
if [ -z "$KEEP" ]; then if [ -z "$KEEP" ]; then
rm -rf "$TEMPDIR" rm -rf "$TEMPDIR"
+14 -4
View File
@@ -5,12 +5,16 @@ then
exit 1 exit 1
fi fi
if [ -f .compilation-options ]; then
source ./.compilation-options
fi
while getopts "cska:" flag; do while getopts "cska:" flag; do
case "$flag" in case "$flag" in
c) CONVERT=true;; c) CONVERT=true;;
k) KEEP=true;; k) KEEP=true;;
s) SKIPCHECK=true;; s) SKIPCHECK=true;;
a) ARCHITECTURE="${OPTARG}";; a) ARCH="${OPTARG}";;
*) exit 1;; *) exit 1;;
esac esac
done done
@@ -23,7 +27,7 @@ if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
fi fi
type="binary" type="binary"
toCompress=("pkg.info") toCompress=()
echo "Creating package with the name $output..." echo "Creating package with the name $output..."
@@ -74,16 +78,22 @@ else
exit 1 exit 1
fi fi
for pkginfo in ./pkg.inf*; do
pkginfo=$(basename "$pkginfo")
echo "${pkginfo} file found"
toCompress+=("$pkginfo")
done
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 -c --owner=0 --group=0 --no-same-owner -zf "$output" "${toCompress[@]}"
if [ ! -z "$CONVERT" ] && "$CONVERT" && [[ "$type" == "source" ]]; then if [ ! -z "$CONVERT" ] && "$CONVERT" && [[ "$type" == "source" ]]; then
args=() args=()
if ! [ -z "$KEEP" ]; then if ! [ -z "$KEEP" ]; then
args+=("-a" "$ARCHITECTURE") args+=("-a" "$ARCH")
fi fi
if ! [ -z "$SKIPCHECK" ]; then if ! [ -z "$SKIPCHECK" ]; then
args+=("-s") args+=("-s")
fi fi
bpm-convert "${args[@]}" -a "$ARCHITECTURE" "$output" bpm-convert "${args[@]}" -a "$ARCH" "$output"
fi fi
+74
View File
@@ -0,0 +1,74 @@
#!/bin/bash
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
SCRIPT_PATH=$(realpath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
DEEP=false
PKGS=()
while getopts "d" flag; do
case "$flag" in
d) DEEP=true
shopt -s globstar;;
*) echo "Unknown flag ${flag}"
exit 2;;
esac
done
if [ -z "${@:$OPTIND:1}" ]; then
echo "You have not specified a repository"
exit 1
fi
if ! [ -d "${@:$OPTIND:1}" ]; then
echo "The given path is not a directory"
exit 1
fi
if realpath "${@:$OPTIND:1}" &> /dev/null; then
REPO=$(realpath "${@:$OPTIND:1}")
fi
shopt -s nullglob
create_entry() {
if [ $# -eq 0 ]; then
return 0
fi
if ! [ -f "$1" ]; then
return 0
fi
info="info:"$'\n'
info+=$(tar -xf "$pkg" pkg.info -O | sed 's/^/ /g')
package=$(echo "$info" | grep 'name: ' | xargs | awk '{print $2}')
if containsElement "$package" "${PKGS[@]}"; then
echo "The following package was found in more than 1 package archives: ${package}"
exit 1
fi
PKGS+=("$package")
file="$(realpath -s --relative-to="$REPO" "$pkg")"
info+=$'\n'"download: ${file}"
info+=$'\n---'
echo "$info"
}
if ! $DEEP; then
for arch in "$REPO"/*/; do
for pkg in "$arch"/*.bpm; do
create_entry "$pkg"
done
done
else
for arch in "$REPO"/*/; do
for pkg in "$arch"/**/*.bpm; do
create_entry "$pkg"
done
done
fi