|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Apel-SSM Build Script 2.0: FPM edition |
| 4 | +# Adapted from the Debian only build script, now with RPM! |
| 5 | +# @Author: Nicholas Whyatt (RedProkofiev@github.com) |
| 6 | + |
| 7 | +# Script runs well with FPM 1.14.2 on ruby 2.7.1, setuptools 51.3.3 on RHEL and Deb platforms |
| 8 | +# Download ruby (if you're locked to 2.5, use RVM) and then run: |
| 9 | +# sudo gem install fpm -v 1.14.2 |
| 10 | +# ./ssm-build-dual.sh (deb | rpm) <version> <iteration> <python_root_dir> e.g. |
| 11 | +# ./ssm-build.dual.sh deb 3.4.0 1 /usr/lib/python3.6 |
| 12 | +# For SSM 3.4.0 and up. Versions before that would technically work, but the changelog |
| 13 | +# then was in a Debian format that doesn't parse and fails hard if you want to build RPM. |
| 14 | + |
| 15 | +set -e |
| 16 | + |
| 17 | +usage() { |
| 18 | + echo "Usage: $0 [options] (deb | rpm) <version> <iteration> <python_root_dir> " |
| 19 | + echo -e "Build script for Apel-SSM.\n" |
| 20 | + echo " -h Displays help." |
| 21 | + echo " -v Verbose FPM output." |
| 22 | + echo " -s <source_dir> Directory of source files. Defaults to /debbuild/source or SOME RPM DIR." |
| 23 | + echo -e " -b <build_dir> Directory of build files. Defaults to /debbuild/build or SOME RPM DIR.\n" 1>&2; |
| 24 | + exit 1; |
| 25 | +} |
| 26 | + |
| 27 | +# Bool flags to prevent automatic overwrite of input |
| 28 | +SOURCE_ASSIGNED=0 |
| 29 | +BUILD_ASSIGNED=0 |
| 30 | + |
| 31 | +# Configurable options |
| 32 | +while getopts ":hs:b:v" o; do |
| 33 | + case "${o}" in |
| 34 | + h) echo "SSM Help" |
| 35 | + usage; |
| 36 | + ;; |
| 37 | + s) s=${OPTARG} |
| 38 | + SOURCE_DIR=$s |
| 39 | + SOURCE_ASSIGNED=1 |
| 40 | + ;; |
| 41 | + b) b=${OPTARG} |
| 42 | + BUILD_DIR=$b |
| 43 | + BUILD_ASSIGNED=1 |
| 44 | + ;; |
| 45 | + v) VERBOSE="--verbose " |
| 46 | + ;; |
| 47 | + *) usage; |
| 48 | + ;; |
| 49 | + esac |
| 50 | +done |
| 51 | +shift $((OPTIND-1)) |
| 52 | + |
| 53 | +# Check how any arguments there are |
| 54 | +if [ "$#" -ne 4 ]; then |
| 55 | + echo "Expected 4 arguments, $# given." |
| 56 | + usage; |
| 57 | +fi |
| 58 | + |
| 59 | +PACK_TYPE=$1 |
| 60 | +VERSION=$2 |
| 61 | +ITERATION=$3 |
| 62 | +PYTHON_ROOT_DIR=$4 # i.e. /usr/lib/python3.6 |
| 63 | + |
| 64 | +# Alter library, build and source directories depending on the package |
| 65 | +if [[ "$PACK_TYPE" = "deb" ]]; then |
| 66 | + LIB_EXTENSION="/dist-packages" |
| 67 | + if [[ "$SOURCE_ASSIGNED" = 0 ]]; then |
| 68 | + SOURCE_DIR=~/debbuild/source |
| 69 | + fi |
| 70 | + if [[ "$BUILD_ASSIGNED" = 0 ]]; then |
| 71 | + BUILD_DIR=~/debbuild/build |
| 72 | + fi |
| 73 | +elif [[ "$PACK_TYPE" = "rpm" ]]; then |
| 74 | + LIB_EXTENSION="/site-packages" |
| 75 | + if [[ "$SOURCE_ASSIGNED" = 0 ]]; then |
| 76 | + SOURCE_DIR=~/rpmbuild/SOURCES |
| 77 | + fi |
| 78 | + if [[ "$BUILD_ASSIGNED" = 0 ]]; then |
| 79 | + BUILD_DIR=~/rpmbuild/BUILD |
| 80 | + fi |
| 81 | +else # If package type is neither deb nor rpm, show an error message and exit |
| 82 | + echo "$0 currently only supports 'deb' and 'rpm' packages." |
| 83 | + usage; |
| 84 | +fi |
| 85 | + |
| 86 | +# Directory cleaning and repository management |
| 87 | +# Create SSM and DEB dir (if not present) |
| 88 | +mkdir -p "$SOURCE_DIR" |
| 89 | +mkdir -p "$BUILD_DIR" |
| 90 | + |
| 91 | +# Clean up any previous build |
| 92 | +rm -rf "${SOURCE_DIR:?}"/* |
| 93 | +rm -rf "${BUILD_DIR:?}"/* |
| 94 | + |
| 95 | +# Get and extract the source |
| 96 | +TAR_FILE=${VERSION}-${ITERATION}.tar.gz |
| 97 | +TAR_URL=https://github.com/apel/ssm/archive/$TAR_FILE |
| 98 | +wget --no-check-certificate "$TAR_URL" -O "$TAR_FILE" |
| 99 | +tar xvf "$TAR_FILE" -C "$SOURCE_DIR" |
| 100 | +rm -f "$TAR_FILE" |
| 101 | + |
| 102 | +# Get supplied Python version |
| 103 | +PY_VERSION="$(basename "$PYTHON_ROOT_DIR")" |
| 104 | +PY_NUM=${PY_VERSION#python} |
| 105 | + |
| 106 | +# Universal FPM Call |
| 107 | +FPM_CORE="fpm -s python \ |
| 108 | + -t $PACK_TYPE \ |
| 109 | + -n apel-ssm \ |
| 110 | + -v $VERSION \ |
| 111 | + --iteration $ITERATION \ |
| 112 | + -m \"Apel Administrators <apel-admins@stfc.ac.uk>\" \ |
| 113 | + --description \"Secure Stomp Messenger (SSM).\" \ |
| 114 | + --no-auto-depends " |
| 115 | + |
| 116 | +# Simple Python filter for version specific FPM |
| 117 | +if [[ ${PY_NUM:0:1} == "3" ]]; then |
| 118 | + echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." |
| 119 | + |
| 120 | + # python-stomp < 5.0.0 to python-stomp, python to python3/pip3 |
| 121 | + # edited python-pip3 to python-pip |
| 122 | + FPM_PYTHON="--depends python3 \ |
| 123 | + --depends python-pip3 \ |
| 124 | + --depends 'python-stomp' \ |
| 125 | + --depends python-ldap \ |
| 126 | + --depends libssl-dev \ |
| 127 | + --depends libsasl2-dev \ |
| 128 | + --depends openssl " |
| 129 | + |
| 130 | +elif [[ ${PY_NUM:0:1} == "2" ]]; then |
| 131 | + echo "Building $VERSION iteration $ITERATION for Python $PY_NUM as $PACK_TYPE." |
| 132 | + |
| 133 | + FPM_PYTHON="--depends python2.7 \ |
| 134 | + --depends python-pip \ |
| 135 | + --depends 'python-stomp < 5.0.0' \ |
| 136 | + --depends python-ldap \ |
| 137 | + --depends libssl-dev \ |
| 138 | + --depends libsasl2-dev \ |
| 139 | + --depends openssl " |
| 140 | +fi |
| 141 | + |
| 142 | +# python-bin must always be specified in modern linux |
| 143 | +PACKAGE_VERSION="--$PACK_TYPE-changelog $SOURCE_DIR/ssm-$VERSION-$ITERATION/CHANGELOG \ |
| 144 | + --python-bin /usr/bin/$PY_VERSION \ |
| 145 | + --python-install-lib $PYTHON_ROOT_DIR$LIB_EXTENSION \ |
| 146 | + --exclude *.pyc \ |
| 147 | + --package $BUILD_DIR \ |
| 148 | + $SOURCE_DIR/ssm-$VERSION-$ITERATION/setup.py" |
| 149 | + |
| 150 | +# Construct and evaluate the primary FPM call |
| 151 | +BUILD_PACKAGE_COMMAND=${FPM_CORE}${FPM_PYTHON}${VERBOSE}${PACKAGE_VERSION} |
| 152 | +eval "$BUILD_PACKAGE_COMMAND" |
| 153 | + |
| 154 | +# When installed, use pleaserun to perform system specific service setup |
| 155 | +fpm -s pleaserun -t "$PACK_TYPE" \ |
| 156 | +-n apel-ssm-service \ |
| 157 | +-v "$VERSION" \ |
| 158 | +--iteration "$ITERATION" \ |
| 159 | +-m "Apel Administrators <apel-admins@stfc.ac.uk>" \ |
| 160 | +--description "Secure Stomp Messenger (SSM) Service Daemon files." \ |
| 161 | +--architecture all \ |
| 162 | +--no-auto-depends \ |
| 163 | +--depends apel-ssm \ |
| 164 | +--package "$BUILD_DIR" \ |
| 165 | +/usr/bin/ssmreceive |
0 commit comments