Skip to content

Commit

Permalink
Build/pleaserun
Browse files Browse the repository at this point in the history
  • Loading branch information
RedProkofiev committed Jan 17, 2024
1 parent a899bc0 commit d13b73e
Showing 1 changed file with 35 additions and 71 deletions.
106 changes: 35 additions & 71 deletions scripts/ssm-build.sh → scripts/ssm-build-dual.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Adapted from the Debian only build script, now with RPM!
# @Author: Nicholas Whyatt (RedProkofiev@github.com)

set -e
# Script runs well with FPM 1.14.2 on ruby 2.7.1, setuptools 51.3.3 on RHEL and Deb platforms

set -ex

usage() {
echo "Usage: $0 (deb | rpm) <version> <iteration> <python_root_dir> [options]"
Expand All @@ -16,17 +18,11 @@ usage() {
exit 1;
}

# cheap python hack!
# if ! python3 -c 'import sys; assert sys.version_info >= (3,6)' > /dev/null; then
# export PYTHON_VERSION=`python -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}".format(*version))'
# elif ! python2 -c 'import sys; assert sys.version_info >= (3,6)' > /dev/null; then

SOURCE_ASSIGNED=0
BUILD_ASSIGNED=0
BIN_DIR="/usr/bin/python3.8 " \

# Configurable options
while getopts ":hs:b:v:e" o; do
while getopts ":hs:b:v" o; do
case "${o}" in
h) echo "SSM Help"
usage;
Expand All @@ -40,10 +36,7 @@ while getopts ":hs:b:v:e" o; do
BUILD_ASSIGNED=1
;;
v) v=${OPTARG}
VERBOSE="--verbose " \
;;
e) e=${OPTARG}
BIN_DIR="$b " \
VERBOSE="--verbose "
;;
*) usage;
;;
Expand All @@ -62,9 +55,6 @@ VERSION=$2
ITERATION=$3
PYTHON_ROOT_DIR=$4 # i.e. /usr/lib/python3.6

# TODO: Replace rpm directories with their sensible equivalents
# It ain't pretty, but it is readable and it gets the job done
# LIB_EXTENSION is the install dir for python lib files, and is system dependent
if [[ "$PACK_TYPE" = "deb" ]]; then
LIB_EXTENSION="/dist-packages"
if [[ "$SOURCE_ASSIGNED" = 0 ]]; then
Expand All @@ -86,7 +76,6 @@ else # If package type is neither deb nor rpm, show an error message and exit
usage;
fi


# Directory cleaning and repository management
# Create SSM and DEB dir (if not present)
mkdir -p $SOURCE_DIR
Expand All @@ -98,7 +87,7 @@ 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
TAR_URL=https://github.com/RedProkofiev/ssm/archive/$TAR_FILE
wget --no-check-certificate $TAR_URL -O $TAR_FILE
tar xvf $TAR_FILE -C $SOURCE_DIR
rm -f $TAR_FILE
Expand All @@ -108,86 +97,61 @@ PY_VERSION=$(basename $PYTHON_ROOT_DIR)
PY_NUM=${PY_VERSION#python}
echo $PY_NUM


# Universal FPM Call
FPM_CORE="fpm -s python -t $PACK_TYPE \
FPM_CORE="fpm -s python \
-t $PACK_TYPE \
-n apel-ssm \
-v $VERSION \
--iteration $ITERATION \
-m \"Apel Administrators <apel-admins@stfc.ac.uk>\" \
--description \"Secure Stomp Messenger (SSM).\" \
--no-auto-depends " \

--no-auto-depends "

# Python 2
if (( ${PY_NUM:0:1} == 2 )) ; then
if (( ${PY_NUM:2:3} < 7 )) ; then # or version is later than 4.0.0
echo "Python version is insufficient, you supplied $PY_NUM when you need 2.7. Python 2 will be removed in 4.0.0."
usage;
fi
if [[ ${PY_NUM:0:1} == "3" ]]; 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' \
# 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 " \
--depends openssl "

# Python 3
elif (( ${PY_NUM:0:1} == 3 )) ; then
if (( ${PY_NUM:2:3} < 6 )) ; then
echo "Python version is insufficient, you supplied $PY_NUM when you need above 3.5."
usage;
fi
elif [[ ${PY_NUM:0:1} == "2" ]]; then
echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE."

# python-stomp < 5.0.0 to python-stomp
# everything else is chill
FPM_PYTHON="--depends python3.6 \
--depends python-pip3 \
--depends 'python-stomp' \
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

if [ "$PACK_TYPE" == "deb" ]; then
FPM_PYTHON="${FPM_PYTHON} --python-bin ${BIN_DIR}"
--depends openssl "
fi

# FPM Version Specific End
# Change pythoninstall lib?
# is it the darned changelog? Changelog source dir may be completely off.s
# Place changelog in specs.


# python-bin from python-install-bin
PACKAGE_VERSION="--$PACK_TYPE-changelog $SOURCE_DIR/ssm-$VERSION-$ITERATION/CHANGELOG \
--python-install-bin /usr/bin \
--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"


# Spaces betwixt verbose and package_version for --rpm-changelog, space here command not found renders package_version as sep command
# probably bash string handling issue, add handled string
BUILD_PACKAGE_COMMAND=${FPM_CORE}${FPM_PYTHON}${VERBOSE}${PACKAGE_VERSION}
echo $BUILD_PACKAGE_COMMAND
eval $BUILD_PACKAGE_COMMAND

echo "$BUILD_PACKAGE_COMMAND"
eval "$BUILD_PACKAGE_COMMAND"

fpm -s pleaserun -t $PACK_TYPE \
-n apel-ssm-service \
-v $VERSION \
--iteration $ITERATION \
-m "Apel Administrators <apel-admins@stfc.ac.uk>" \
--description "Secure Stomp Messenger (SSM) Service Daemon files." \
--architecture all \
--no-auto-depends \
--depends apel-ssm \
--package $BUILD_DIR \
/usr/bin/ssmreceive
-n apel-ssm-service \
-v $VERSION \
--iteration $ITERATION \
-m "Apel Administrators <apel-admins@stfc.ac.uk>" \
--description "Secure Stomp Messenger (SSM) Service Daemon files." \
--architecture all \
--no-auto-depends \
--depends apel-ssm \
--package $BUILD_DIR \
/usr/bin/ssmreceive

0 comments on commit d13b73e

Please sign in to comment.