#!/bin/sh DESTDIR=.build CLEAN=0 DIST=fedora-18-local-x86_64 PACKAGE_PATH_BASE=$HOME/devel/specs 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 } while [ $# -gt 0 ] do OPTION=$1 shift case $OPTION in -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 ;; -h|--help) echo "Create a local repository from the RPMs found in the scan-path. usage: $0 [ options ] < package name > options: -b --build Specify output for source/built RPMs (default: $DESTDIR) -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 -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 #set -x if [ $CLEAN -eq 1 ] then rm -rf $DESTDIR/* fi if [ ! -d $DESTDIR ] then mkdir -p $REPODIR elif [ ! -w $REPODIR ] then die "You don't have access to $REPODIR" 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 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