From 0c226281e6d3789262c6304b17070a4d7c5a6c0f Mon Sep 17 00:00:00 2001 From: RedProkofiev Date: Mon, 19 Feb 2024 16:33:56 +0000 Subject: [PATCH 1/4] Make script compatible with Rocky 8 and CentOS 8 and add OS specific tags A mixture of inconsistent testing and dependencies led to some weird errors that were hard to reproduce. I cordoned it down to: - Ordering of --depends calls, where calling python3-pip before python3-stomppy led to an almost instant fail - Bad module names It was not in fact the ifs that were at fault. This script has now been tested with Rocky 8 and CentOS 8 from start to finish, and Debian previously. It will now be tested with EL7. --- scripts/ssm-build.sh | 203 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100755 scripts/ssm-build.sh diff --git a/scripts/ssm-build.sh b/scripts/ssm-build.sh new file mode 100755 index 00000000..f81eae51 --- /dev/null +++ b/scripts/ssm-build.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +# Apel-SSM Build Script 2.0: FPM edition +# Adapted from the Debian only build script, now with RPM! +# @Author: Nicholas Whyatt (RedProkofiev@github.com) + +# Script runs well with FPM 1.14.2 on ruby 2.7.1, setuptools 51.3.3 on RHEL and Deb platforms +# Download ruby (if you're locked to 2.5, use RVM) and then run: +# sudo gem install fpm -v 1.14.2 +# for RPM builds, you will also need: +# sudo yum install rpm-build | sudo apt-get install rpm +# ./ssm-build.sh (deb | rpm) e.g. +# ./ssm-build.sh deb 3.4.0 1 /usr/lib/python3.6 +# If you're struggling finding the right version of Python to use, consider opening interpreter and: +# import site; site.getsitepackages() +# For SSM 3.4.0 and up. Versions before that would technically work, but the changelog +# then was in a Debian format that doesn't parse and fails hard if you want to build RPM. + +set -e + +usage() { + echo "Usage: $0 [options] (deb | rpm) " + echo -e "Build script for Apel-SSM.\n" + echo " -h Displays help." + echo " -v Verbose FPM output." + echo " -s Directory of source files. Defaults to /debbuild/source or SOME RPM DIR." + echo -e " -b Directory of build files. Defaults to /debbuild/build or SOME RPM DIR.\n" 1>&2; + exit 1; +} + +# Bool flags to prevent automatic overwrite of input +SOURCE_ASSIGNED=0 +BUILD_ASSIGNED=0 + +# Configurable options +while getopts ":hs:b:v" o; do + case "${o}" in + h) echo "SSM Help" + usage; + ;; + s) s=${OPTARG} + SOURCE_DIR=$s + SOURCE_ASSIGNED=1 + ;; + b) b=${OPTARG} + BUILD_DIR=$b + BUILD_ASSIGNED=1 + ;; + v) VERBOSE="--verbose " + ;; + *) usage; + ;; + esac +done +shift $((OPTIND-1)) + +# Check how any arguments there are +if [ "$#" -ne 4 ]; then + echo "Expected 4 arguments, $# given." + usage; +fi + +PACK_TYPE=$1 +VERSION=$2 +ITERATION=$3 +PYTHON_ROOT_DIR=$4 # i.e. /usr/lib/python3.6 + +# Alter library, build and source directories depending on the package +if [[ "$PACK_TYPE" = "deb" ]]; then + LIB_EXTENSION="/dist-packages" + if [[ "$SOURCE_ASSIGNED" = 0 ]]; then + SOURCE_DIR=~/debbuild/source + fi + if [[ "$BUILD_ASSIGNED" = 0 ]]; then + BUILD_DIR=~/debbuild/build + fi +elif [[ "$PACK_TYPE" = "rpm" ]]; then + LIB_EXTENSION="/site-packages" + if [[ "$SOURCE_ASSIGNED" = 0 ]]; then + SOURCE_DIR=~/rpmbuild/SOURCES + fi + if [[ "$BUILD_ASSIGNED" = 0 ]]; then + BUILD_DIR=~/rpmbuild/BUILD + fi +else # If package type is neither deb nor rpm, show an error message and exit + echo "$0 currently only supports 'deb' and 'rpm' packages." + usage; +fi + +# Directory cleaning and repository management +# Create SSM and DEB dir (if not present) +mkdir -p "$SOURCE_DIR" +mkdir -p "$BUILD_DIR" + +# Clean up any previous build +rm -rf "${SOURCE_DIR:?}"/* +rm -rf "${BUILD_DIR:?}"/* + +# Get and extract the source +TAR_FILE=${VERSION}-${ITERATION}.tar.gz +TAR_URL=https://github.com/apel/ssm/archive/$TAR_FILE +wget --no-check-certificate "$TAR_URL" -O "$TAR_FILE" +tar xvf "$TAR_FILE" -C "$SOURCE_DIR" +rm -f "$TAR_FILE" + +# Get supplied Python version +PY_VERSION="$(basename "$PYTHON_ROOT_DIR")" +PY_NUM=${PY_VERSION#python} + +# Universal FPM Call +FPM_CORE="fpm -s python \ + -t $PACK_TYPE \ + -n apel-ssm \ + -v $VERSION \ + --iteration $ITERATION \ + -m \"Apel Administrators \" \ + --description \"Secure Stomp Messenger (SSM).\" \ + --no-auto-depends " + +# Simple Python filter for version specific FPM +if [[ ${PY_NUM:0:1} == "3" ]]; then + echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." + # python-stomp < 5.0.0 to python-stomp, python to python3/pip3 + # edited python-pip3 to python-pip + # slight spelling inconsistencites betwixt OS's + + if [[ "$PACK_TYPE" = "deb" ]]; then + FPM_PYTHON="--depends python3 \ + --depends python-pip3 \ + --depends 'python-stomp' \ + --depends python-ldap \ + --depends libssl-dev \ + --depends libsasl2-dev \ + --depends openssl " + + OS_EXTENSION="_all" + + # Currently builds for el8 + elif [[ "$PACK_TYPE" = "rpm" ]]; then + FPM_PYTHON="--depends python3 \ + --depends python3-stomppy \ + --depends python3-pip \ + --depends python3-ldap \ + --depends openssl \ + --depends openssl-devel " + + OS_EXTENSION="el8" + fi + +elif [[ ${PY_NUM:0:1} == "2" ]]; then + echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." + + if [[ "$PACK_TYPE" = "deb" ]]; then + FPM_PYTHON="--depends python2.7 \ + --depends python-pip \ + --depends 'python-stomp < 5.0.0' \ + --depends python-ldap \ + --depends libssl-dev \ + --depends libsasl2-dev \ + --depends openssl " + + OS_EXTENSION="_all" + + # el7 and below, due to yum package versions + elif [[ "$PACK_TYPE" = "rpm" ]]; then + FPM_PYTHON="--depends python2.7 \ + --depends python2-pip \ + --depends 'python-stomp < 5.0.0' \ + --depends python-ldap \ + --depends openssl \ + --depends openssl-devel " + + OS_EXTENSION="el7" + fi +fi + +# python-bin must always be specified in modern linux +PACKAGE_VERSION="--$PACK_TYPE-changelog $SOURCE_DIR/ssm-$VERSION-$ITERATION/CHANGELOG \ + --$PACK_TYPE-dist $OS_EXTENSION \ + --python-bin /usr/bin/$PY_VERSION \ + --python-install-lib $PYTHON_ROOT_DIR$LIB_EXTENSION \ + --exclude *.pyc \ + --package $BUILD_DIR \ + $SOURCE_DIR/ssm-$VERSION-$ITERATION/setup.py" + +# Construct and evaluate the primary FPM call +BUILD_PACKAGE_COMMAND=${FPM_CORE}${FPM_PYTHON}${VERBOSE}${PACKAGE_VERSION} +eval "$BUILD_PACKAGE_COMMAND" +echo "== BEGINNING PLEASERUN SETUP ==" + +# When installed, use pleaserun to perform system specific service setup +fpm -s pleaserun -t "$PACK_TYPE" \ +-n apel-ssm-service \ +-v "$VERSION" \ +--iteration "$ITERATION" \ +--"$PACK_TYPE"-dist "$OS_EXTENSION" \ +-m "Apel Administrators " \ +--description "Secure Stomp Messenger (SSM) Service Daemon files." \ +--architecture all \ +--no-auto-depends \ +--depends apel-ssm \ +--package "$BUILD_DIR" \ +/usr/bin/ssmreceive From aa9f5e19add7418e35e3fb41049b1b3c16e0a6f2 Mon Sep 17 00:00:00 2001 From: RedProkofiev Date: Mon, 19 Feb 2024 17:15:44 +0000 Subject: [PATCH 2/4] Add EL7 compatibility and modules Fixes incompatibility with EL7 by changing some module names. --- scripts/ssm-build-dual.sh | 165 -------------------------------------- scripts/ssm-build.sh | 4 +- 2 files changed, 2 insertions(+), 167 deletions(-) delete mode 100755 scripts/ssm-build-dual.sh diff --git a/scripts/ssm-build-dual.sh b/scripts/ssm-build-dual.sh deleted file mode 100755 index fe697f54..00000000 --- a/scripts/ssm-build-dual.sh +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/bash - -# Apel-SSM Build Script 2.0: FPM edition -# Adapted from the Debian only build script, now with RPM! -# @Author: Nicholas Whyatt (RedProkofiev@github.com) - -# Script runs well with FPM 1.14.2 on ruby 2.7.1, setuptools 51.3.3 on RHEL and Deb platforms -# Download ruby (if you're locked to 2.5, use RVM) and then run: -# sudo gem install fpm -v 1.14.2 -# ./ssm-build-dual.sh (deb | rpm) e.g. -# ./ssm-build.dual.sh deb 3.4.0 1 /usr/lib/python3.6 -# For SSM 3.4.0 and up. Versions before that would technically work, but the changelog -# then was in a Debian format that doesn't parse and fails hard if you want to build RPM. - -set -e - -usage() { - echo "Usage: $0 [options] (deb | rpm) " - echo -e "Build script for Apel-SSM.\n" - echo " -h Displays help." - echo " -v Verbose FPM output." - echo " -s Directory of source files. Defaults to /debbuild/source or SOME RPM DIR." - echo -e " -b Directory of build files. Defaults to /debbuild/build or SOME RPM DIR.\n" 1>&2; - exit 1; -} - -# Bool flags to prevent automatic overwrite of input -SOURCE_ASSIGNED=0 -BUILD_ASSIGNED=0 - -# Configurable options -while getopts ":hs:b:v" o; do - case "${o}" in - h) echo "SSM Help" - usage; - ;; - s) s=${OPTARG} - SOURCE_DIR=$s - SOURCE_ASSIGNED=1 - ;; - b) b=${OPTARG} - BUILD_DIR=$b - BUILD_ASSIGNED=1 - ;; - v) VERBOSE="--verbose " - ;; - *) usage; - ;; - esac -done -shift $((OPTIND-1)) - -# Check how any arguments there are -if [ "$#" -ne 4 ]; then - echo "Expected 4 arguments, $# given." - usage; -fi - -PACK_TYPE=$1 -VERSION=$2 -ITERATION=$3 -PYTHON_ROOT_DIR=$4 # i.e. /usr/lib/python3.6 - -# Alter library, build and source directories depending on the package -if [[ "$PACK_TYPE" = "deb" ]]; then - LIB_EXTENSION="/dist-packages" - if [[ "$SOURCE_ASSIGNED" = 0 ]]; then - SOURCE_DIR=~/debbuild/source - fi - if [[ "$BUILD_ASSIGNED" = 0 ]]; then - BUILD_DIR=~/debbuild/build - fi -elif [[ "$PACK_TYPE" = "rpm" ]]; then - LIB_EXTENSION="/site-packages" - if [[ "$SOURCE_ASSIGNED" = 0 ]]; then - SOURCE_DIR=~/rpmbuild/SOURCES - fi - if [[ "$BUILD_ASSIGNED" = 0 ]]; then - BUILD_DIR=~/rpmbuild/BUILD - fi -else # If package type is neither deb nor rpm, show an error message and exit - echo "$0 currently only supports 'deb' and 'rpm' packages." - usage; -fi - -# Directory cleaning and repository management -# Create SSM and DEB dir (if not present) -mkdir -p "$SOURCE_DIR" -mkdir -p "$BUILD_DIR" - -# Clean up any previous build -rm -rf "${SOURCE_DIR:?}"/* -rm -rf "${BUILD_DIR:?}"/* - -# Get and extract the source -TAR_FILE=${VERSION}-${ITERATION}.tar.gz -TAR_URL=https://github.com/apel/ssm/archive/$TAR_FILE -wget --no-check-certificate "$TAR_URL" -O "$TAR_FILE" -tar xvf "$TAR_FILE" -C "$SOURCE_DIR" -rm -f "$TAR_FILE" - -# Get supplied Python version -PY_VERSION="$(basename "$PYTHON_ROOT_DIR")" -PY_NUM=${PY_VERSION#python} - -# Universal FPM Call -FPM_CORE="fpm -s python \ - -t $PACK_TYPE \ - -n apel-ssm \ - -v $VERSION \ - --iteration $ITERATION \ - -m \"Apel Administrators \" \ - --description \"Secure Stomp Messenger (SSM).\" \ - --no-auto-depends " - -# Simple Python filter for version specific FPM -if [[ ${PY_NUM:0:1} == "3" ]]; then - echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." - - # python-stomp < 5.0.0 to python-stomp, python to python3/pip3 - # edited python-pip3 to python-pip - FPM_PYTHON="--depends python3 \ - --depends python-pip3 \ - --depends 'python-stomp' \ - --depends python-ldap \ - --depends libssl-dev \ - --depends libsasl2-dev \ - --depends openssl " - -elif [[ ${PY_NUM:0:1} == "2" ]]; then - echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." - - FPM_PYTHON="--depends python2.7 \ - --depends python-pip \ - --depends 'python-stomp < 5.0.0' \ - --depends python-ldap \ - --depends libssl-dev \ - --depends libsasl2-dev \ - --depends openssl " -fi - -# python-bin must always be specified in modern linux -PACKAGE_VERSION="--$PACK_TYPE-changelog $SOURCE_DIR/ssm-$VERSION-$ITERATION/CHANGELOG \ - --python-bin /usr/bin/$PY_VERSION \ - --python-install-lib $PYTHON_ROOT_DIR$LIB_EXTENSION \ - --exclude *.pyc \ - --package $BUILD_DIR \ - $SOURCE_DIR/ssm-$VERSION-$ITERATION/setup.py" - -# Construct and evaluate the primary FPM call -BUILD_PACKAGE_COMMAND=${FPM_CORE}${FPM_PYTHON}${VERBOSE}${PACKAGE_VERSION} -eval "$BUILD_PACKAGE_COMMAND" - -# When installed, use pleaserun to perform system specific service setup -fpm -s pleaserun -t "$PACK_TYPE" \ --n apel-ssm-service \ --v "$VERSION" \ ---iteration "$ITERATION" \ --m "Apel Administrators " \ ---description "Secure Stomp Messenger (SSM) Service Daemon files." \ ---architecture all \ ---no-auto-depends \ ---depends apel-ssm \ ---package "$BUILD_DIR" \ -/usr/bin/ssmreceive diff --git a/scripts/ssm-build.sh b/scripts/ssm-build.sh index f81eae51..38a043f4 100755 --- a/scripts/ssm-build.sh +++ b/scripts/ssm-build.sh @@ -163,9 +163,9 @@ elif [[ ${PY_NUM:0:1} == "2" ]]; then # el7 and below, due to yum package versions elif [[ "$PACK_TYPE" = "rpm" ]]; then - FPM_PYTHON="--depends python2.7 \ + FPM_PYTHON="--depends python2 \ --depends python2-pip \ - --depends 'python-stomp < 5.0.0' \ + --depends stomppy \ --depends python-ldap \ --depends openssl \ --depends openssl-devel " From d0261d8ae827da20ba03ec3dc5c0e787b4c72fcb Mon Sep 17 00:00:00 2001 From: RedProkofiev <87487335+RedProkofiev@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:21:36 +0000 Subject: [PATCH 3/4] Update usage comments Co-authored-by: Adrian Coveney <4836233+tofu-rocketry@users.noreply.github.com> --- scripts/ssm-build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/ssm-build.sh b/scripts/ssm-build.sh index 38a043f4..6cfb2d0a 100755 --- a/scripts/ssm-build.sh +++ b/scripts/ssm-build.sh @@ -9,7 +9,8 @@ # sudo gem install fpm -v 1.14.2 # for RPM builds, you will also need: # sudo yum install rpm-build | sudo apt-get install rpm -# ./ssm-build.sh (deb | rpm) e.g. +# ./ssm-build.sh (deb | rpm) +# e.g. # ./ssm-build.sh deb 3.4.0 1 /usr/lib/python3.6 # If you're struggling finding the right version of Python to use, consider opening interpreter and: # import site; site.getsitepackages() From 6286126f35829473668b6a37fc8a23bada85637b Mon Sep 17 00:00:00 2001 From: RedProkofiev <87487335+RedProkofiev@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:22:09 +0000 Subject: [PATCH 4/4] Update pleaserun setup message Co-authored-by: Adrian Coveney <4836233+tofu-rocketry@users.noreply.github.com> --- scripts/ssm-build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/ssm-build.sh b/scripts/ssm-build.sh index 6cfb2d0a..d2eb8248 100755 --- a/scripts/ssm-build.sh +++ b/scripts/ssm-build.sh @@ -187,7 +187,8 @@ PACKAGE_VERSION="--$PACK_TYPE-changelog $SOURCE_DIR/ssm-$VERSION-$ITERATION/CHAN # Construct and evaluate the primary FPM call BUILD_PACKAGE_COMMAND=${FPM_CORE}${FPM_PYTHON}${VERBOSE}${PACKAGE_VERSION} eval "$BUILD_PACKAGE_COMMAND" -echo "== BEGINNING PLEASERUN SETUP ==" + +echo "== Generating pleaserun package ==" # When installed, use pleaserun to perform system specific service setup fpm -s pleaserun -t "$PACK_TYPE" \