eef588dfe267122da34ad3290000c74b04c22cfcjim#!/bin/bash
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim# Authors:
eef588dfe267122da34ad3290000c74b04c22cfcjim# Lukas Slebodnik <lslebodn@redhat.com>
eef588dfe267122da34ad3290000c74b04c22cfcjim#
eef588dfe267122da34ad3290000c74b04c22cfcjim# Copyright (C) 2013 Red Hat
eef588dfe267122da34ad3290000c74b04c22cfcjim#
eef588dfe267122da34ad3290000c74b04c22cfcjim# This program is free software; you can redistribute it and/or modify
eef588dfe267122da34ad3290000c74b04c22cfcjim# it under the terms of the GNU General Public License as published by
eef588dfe267122da34ad3290000c74b04c22cfcjim# the Free Software Foundation; either version 3 of the License, or
eef588dfe267122da34ad3290000c74b04c22cfcjim# (at your option) any later version.
eef588dfe267122da34ad3290000c74b04c22cfcjim#
eef588dfe267122da34ad3290000c74b04c22cfcjim# This program is distributed in the hope that it will be useful,
eef588dfe267122da34ad3290000c74b04c22cfcjim# but WITHOUT ANY WARRANTY; without even the implied warranty of
eef588dfe267122da34ad3290000c74b04c22cfcjim# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eef588dfe267122da34ad3290000c74b04c22cfcjim# GNU General Public License for more details.
eef588dfe267122da34ad3290000c74b04c22cfcjim#
eef588dfe267122da34ad3290000c74b04c22cfcjim# You should have received a copy of the GNU General Public License
eef588dfe267122da34ad3290000c74b04c22cfcjim# along with this program. If not, see <http://www.gnu.org/licenses/>.
eef588dfe267122da34ad3290000c74b04c22cfcjim
12b170a812f740fafc96da32a188a8b2761a3d5cjimPACKAGE_NAME="sssd"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimusage(){
eef588dfe267122da34ad3290000c74b04c22cfcjim echo "$(basename $0) [OPTIONS] [-P|--patches <patch>...]"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin echo -e "\t-p, --prerelease Create prerelease SRPM"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin echo -e "\t-d, --debug Enable debugging."
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin echo -e "\t-c, --clean Remove directory rpmbuild and exit."
eef588dfe267122da34ad3290000c74b04c22cfcjim echo -e "\t-P, --patches Requires list of patches for SRPM."
eef588dfe267122da34ad3290000c74b04c22cfcjim echo -e "\t-h, --help Print this help and exit."
eef588dfe267122da34ad3290000c74b04c22cfcjim echo -e "\t-?, --usage"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim exit 1
eef588dfe267122da34ad3290000c74b04c22cfcjim}
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimadd_patches(){
eef588dfe267122da34ad3290000c74b04c22cfcjim spec_file=$1
eef588dfe267122da34ad3290000c74b04c22cfcjim shift
eef588dfe267122da34ad3290000c74b04c22cfcjim source_dir=$1
eef588dfe267122da34ad3290000c74b04c22cfcjim shift
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim patches=("${@}")
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim # These keep track of our spec file substitutions.
eef588dfe267122da34ad3290000c74b04c22cfcjim i=1
eef588dfe267122da34ad3290000c74b04c22cfcjim prefix="Source0:"
eef588dfe267122da34ad3290000c74b04c22cfcjim prepprefix="%setup"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim # If no patches exist, just exit.
eef588dfe267122da34ad3290000c74b04c22cfcjim if [ -z "$patches" ]; then
eef588dfe267122da34ad3290000c74b04c22cfcjim echo Creating SRPM without extra patches.
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere return 0
eef588dfe267122da34ad3290000c74b04c22cfcjim fi
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjim # Add the patches to the specfile.
eef588dfe267122da34ad3290000c74b04c22cfcjim for p in "${patches[@]}"; do
eef588dfe267122da34ad3290000c74b04c22cfcjim cp "$p" "$source_dir"
eef588dfe267122da34ad3290000c74b04c22cfcjim p=$(basename $p)
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin echo "Adding patch to spec file - $p"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin sed -i -e "/${prefix}/a Patch${i}: ${p}" \
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin -e "/$prepprefix/a %patch${i} -p1" \
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin "$spec_file"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin prefix="Patch${i}:"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin prepprefix="%patch${i}"
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin i=$(($i+1))
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin done
185aa71728867671e105178b4c66fbc22b65ae26sf}
eef588dfe267122da34ad3290000c74b04c22cfcjim
aee938da5530729ca29b60015120c487d5e1bcacjimfor i in "$@"
eef588dfe267122da34ad3290000c74b04c22cfcjimdo
eef588dfe267122da34ad3290000c74b04c22cfcjimcase $i in
eef588dfe267122da34ad3290000c74b04c22cfcjim -p|--prerelease)
eef588dfe267122da34ad3290000c74b04c22cfcjim PRERELEASE=1
eef588dfe267122da34ad3290000c74b04c22cfcjim shift
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere ;;
eef588dfe267122da34ad3290000c74b04c22cfcjim -d|--debug)
eef588dfe267122da34ad3290000c74b04c22cfcjim set -x
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere shift
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere ;;
eef588dfe267122da34ad3290000c74b04c22cfcjim -c|--clean)
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim CLEAN=1
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim shift
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim ;;
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim -P|--patches)
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim shift
eef588dfe267122da34ad3290000c74b04c22cfcjim patches=("$@")
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim break
4efeaf392b8e7584b7fe240e8c6116837c3f54bajim ;;
eef588dfe267122da34ad3290000c74b04c22cfcjim -h|--help|-\?|--usage)
eef588dfe267122da34ad3290000c74b04c22cfcjim usage
eef588dfe267122da34ad3290000c74b04c22cfcjim ;;
eef588dfe267122da34ad3290000c74b04c22cfcjim *)
eef588dfe267122da34ad3290000c74b04c22cfcjim # unknown option
eef588dfe267122da34ad3290000c74b04c22cfcjim ;;
834fc281be8e0f7f2614961f12d8bbf603382a17jfclereesac
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrindone
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimRPMBUILD="$(pwd)/rpmbuild"
eef588dfe267122da34ad3290000c74b04c22cfcjimif [ -n "$CLEAN" ]; then
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere rm -rfv "$RPMBUILD"
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere exit 0
834fc281be8e0f7f2614961f12d8bbf603382a17jfclerefi
eef588dfe267122da34ad3290000c74b04c22cfcjim
834fc281be8e0f7f2614961f12d8bbf603382a17jfclereSRC_DIR=$(git rev-parse --show-toplevel)
eef588dfe267122da34ad3290000c74b04c22cfcjimrc=$?
eef588dfe267122da34ad3290000c74b04c22cfcjimif [ $rc != 0 ]; then
eef588dfe267122da34ad3290000c74b04c22cfcjim echo "This script must be run from the $PACKAGE_NAME git repository!"
eef588dfe267122da34ad3290000c74b04c22cfcjim exit 1;
eef588dfe267122da34ad3290000c74b04c22cfcjimfi
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimif [ "x$SRC_DIR" = x ]; then
eef588dfe267122da34ad3290000c74b04c22cfcjim echo "Fatal: Could not find source directory!"
eef588dfe267122da34ad3290000c74b04c22cfcjim exit 1;
eef588dfe267122da34ad3290000c74b04c22cfcjimfi
185aa71728867671e105178b4c66fbc22b65ae26sf
eef588dfe267122da34ad3290000c74b04c22cfcjimVERSION_FILE="$SRC_DIR/version.m4"
23a31b10f869a72c9197b5f153f4f3e1a4c68f28jimSPEC_TEMPLATE="$SRC_DIR/contrib/$PACKAGE_NAME.spec.in"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimif [ ! -f "$VERSION_FILE" ]; then
eef588dfe267122da34ad3290000c74b04c22cfcjim echo "Fatal: Could not find file version.m4 in source directory!"
eef588dfe267122da34ad3290000c74b04c22cfcjim exit 1;
eef588dfe267122da34ad3290000c74b04c22cfcjimfi
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim
19f5359fc7b955a110e5ebe345ef4962cdd76473jailletcif [ ! -f "$SPEC_TEMPLATE" ]; then
19f5359fc7b955a110e5ebe345ef4962cdd76473jailletc echo "Fatal: Could not find $PACKAGE_NAME.spec.in in contrib subdirectory!"
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim exit 1;
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jimfi
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jimPACKAGE_VERSION=$(grep "\[VERSION_NUMBER\]" $VERSION_FILE \
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim | sed -e 's/.*\[//' -e 's/\]).*$//')
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jimif [ "x$PACKAGE_VERSION" = x ]; then
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim echo "Fatal: Could parse version from file:$VERSION_FILE!"
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim exit 1;
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jimfi
2c4ed36c350564e8bfb68e9d9ba58fe77b9bf3c0jim
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jimPRERELEASE_VERSION=""
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jimif [ -n "$PRERELEASE" ]; then
19f5359fc7b955a110e5ebe345ef4962cdd76473jailletc PRERELEASE_VERSION=.$(date +%Y%m%d.%H%M).git$(git log -1 --pretty=format:%h)
19f5359fc7b955a110e5ebe345ef4962cdd76473jailletcfi
19f5359fc7b955a110e5ebe345ef4962cdd76473jailletc
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jimmkdir -p $RPMBUILD/BUILD
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jimmkdir -p $RPMBUILD/RPMS
eef588dfe267122da34ad3290000c74b04c22cfcjimmkdir -p $RPMBUILD/SOURCES
eef588dfe267122da34ad3290000c74b04c22cfcjimmkdir -p $RPMBUILD/SPECS
eef588dfe267122da34ad3290000c74b04c22cfcjimmkdir -p $RPMBUILD/SRPMS
eef588dfe267122da34ad3290000c74b04c22cfcjim
9a0e1ad272fdbe3fee989e93bdae8253418429edjfcleresed -e "s/@PACKAGE_NAME@/$PACKAGE_NAME/" \
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jim -e "s/@PACKAGE_VERSION@/$PACKAGE_VERSION/" \
9a0e1ad272fdbe3fee989e93bdae8253418429edjfclere -e "s/@PRERELEASE_VERSION@/$PRERELEASE_VERSION/" \
eef588dfe267122da34ad3290000c74b04c22cfcjim < "$SPEC_TEMPLATE" \
eef588dfe267122da34ad3290000c74b04c22cfcjim > "$RPMBUILD/SPECS/$PACKAGE_NAME.spec"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimNAME="$PACKAGE_NAME-$PACKAGE_VERSION"
eef588dfe267122da34ad3290000c74b04c22cfcjimgit archive --format=tar --prefix="$NAME"/ \
eef588dfe267122da34ad3290000c74b04c22cfcjim --remote="file://$SRC_DIR" \
eef588dfe267122da34ad3290000c74b04c22cfcjim HEAD \
eef588dfe267122da34ad3290000c74b04c22cfcjim | gzip > "$RPMBUILD/SOURCES/$NAME.tar.gz"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimcp "$SRC_DIR"/contrib/*.patch "$RPMBUILD/SOURCES" 2>/dev/null
eef588dfe267122da34ad3290000c74b04c22cfcjimadd_patches "$RPMBUILD/SPECS/$PACKAGE_NAME.spec" \
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf "$RPMBUILD/SOURCES" \
eef588dfe267122da34ad3290000c74b04c22cfcjim "${patches[@]}"
eef588dfe267122da34ad3290000c74b04c22cfcjim
eef588dfe267122da34ad3290000c74b04c22cfcjimcd $RPMBUILD
eef588dfe267122da34ad3290000c74b04c22cfcjimrpmbuild --define "_topdir $RPMBUILD" \
eef588dfe267122da34ad3290000c74b04c22cfcjim -bs SPECS/$PACKAGE_NAME.spec
eef588dfe267122da34ad3290000c74b04c22cfcjim