#!/bin/sh DESTDIR=/tmp/$0.$UID.build CLEAN=0 DIST=fedora-18-local-x86_64 SYSTEM=Fedora PACKAGE_PATH_BASE=$HOME/.specs VERBOSE=0 MAKEREPO= NOTIFY=0 ARGS="$0 $@" BRANCH= MOCKDIR=/var/lib/mock MOCKCONF=/etc/mock PACKAGES= function die { echo $@ >&2 exit 1 } function get_mock_path { FILE="$MOCKCONF/$1.cfg" NAME=$(sed -n "s,^config_opts\['root'\]\s*=\s*'\(.*\)'.*$,\1,p" $FILE) echo $MOCKDIR/$NAME } function alert { notify-send --urgency=low -- "$1" "$2" } function make_repo { REPODIR=$1 SCANPATH=$2 if [ ! -d $REPODIR ] then mkdir -p $REPODIR fi if [ ! -w $REPODIR ] then echo "You don't have access to $REPODIR" >&2 return 1 fi find $SCANPATH \( -name '*.rpm' -a ! -path '*/.repo/*' \) -exec cp {} $REPODIR \; createrepo -o $REPODIR $REPODIR ls -lahR $REPODIR > $REPODIR/files.txt } while [ $# -gt 0 ] do OPTION=$1 shift case $OPTION in --base-path) PACKAGE_PATH_BASE=$1 shift ;; -b|--build) DESTDIR=$1 shift ;; -c|--clean) CLEAN=1 ;; -d|--dist) DIST=$1 shift ;; --list-pkgs) for path in $(find $PACKAGE_PATH_BASE -maxdepth 2 -name '*.spec') do echo $(basename $(dirname $path)) done exit 0 ;; --list-dists) for profile in $(find $MOCKCONF -name '*.cfg' -printf '%f\n') do echo ${profile:0: -4} done exit 0 ;; -v|--verbose) VERBOSE=1 ;; -m|--make-repo) MAKEREPO=$1 shift ;; -N|--notify) NOTIFY=1 ;; --branch) BRANCH=$1 shift ;; -h|--help) echo "Build SPEC file from a package in $PACKAGE_PATH_BASE usage: $0 [ options ] < package name > options: --base-path Specify base path for spec searches (default: $PACKAGE_PATH_BASE) -b --build Specify output for source/built RPMs (default: $DESTDIR) --branch Change branch before building -c --clean Clean build directory before building -d --dist Specify distribution (mock profile name) (default: $DIST) --list-pkgs List packages that can be built --list-dists List available distributions -v --verbose Enable verbose run -m --make-repo Add build results to given repository -N --notify Send DBus notification when done -h --help Show this help file" exit 1 ;; --) PACKAGES="$PACKAGES $@" break ;; -*) echo "Unkown option $OPTION" >&2 exit 1 ;; *) PACKAGES="$PACKAGES $OPTION" ;; esac done [ "x$PACKAGES" = "x" ] && die Missing package name [ $VERBOSE -ne 0 ] && set -x if [ $CLEAN -eq 1 ] then rm -rf $DESTDIR/* fi if [ -e $DESTDIR ] then if [ ! -d $DESTDIR ] then die "$DESTDIR not a directory" fi if [ ! -w $DESTDIR ] then die "You don't have access to $DESTDIR" fi fi mkdir -p $DESTDIR/srpm mkdir -p $DESTDIR/rpm BASE_DIR=$(pwd) cd $DESTDIR DESTDIR=$(pwd) cd $BASE_DIR for PACKAGE in $PACKAGES do PACKAGE_PATH=$PACKAGE_PATH_BASE/$PACKAGE if [ ! -d $PACKAGE_PATH ] then echo "$PACKAGE_PATH not found" continue fi SPECFILE=$(find $PACKAGE_PATH/ -name '*.spec' | head -1) if [ "x$SPECFILE" = "x" ] then echo "$PACKAGE_PATH contains no spec file" continue fi if [ "x$BRANCH" != "x" ] then cd $PACKAGE_PATH git checkout $BRANCH CODE=$? cd - if [ $CODE -ne 0 ] then echo "$PACKAGE_PATH has no branch $BRANCH; skipping" >&2 continue fi fi mock --buildsrpm --spec $SPECFILE --sources $PACKAGE_PATH -r $DIST if [ $? -ne 0 ] then echo "Mock failed to create srpm from $SPECFILE" continue fi DISTPATH=$(get_mock_path $DIST)/result SRPM=$(find $DISTPATH -name '*.src.rpm' -printf '%f\n' | head -1) cp $DISTPATH/$SRPM $DESTDIR/srpm mock -r $DIST --rebuild $DESTDIR/srpm/$SRPM if [ $? -ne 0 ] then echo "Mock failed to build $SRPM" continue fi find $DISTPATH \( -name '*.rpm' -a ! -name '*.src.rpm' \) -exec cp {} $DESTDIR/rpm \; cd $BASE_DIR done if [ "x$MAKEREPO" != "x" ] then make_repo $MAKEREPO $DISTPATH fi if [ $NOTIFY -ne 0 ] then alert "Build complete" "$ARGS" fi