From 87c8aeb8f6ce270f06b57336c421fffe7903434d Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Jun 25 2014 17:38:48 +0000 Subject: Added script to re-create SRPM from git commit --- diff --git a/README.md b/README.md index 97020f3..cdc37a5 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ This git repo contains the following scripts that make interfacing with git.c.o, Tools: * get_sources.sh: when run from inside a package git checkout, will download the relevant non-text sources from the lookaside cache and drop them into the SOURCES/ dir; note: it will generate 0 byte files in place, rather than download them. + * into_srpm.sh: reconstructs the srpm from a given commit + * centos.git.repolist.py: This package gets list of repos from gitblit RPC, used to grab CentOS sources. Requires the package 'python-requests' which is in the EPEL repo for CentOS-6. Has a -b switch to pick a specific branch (defaults to master, but you might want to use -b c7) * return_disttag.sh: Extracts what appears to be the value of %{dist} from the commit message diff --git a/into_srpm.sh b/into_srpm.sh new file mode 100755 index 0000000..32f02b2 --- /dev/null +++ b/into_srpm.sh @@ -0,0 +1,152 @@ +#!/bin/bash -u +# +# Turn a centos git repo into a .src.rpm file +# +# Might want to drop this in ~/bin/ and chmod u+x it + +# +# License: GPLv2 +# +# Initial Author: Pat Riehecky +# + +##################################################################### +usage() { + echo '' >&2 + echo "$0 [-hq] [-b branch] [-c shasum]" >&2 + echo '' >&2 + echo 'You need to run this from inside a sources git repo' >&2 + echo '' >&2 + echo ' -h: This help message' >&2 + echo ' -q: Suppress warnings' >&2 + echo '' >&2 + echo ' -b: specify a branch to examine' >&2 + echo " defaults to repo's current branch" >&2 + echo " NOTE: your repo will be set to this branch">&2 + echo '' >&2 + echo ' -c: specify a commit id' >&2 + echo " defaults to repo's current commit id" >&2 + echo " NOTE: your repo will be set to this commit">&2 + echo '' >&2 + echo " $0" >&2 + echo " $0 -b c7" >&2 + echo " $0 -b remotes/origin/c7" >&2 + echo " $0 -c 865ae5909b2b5d5fb37971b7ad7960f1fd5a5ffa" >&2 + echo " $0 -b c7 -c 865ae5909b2b5d5fb37971b7ad7960f1fd5a5ffa" >&2 + exit 1 +} + +##################################################################### + +QUIET=0 +COMMITHASH="" +BRANCH="" + +##################################################################### +# setup args in the right order for making getopt evaluation +# nice and easy. You'll need to read the manpages for more info +# utilizing 'while' construct rather than 'for arg' to avoid unnecessary +# shifting of program args +args=$(getopt -o hqb:c: -- "$@") +eval set -- "$args" + +while [[ 0 -eq 0 ]]; do + case $1 in + -- ) + # end of getopt args, shift off the -- and get out of the loop + shift + break + ;; + -q ) + # suppress warnings + QUIET=1 + shift + ;; + -c ) + # Use this commit id + COMMITHASH=$2 + shift + shift + ;; + -b ) + # Check this particular branch + BRANCH=$2 + shift + shift + ;; + -h ) + # get help + usage + ;; + esac +done + +if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then + echo 'You need to run this from inside a sources git repo' >&2 + exit 1 +fi + +which git >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need git in PATH' >&2 + exit 1 +fi + +which get_sources.sh >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need get_sources.sh from centos-git-common in PATH' >&2 + exit 1 +fi + +which return_disttag.sh >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need return_disttag.sh from centos-git-common in PATH' >&2 + exit 1 +fi + +which get_sources.sh >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need get_sources.sh from centos-git-common in PATH' >&2 + exit 1 +fi + +if [[ "x${BRANCH}" != 'x' ]]; then + if [[ $QUIET -eq 1 ]]; then + git fetch >/dev/null + git checkout ${BRANCH} >/dev/null + else + git fetch + git checkout ${BRANCH} + fi +fi + +if [[ "x${COMMITHASH}" != 'x' ]]; then + if [[ $QUIET -eq 1 ]]; then + git fetch >/dev/null + git checkout ${COMMITHASH} >/dev/null + else + git fetch + git checkout ${COMMITHASH} + fi +fi + +if [[ $QUIET -eq 1 ]]; then + get_sources.sh +else + get_sources.sh -q +fi + +if [[ $QUIET -eq 1 ]]; then + rpmbuild --define "%_topdir `pwd`" --define "%dist `return_disttag.sh -q`" -bs --nodeps SPECS/*.spec + RC=$? +else + rpmbuild --define "%_topdir `pwd`" --define "%dist `return_disttag.sh`" -bs --nodeps SPECS/*.spec + RC=$? +fi + +if [[ ${RC} -ne 0 ]]; then + if [[ $QUIET -eq 1 ]]; then + echo "$0 failed to recreate srpm" >&2 + fi + exit 1 +fi