## ## Obtain various platform information ## OS=`uname` if [ "${OS}" != "Linux" ] ; then printf "'$0' is ONLY available on '${OS}'!\n" exit 255 fi PLATFORM=`uname -p` if [ "${PLATFORM}" = "i686" ] ; then ARCHITECTURE="32-bit" elif [ "${PLATFORM}" = "x86_64" ] ; then ARCHITECTURE="64-bit" else printf "'$0' is ONLY available on 'i686' or 'x86_64' platforms!\n" exit 255 fi if [ -f "/etc/redhat-release" ] ; then DISTRIBUTION=`cat /etc/redhat-release | cut -c1-7` DIST_VERSION=`cat /etc/redhat-release | tr -d [:alpha:][:blank:][\(\)]` if [ "${DISTRIBUTION}" = "Fedora " ] ; then MESSAGE="[built for ${ARCHITECTURE} Fedora ${DIST_VERSION}]" elif [ "${DISTRIBUTION}" = "Red Hat" ] ; then MESSAGE="[built for ${ARCHITECTURE} Red Hat ${DIST_VERSION}]" else printf "'$0' is ONLY available on 'Fedora' or 'Red Hat' " printf "distributions!\n" exit 255 fi else printf "'$0' is ONLY available on 'Fedora' or 'Red Hat' distributions!\n" exit 255 fi ## ## Establish various shared variables ## PKI_DIR="pki" export PKI_DIR PKI_BASE_DIR="${PKI_DIR}/base" export PKI_BASE_DIR PKI_DOGTAG_DIR="${PKI_DIR}/dogtag" export PKI_DOGTAG_DIR PKI_FILE_LIST="CMakeLists.txt COPYING CPackConfig.cmake ConfigureChecks.cmake DefineOptions.cmake README cmake_uninstall.cmake.in config.h.cmake" export PKI_FILE_LIST PKI_CMAKE_DIR="cmake" export PKI_CMAKE_DIR PKI_BASE_MANIFEST="CMakeLists.txt" export PKI_BASE_MANIFEST PKI_DOGTAG_MANIFEST="CMakeLists.txt" export PKI_DOGTAG_MANIFEST ## ## Usage statement ## Usage() { printf "\n" printf "Usage: $0 [options] \n\n" printf " where is one of the following:\n\n" printf " srpm - copies a spec file from local source,\n" printf " generates a tarball from local source,\n" printf " copies any relevant patches from the\n" printf " local 'patches' directory, and\n" printf " produces an SRPM\n" printf " [suitable for use by 'mock']\n\n" printf " rpms - copies a spec file from local source,\n" printf " generates a tarball from local source,\n" printf " copies any relevant patches from the\n" printf " local 'patches' directory, and\n" printf " produces an SRPM and one or more RPMS\n" printf " ${MESSAGE}\n\n" printf " hybrid_srpm - copies a spec file from local source,\n" printf " generates a tarball from local source,\n" printf " fetches any relevant patches from the\n" printf " spec's URL, and\n" printf " produces an SRPM\n" printf " [suitable for use by 'mock']\n\n" printf " hybrid_rpms - copies a spec file from local source,\n" printf " generates a tarball from local source,\n" printf " fetches any relevant patches from the\n" printf " spec's URL, and\n" printf " produces an SRPM and one or more RPMS\n" printf " ${MESSAGE}\n\n" printf " patched_srpm - copies a spec file from local source,\n" printf " fetches a tarball from the spec's URL,\n" printf " fetches any relevant patches from the\n" printf " spec's URL, and\n" printf " produces an SRPM\n" printf " [suitable for use by 'mock']\n\n" printf " patched_rpms - copies a spec file from local source,\n" printf " fetches a tarball from the spec's URL,\n" printf " fetches any relevant patches from the\n" printf " spec's URL, and\n" printf " produces an SRPM and one or more RPMS\n" printf " ${MESSAGE}\n\n" printf "Options:\n" printf " --without-javadoc do not build Javadoc RPMS\n\n" } ## ## Copy Specified Patches to SOURCES ## Fetch_Patch_Files() { if [ $# -ne 2 ] ; then Usage exit 255 fi SPECFILE=$1 TARGET_DIR=$2 if [ ! -f ${SPECFILE} ] ; then printf "ERROR: '${SPECFILE}' is missing!\n\n" Usage exit 255 elif [ ! -d ${TARGET_DIR} ] ; then printf "ERROR: '${TARGET_DIR}' does NOT exist!\n\n" Usage exit 255 fi component_name_marker="Name" component_version_marker="Version" component_source_marker="Source" component_patch_marker="Patch" component_name="" component_version="" component_source="" component_url="" component_patch="" exec < ${SPECFILE} while read line; do entry=`echo $line | cut -d: -f 1` if [ "${entry:0:4}" = "${component_name_marker}" ] ; then component_name=`echo $line | cut -d' ' -f 2` elif [ "${entry:0:7}" = "${component_version_marker}" ] ; then component_version=`echo $line | cut -d' ' -f 2` elif [ "${entry:0:6}" = "${component_source_marker}" ] ; then value=`echo $line | cut -d' ' -f 2` component_source=`echo $value | sed -e "s/\%{name}/${component_name}/g" -e "s/\%{version}/${component_version}/g"` component_url=`dirname ${component_source}` elif [ "${entry:0:5}" = "${component_patch_marker}" ] ; then if [ ${component_url} != "" ] ; then value=`echo $line | cut -d' ' -f 2` component_patch=${component_url}"/"`echo $value | sed -e "s/\%{name}/${component_name}/g" -e "s/\%{version}/${component_version}/g"` wget -q -O ${TARGET_DIR}/`basename ${component_patch}` ${component_patch} if [ $? -ne 0 ] ; then printf "ERROR: Failed to download '${component_patch}'!\n\n" Usage exit 255 elif [ ! -f ${TARGET_DIR}/`basename ${component_patch}` ] ; then printf "ERROR: Failed to save '${TARGET_DIR}/`basename ${component_patch}`'!\n\n" Usage exit 255 fi else printf "ERROR: '${component_source_marker}' MUST be specified PRIOR to '${component_patch_marker}'!\n\n" Usage exit 255 fi fi done } ## ## Copy Specified Source Tarball to SOURCES ## Fetch_Source_Tarball() { if [ $# -ne 2 ] ; then Usage exit 255 fi SPECFILE=$1 TARGET_DIR=$2 if [ ! -f ${SPECFILE} ] ; then printf "ERROR: '${SPECFILE}' is missing!\n\n" Usage exit 255 elif [ ! -d ${TARGET_DIR} ] ; then printf "ERROR: '${TARGET_DIR}' does NOT exist!\n\n" Usage exit 255 fi component_name_marker="Name" component_version_marker="Version" component_tarball_marker="Source" component_name="" component_version="" component_tarball="" exec < ${SPECFILE} while read line; do entry=`echo $line | cut -d: -f 1` if [ "${entry:0:4}" = "${component_name_marker}" ] ; then component_name=`echo $line | cut -d' ' -f 2` elif [ "${entry:0:7}" = "${component_version_marker}" ] ; then component_version=`echo $line | cut -d' ' -f 2` elif [ "${entry:0:6}" = "${component_tarball_marker}" ] ; then value=`echo $line | cut -d' ' -f 2` component_tarball=`echo $value | sed -e "s/\%{name}/${component_name}/g" -e "s/\%{version}/${component_version}/g"` wget -q -O ${TARGET_DIR}/`basename ${component_tarball}` ${component_tarball} if [ $? -ne 0 ] ; then printf "ERROR: Failed to download '${component_tarball}'!\n\n" Usage exit 255 elif [ ! -f ${TARGET_DIR}/`basename ${component_tarball}` ] ; then printf "ERROR: Failed to save '${TARGET_DIR}/`basename ${component_tarball}`'!\n\n" Usage exit 255 fi fi done } ## ## Check for command line argument validity ## GETOPT=`getopt -o '' -l without-javadoc -n "$0" -- "$@"` if [ $? != 0 ] ; then Usage exit 255 fi eval set -- "$GETOPT" while true ; do case "$1" in --without-javadoc) JAVADOC="--without javadoc" ; shift ;; --) shift ; break ;; *) echo "$0: unrecognized option '$1'" 1>&2 ; exit 255 ;; esac done if [ $# -ne 1 ] ; then Usage exit 255 fi if [ $1 = "srpm" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -bs" FETCH_SOURCE_TARBALL=0 FETCH_PATCH_FILES=0 elif [ $1 = "hybrid_srpm" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -bs" FETCH_SOURCE_TARBALL=0 FETCH_PATCH_FILES=1 elif [ $1 = "patched_srpm" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -bs" FETCH_SOURCE_TARBALL=1 FETCH_PATCH_FILES=1 elif [ $1 = "rpms" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -ba" FETCH_SOURCE_TARBALL=0 FETCH_PATCH_FILES=0 elif [ $1 = "hybrid_rpms" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -ba" FETCH_SOURCE_TARBALL=0 FETCH_PATCH_FILES=1 elif [ $1 = "patched_rpms" ] ; then RPMBUILD_CMD="rpmbuild --define \"_topdir \`pwd\`\" $JAVADOC -ba" FETCH_SOURCE_TARBALL=1 FETCH_PATCH_FILES=1 else Usage exit 255 fi export RPMBUILD_CMD