|
Pat Riehecky |
87c8ae |
#!/bin/bash -u
|
|
Pat Riehecky |
87c8ae |
#
|
|
Pat Riehecky |
87c8ae |
# Turn a centos git repo into a .src.rpm file
|
|
Pat Riehecky |
87c8ae |
#
|
|
Pat Riehecky |
87c8ae |
# Might want to drop this in ~/bin/ and chmod u+x it
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
#
|
|
Pat Riehecky |
87c8ae |
# License: GPLv2
|
|
Pat Riehecky |
87c8ae |
#
|
|
Pat Riehecky |
87c8ae |
# Initial Author: Pat Riehecky <riehecky at fnal.gov>
|
|
Pat Riehecky |
87c8ae |
#
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
#####################################################################
|
|
Pat Riehecky |
87c8ae |
usage() {
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo "$0 [-hq] [-b branch] [-c shasum]" >&2
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo 'You need to run this from inside a sources git repo' >&2
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo ' -h: This help message' >&2
|
|
Pat Riehecky |
87c8ae |
echo ' -q: Suppress warnings' >&2
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo ' -b: specify a branch to examine' >&2
|
|
Pat Riehecky |
87c8ae |
echo " defaults to repo's current branch" >&2
|
|
Pat Riehecky |
87c8ae |
echo " NOTE: your repo will be set to this branch">&2
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo ' -c: specify a commit id' >&2
|
|
Pat Riehecky |
87c8ae |
echo " defaults to repo's current commit id" >&2
|
|
Pat Riehecky |
87c8ae |
echo " NOTE: your repo will be set to this commit">&2
|
|
Pat Riehecky |
87c8ae |
echo '' >&2
|
|
Pat Riehecky |
87c8ae |
echo " $0" >&2
|
|
Pat Riehecky |
87c8ae |
echo " $0 -b c7" >&2
|
|
Pat Riehecky |
87c8ae |
echo " $0 -b remotes/origin/c7" >&2
|
|
Pat Riehecky |
87c8ae |
echo " $0 -c 865ae5909b2b5d5fb37971b7ad7960f1fd5a5ffa" >&2
|
|
Pat Riehecky |
87c8ae |
echo " $0 -b c7 -c 865ae5909b2b5d5fb37971b7ad7960f1fd5a5ffa" >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
}
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
#####################################################################
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
QUIET=0
|
|
Pat Riehecky |
87c8ae |
COMMITHASH=""
|
|
Pat Riehecky |
87c8ae |
BRANCH=""
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
#####################################################################
|
|
Pat Riehecky |
87c8ae |
# setup args in the right order for making getopt evaluation
|
|
Pat Riehecky |
87c8ae |
# nice and easy. You'll need to read the manpages for more info
|
|
Pat Riehecky |
87c8ae |
# utilizing 'while' construct rather than 'for arg' to avoid unnecessary
|
|
Pat Riehecky |
87c8ae |
# shifting of program args
|
|
Pat Riehecky |
87c8ae |
args=$(getopt -o hqb:c: -- "$@")
|
|
Pat Riehecky |
87c8ae |
eval set -- "$args"
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
while [[ 0 -eq 0 ]]; do
|
|
Pat Riehecky |
87c8ae |
case $1 in
|
|
Pat Riehecky |
87c8ae |
-- )
|
|
Pat Riehecky |
87c8ae |
# end of getopt args, shift off the -- and get out of the loop
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
break
|
|
Pat Riehecky |
87c8ae |
;;
|
|
Pat Riehecky |
87c8ae |
-q )
|
|
Pat Riehecky |
87c8ae |
# suppress warnings
|
|
Pat Riehecky |
87c8ae |
QUIET=1
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
;;
|
|
Pat Riehecky |
87c8ae |
-c )
|
|
Pat Riehecky |
87c8ae |
# Use this commit id
|
|
Pat Riehecky |
87c8ae |
COMMITHASH=$2
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
;;
|
|
Pat Riehecky |
87c8ae |
-b )
|
|
Pat Riehecky |
87c8ae |
# Check this particular branch
|
|
Pat Riehecky |
87c8ae |
BRANCH=$2
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
shift
|
|
Pat Riehecky |
87c8ae |
;;
|
|
Pat Riehecky |
87c8ae |
-h )
|
|
Pat Riehecky |
87c8ae |
# get help
|
|
Pat Riehecky |
87c8ae |
usage
|
|
Pat Riehecky |
87c8ae |
;;
|
|
Pat Riehecky |
87c8ae |
esac
|
|
Pat Riehecky |
87c8ae |
done
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then
|
|
Pat Riehecky |
87c8ae |
echo 'You need to run this from inside a sources git repo' >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
which git >/dev/null 2>&1
|
|
Pat Riehecky |
87c8ae |
if [[ $? -ne 0 ]]; then
|
|
Pat Riehecky |
87c8ae |
echo 'You need git in PATH' >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
which get_sources.sh >/dev/null 2>&1
|
|
Pat Riehecky |
87c8ae |
if [[ $? -ne 0 ]]; then
|
|
Pat Riehecky |
87c8ae |
echo 'You need get_sources.sh from centos-git-common in PATH' >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
which return_disttag.sh >/dev/null 2>&1
|
|
Pat Riehecky |
87c8ae |
if [[ $? -ne 0 ]]; then
|
|
Pat Riehecky |
87c8ae |
echo 'You need return_disttag.sh from centos-git-common in PATH' >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
which get_sources.sh >/dev/null 2>&1
|
|
Pat Riehecky |
87c8ae |
if [[ $? -ne 0 ]]; then
|
|
Pat Riehecky |
87c8ae |
echo 'You need get_sources.sh from centos-git-common in PATH' >&2
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ "x${BRANCH}" != 'x' ]]; then
|
|
Pat Riehecky |
87c8ae |
if [[ $QUIET -eq 1 ]]; then
|
|
Pat Riehecky |
87c8ae |
git fetch >/dev/null
|
|
Pat Riehecky |
87c8ae |
git checkout ${BRANCH} >/dev/null
|
|
Pat Riehecky |
87c8ae |
else
|
|
Pat Riehecky |
87c8ae |
git fetch
|
|
Pat Riehecky |
87c8ae |
git checkout ${BRANCH}
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ "x${COMMITHASH}" != 'x' ]]; then
|
|
Pat Riehecky |
87c8ae |
if [[ $QUIET -eq 1 ]]; then
|
|
Pat Riehecky |
87c8ae |
git fetch >/dev/null
|
|
Pat Riehecky |
87c8ae |
git checkout ${COMMITHASH} >/dev/null
|
|
Pat Riehecky |
87c8ae |
else
|
|
Pat Riehecky |
87c8ae |
git fetch
|
|
Pat Riehecky |
87c8ae |
git checkout ${COMMITHASH}
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ $QUIET -eq 1 ]]; then
|
|
Pat Riehecky |
87c8ae |
get_sources.sh
|
|
Pat Riehecky |
87c8ae |
else
|
|
Pat Riehecky |
87c8ae |
get_sources.sh -q
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ $QUIET -eq 1 ]]; then
|
|
Pat Riehecky |
87c8ae |
rpmbuild --define "%_topdir `pwd`" --define "%dist `return_disttag.sh -q`" -bs --nodeps SPECS/*.spec
|
|
Pat Riehecky |
87c8ae |
RC=$?
|
|
Pat Riehecky |
87c8ae |
else
|
|
Pat Riehecky |
87c8ae |
rpmbuild --define "%_topdir `pwd`" --define "%dist `return_disttag.sh`" -bs --nodeps SPECS/*.spec
|
|
Pat Riehecky |
87c8ae |
RC=$?
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
|
|
Pat Riehecky |
87c8ae |
if [[ ${RC} -ne 0 ]]; then
|
|
Pat Riehecky |
87c8ae |
if [[ $QUIET -eq 1 ]]; then
|
|
Pat Riehecky |
87c8ae |
echo "$0 failed to recreate srpm" >&2
|
|
Pat Riehecky |
87c8ae |
fi
|
|
Pat Riehecky |
87c8ae |
exit 1
|
|
Pat Riehecky |
87c8ae |
fi
|