#! /bin/bash ### # The Directory with SRPMS should have only SRPM files in it # # If the base config file used is named 'file.cfg' then its 'root' # parameter must be 'file' for the sake of simplicity. # # The user running this script must be part of the 'mock' group # and have root privileges. The best way to do this is to make the # user running this command a 'sudoer'. # # Sample Run : Suppose your SRPMS are all in '/path/to/SRPM/' and # your base cfg file is in /etc/mock/my-fedora-rawhide-i386.cfg. # The command you run would be : # './mockbuild -p /path/to/SRPM -c my-fedora-rawhide-i386 -n 3' # and there would be 3 concurrent builds to share the load. #### usage () { echo "USAGE : ./mockbuild -p /path/to/SRPMS -c config [ -n 5 ] [ -r /path/to/results/ ] [ --ignore-passes ]" exit 1 } sanity_check (){ ps aux | grep -v grep | grep -q "${baseFile}"-BUILD while [ "$?" != 1 ]; do sleep 30s ps aux | grep -v grep | grep -q "${baseFile}"-BUILD done } basedir='/etc/mock' #All .cfg files should reside here baseFile= #This is just the config file without the .cfg extention pathToSRPMSDir= #Where the srpm files are expected to be stored numOfBuilds=1 resultDir='.' #Where to output the passes and failures ignorePasses=1 if [ $# -ge 2 ]; then while [ $# -gt 0 ]; do case $1 in -p ) pathToSRPMSDir="$2"; shift 2 ;; -c ) baseFile="$2"; shift 2 ;; -n ) numOfBuilds="$2"; shift 2 ;; -r ) resultDir="$2"; shift 2 ;; --ignore-passes ) ignore_passes=0; shift ;; * ) usage ;; esac done else usage fi if [ -z "${baseFile}" ] || [ -z "${pathToSRPMSDir}" ]; then usage fi oldFile=${basedir}/${baseFile}.cfg # Create the mock build configurations # This sets the number of concurrent mock builds for (( i=0; i < ${numOfBuilds}; i++ )); do newFile=${basedir}/${baseFile}-BUILD-${i}.cfg sudo cp "${oldFile}" "${newFile}" sed -e "s/${baseFile}/${baseFile}-BUILD-${i}/" "${newFile}" | sudo tee "${newFile}" done #Create the results folders mkdir -p "${resultDir}"/{PASS,FAIL} foundSlot=0 for srpm in `ls ${pathToSRPMSDir}`; do #If any of the builds are empty #Queue up the current srpm there foundSlot=1 while [ ${foundSlot} != 0 ]; do for (( i=0; i < ${numOfBuilds}; i++ )); do ps aux | grep -v 'grep' | grep -q "${baseFile}-BUILD-${i}" if [ $? != 0 ]; then mock -r "${baseFile}"-BUILD-${i} "${pathToSRPMSDir}"/"${srpm}" && loc=PASS || loc=FAIL && [ "${ignore_passes}" = 0 ] && [ "${loc}" = 'PASS' ] || sudo cp -r /var/lib/mock/"${baseFile}"-BUILD-${i}/result "${resultDir}"/"${loc}"/"${srpm}" & foundSlot=0 break fi done sleep 30s done echo "${srpm}" >> 'srpms.done' done sanity_check