Skip to content

Instantly share code, notes, and snippets.

@treydock
Created September 12, 2014 18:39
Show Gist options
  • Save treydock/ed5cd81978cbb838cf88 to your computer and use it in GitHub Desktop.
Save treydock/ed5cd81978cbb838cf88 to your computer and use it in GitHub Desktop.
SLURM build script
#!/bin/bash
RPMBUILD_OPTS="--define '_without_aix 1' \
--define '_with_blcr 1' \
--define '_with_lua 1' \
--define '_without_postgres 1' \
--define '_without_sgijob 1' \
--define '_with_pam 1' \
--define '_with_readline 1' \
--define '_with_mysql 1' \
--define '_with_openssl 1' \
--define '_with_phpext 1'"
# Default variables that have command line flags
QUIET=0
DEBUG=0
TRACE=0
NOOP=0
MOCK=0
RPMBUILD=0
EXTRACT_SPEC=0
DIST="el6"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MOCK_CONFIGDIR="${DIR}/mock"
echo_cmd() {
local cmd="$1"
[ $NOOP -eq 1 ] && noop_prefix="(NOOP) " || noop_prefix=""
echo "${noop_prefix}Executing: ${cmd}"
}
exec_cmd() {
local cmd="$1"
local RET=0
echo_cmd "$cmd"
#[ $NOOP -eq 1 ] && noop_prefix="(NOOP) " || noop_prefix=""
#echo "${noop_prefix}Executing: ${cmd}"
if [ $NOOP -eq 0 ]; then
if eval $cmd; then
RET=0
else
RET=1
fi
fi
return $RET
}
exec_cmd_stdout() {
local cmd="$1"
local output=""
if [ $NOOP -eq 0 ]; then
output=$(eval $cmd)
fi
echo $output
}
usage () {
cat << EOF
usage: $(basename $0) [OPTIONS] SLURM_VERSION [MD5SUM]
This script builds RPMs for $NAME.
OPTIONS:
--dist Dist value for rpmbuild
Default is ${DIST}
--mock Run mock rebuild of SRPMs
--rpmbuild Run rpmbuild -ba
--extract-spec Extract spec file
--debug Show debug output
This option also removes the mock --quiet option.
--trace Show the mock debug output
--noop Do not execute commands
-h, --help Show this message
EXAMPLE:
Exract spec file without building (so can be modified)
$(basename $0) --extract-spec 14.03.6
Build SRPMs and run mock rebuild using existing spec
$(basename $0) --mock 14.03.6
Build SRPMs and run mock rebuild using packaged spec
$(basename $0) --extract-spec --mock 14.03.6
Build RPMs using existing spec
$(basename $0) --rpmbuild 14.03.6
Build SRPMs and run mock rebuild with existing spec and using custom dist
$(basename $0) --mock 14.03.6 --dist 1.el6
EOF
}
ARGS=`getopt -o h -l dist:,mock,rpmbuild,extract-spec,help,debug,trace,noop -n "$0" -- "$@"`
[ $? -ne 0 ] && { usage; exit 1; }
eval set -- "${ARGS}"
while true; do
case "$1" in
-h|--help) usage ; exit 0 ;;
--dist) DIST=$2 ; shift 2 ;;
--mock) MOCK=1 ; shift ;;
--rpmbuild) RPMBUILD=1 ; shift ;;
--extract-spec) EXTRACT_SPEC=1 ; shift ;;
--debug) DEBUG=1 ; QUIET=0 shift ;;
--trace) TRACE=1 ; shift ;;
--noop) NOOP=1 ; shift ;;
--) shift ; break ;;
*) break ;;
esac
done
[ $DEBUG -eq 1 ] && set -x
if [ $# -lt 1 ]; then
echo "Missing SLURM_VERSION argument"
usage
exit 1
fi
SLURM_VERSION=$1
SLURM_MD5SUM=$2
# Handle the dist version when in version string
#DIST_VERSION=$(echo ${SLURM_VERSION} | sed -r -n 's/[0-9.]+(-[0-9]+)/\1/p')
DIST_VERSION=$(echo ${SLURM_VERSION} | awk -F'-' '{ print $2}')
[ -z "${DIST_VERSION}" ] && SLURM_DIST_VERSION="-1" || SLURM_DIST_VERSION="-${DIST_VERSION}"
BASE_DEFINES="--define 'dist .${DIST}' --define 'rhel 6'"
RPM_VERSION="${SLURM_VERSION}${SLURM_DIST_VERSION}.${DIST}"
RPMBUILD_OPTS="${BASE_DEFINES} ${RPMBUILD_OPTS}"
# Set variables based on command line flags
[ $TRACE -eq 1 ] && mock_trace="--trace" || mock_trace=""
[ $QUIET -eq 1 ] && mock_quiet="--quiet" || mock_quiet=""
MOCK_OPTS="-r epel-6-x86_64 --configdir=${MOCK_CONFIGDIR} ${mock_quiet} ${mock_trace}"
exec_cmd "cd ${DIR}"
if [ ! -f SOURCES/slurm-${SLURM_VERSION}.tar.bz2 ]
then
exec_cmd "wget http://www.schedmd.com/download/latest/slurm-${SLURM_VERSION}.tar.bz2 -O SOURCES/slurm-${SLURM_VERSION}.tar.bz2 &>/dev/null"
if [ $? -ne 0 ]; then
echo "Failed to download, trying archive URL"
exec_cmd "rm -f SOURCES/slurm-${SLURM_VERSION}.tar.bz2"
exec_cmd "wget http://www.schedmd.com/download/archive/slurm-${SLURM_VERSION}.tar.bz2 -O SOURCES/slurm-${SLURM_VERSION}.tar.bz2 &>/dev/null"
[ $? -ne 0 ] && { echo "Failed to download, exiting..."; exit 1; }
fi
fi
# Verify MD5 checksum if it was provided as argument
if [ ! -z "${SLURM_MD5SUM}" ]; then
exec_cmd "md5sum SOURCES/slurm-${SLURM_VERSION}.tar.bz2 | grep -q ${SLURM_MD5SUM}"
[ $? -ne 0 ] && { echo "MD5 verification failed, exiting..."; exit 1; }
fi
if [ $EXTRACT_SPEC -eq 1 ]; then
exec_cmd "tar xjf SOURCES/slurm-${SLURM_VERSION}.tar.bz2 -C ./ --strip 1 slurm-${SLURM_VERSION}/slurm.spec"
[ $? -ne 0 ] && { echo "Failed extracting updated slurm.spec, exiting..."; exit 1; }
fi
if [ $MOCK -eq 1 ]; then
srpm_cmd="rpmbuild -bs --define '_topdir ${DIR}' ${RPMBUILD_OPTS} slurm.spec"
echo_cmd "$srpm_cmd"
OUTPUT=$(exec_cmd_stdout "$srpm_cmd")
SRPM=$(echo $OUTPUT | tr -s ' ' | cut -d ' ' -f 2)
RPM_VERSION=$(echo $SRPM | sed -r 's|.*/slurm-(.*).src.rpm|\1|g')
exec_cmd "mock ${MOCK_OPTS} --resultdir=${DIR}/RPMS/\"%(dist)s\"/\"%(target_arch)s\"/${RPM_VERSION}/ ${RPMBUILD_OPTS} --rebuild ${SRPM}"
elif [ $RPMBUILD -eq 1 ]; then
exec_cmd "rpmbuild -ba --define '_topdir ${DIR}' ${RPMBUILD_OPTS} slurm.spec"
#else
# exec_cmd "rpmbuild -bs --define '_topdir ${DIR}' ${RPMBUILD_OPTS} slurm.spec"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment