From 1301ea73e6ddd077f78569f4be3ca23438e59605 Mon Sep 17 00:00:00 2001 From: CapCreeperGR Date: Thu, 2 May 2024 13:02:49 +0300 Subject: [PATCH] Initial Commit --- bpm-package | 69 ++++++++++++++++++++++ bpm-setup | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ source.default | 24 ++++++++ 3 files changed, 247 insertions(+) create mode 100755 bpm-package create mode 100755 bpm-setup create mode 100644 source.default diff --git a/bpm-package b/bpm-package new file mode 100755 index 0000000..03de068 --- /dev/null +++ b/bpm-package @@ -0,0 +1,69 @@ +#!/bin/bash +if [ $# -eq 0 ] +then + echo "No output package name given!" + exit 1 +fi + +output=$1 + +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 + +type="binary" +toCompress=("pkg.info") + +echo "Creating package with the name $output..." + +if [ -d files ]; then + echo "files/ directory found" + toCompress+=("files/") +else + if [ -f source.sh ]; then + type="source" + echo "source.sh file found" + toCompress+=("source.sh") + if [ -f pre_update.sh ]; then + echo "pre_update.sh file found" + toCompress+=("pre_update.sh") + fi + if [ -f post_update.sh ]; then + echo "post_update.sh file found" + toCompress+=("post_update.sh") + fi + if [ -f pre_install.sh ]; then + echo "pre_install.sh file found" + toCompress+=("pre_install.sh") + fi + if [ -f post_install.sh ]; then + echo "post_install.sh file found" + toCompress+=("post_install.sh") + fi + if [ -f post_remove.sh ]; then + echo "post_remove.sh file found" + toCompress+=("post_remove.sh") + fi + if [ -d source-files ]; then + if [ ! -z "$(ls -A source-files)" ]; then + echo "source-files/ directory found" + toCompress+=("source-files/") + fi + fi + 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" + +tar -czf "$output" "${toCompress[@]}" diff --git a/bpm-setup b/bpm-setup new file mode 100755 index 0000000..2c23ef7 --- /dev/null +++ b/bpm-setup @@ -0,0 +1,154 @@ +#!/bin/bash + +usage () { + echo "------BPM-Setup options------" + echo "bpm-setup -D | Path to package directory" + echo "bpm-setup -y | Skips confirmation prompt" + echo "bpm-setup -n | Set the package name (Defaults to \"package-name\")" + echo "bpm-setup -d | Set the package description (Defaults to \"Default package description\")" + echo "bpm-setup -v | Set the package version (Defaults to \"1.0\")" + echo "bpm-setup -u | Set the package URL (Optional)" + echo "bpm-setup -l | Set the package licenses (Optional)" + echo "bpm-setup -t | Set the package type to binary or source (Defaults to binary)" + echo "bpm-setup -s | 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 [other options...]" + exit 1 +fi + +if [[ ! "${DIRECTORY}" == "/"* ]]; then + DIRECTORY="${PWD}/${DIRECTORY}" +fi + +if [ -e "${DIRECTORY}" ]; then + echo "This path already exists" + exit 1 +fi + +if [[ "$TYPE" != "binary" ]] && [[ "$TYPE" != "source" ]]; then + echo "Invalid package type! Package type must be either 'binary' or 'source'" + exit 1 +fi + + +if [ -z "${CONFIRM}" ]; then + echo "Setting up package working directory at ${DIRECTORY} with the following information:" + echo "Package name: $NAME" + echo "Package description: $DESCRIPTION" + echo "Package version: $VERSION" + if [ -z "${URL}" ]; then + echo "Package URL: Not set" + else + echo "Package URL: $URL" + 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 + echo "Package directory created successfully!" + 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 "You can turn your package into a .bpm file use the 'bpm-create ' command" +else + echo "architecture: any" >> pkg.info + echo "type: source" >> pkg.info + mkdir -pv source-files + if [ -f "${SOURCE_FILE}" ]; then + touch source.temp + cat "${SOURCE_FILE}" > source.temp + export NAME DESCRIPTION VERSION URL LICENSE TYPE + envsubst '$NAME:$DESCRIPTION:$VERSION:$URL:$LICENSE:$TYPE' < source.temp > source.sh + rm source.temp + else + echo "Source file at ${SOURCE_FILE} does not exist! Creating empty source.sh instead..." + touch source.sh + fi + echo "Package directory created successfully!" + 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 properly create your compilation script" + 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 ' command" +fi diff --git a/source.default b/source.default new file mode 100644 index 0000000..0c7d060 --- /dev/null +++ b/source.default @@ -0,0 +1,24 @@ +# 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" +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!"