>
>
>I am interested in that script, please.
>
OK. Here it goes.
1/ I've setup a user account named "cooker".
2/ Then I've given this useraccount permissions to run urpmi and urpme 
via sudo (edit with visudo):
   cooker ALL = NOPASSWD: /usr/sbin/urpme
   cooker ALL = NOPASSWD: /usr/sbin/urpmi

3/ Download the SRPMS directory. (I like using rsync) (I put it in 
/mirrors/SRPMS):
4/ Make the following directory structure to store the urpmi and 
buildoutputs, the cooker user must have write permisions here (I put it 
in /misc/linux/mandrake/buildoutputs on my box):

./cooker/i586/arch_excl
./cooker/i586/broken
./cooker/i586/OK
./cooker/i586/problem
./cooker/i586/requires_its_self
./cooker/i586/root_only
./cooker/i586/uploaded
./cooker/urpmi/i586

5/ make a crontab for cooker:
0,15,30,45 * * * * if [ `ps -u $UID | grep build.sh | wc -l` = 0 ]; then 
/misc/linux/mandrake/bin/build.sh /misc/linux/mandrake/buildout 
/mirrors/SRPMS /misc/linux/mandrake cooker >/dev/null 2>&1 ; fi

This crontab checks if build.sh is running, if not, it starts build.sh, 
with parameters to the paths. build.sh is attached to this email. The 
script is not perfect by far, don't sue me if it wrecks your system...

Goodluck!!!

Stefan
#!/bin/sh

export PATH=$PATH:/usr/X11R6/bin:/usr/sbin:/sbin

buildoutput=${1}        # /misc/linux/mandrake/buildout
sources=${2}            # /mirrors/SRPMS
rpm_output=${3}         # /misc/linux/mandrake
build_type=${4}         # contrib / cooker / crypto

cleanup () {
        chmod 777 ~/RPM/BUILD/* -R 
        rm -rf ~/RPM/BUILD/* ~/RPM/SOURCES/* ~/RPM/SPECS/* ~/tmp/* /var/tmp/*
        find ~/RPM/ -type f -exec rm -rf {} \;
        }

count_new () {
        ls -R ${buildoutput}/${build_type}/${HOSTTYPE} | sort | sed s/.txt// | grep 
src.rpm > /tmp/${build_type}_LOG.txt
        ls -R ${sources} | sort | grep src.rpm > /tmp/${build_type}_SRPMS.txt

        diff /tmp/${build_type}_LOG.txt /tmp/${build_type}_SRPMS.txt | grep src.rpm \
                | cut -b 3-100 | sort | uniq | wc -l
        
        rm -rf /tmp/${build_type}_LOG.txt /tmp/${build_type}_SRPMS.txt
        }

count_old () {
        cd ${buildoutput}/${build_type}/${HOSTTYPE}
        find -type f -maxdepth 1 -mtime +1 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/broken
        find -type f \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/OK
        find -type f -mtime +7 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/problem
        find -type f -mtime +7 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt
        
        cat /tmp/${build_type}_BUILD.txt | wc -l
        rm -rf /tmp/${build_type}_BUILD.txt
        }

find_new () {
        ls -R ${buildoutput}/${build_type}/${HOSTTYPE} | sort | sed s/.txt// | grep 
src.rpm > /tmp/${build_type}_LOG.txt
        ls -R ${sources} | sort | grep src.rpm > /tmp/${build_type}_SRPMS.txt

        diff /tmp/${build_type}_LOG.txt /tmp/${build_type}_SRPMS.txt | grep src.rpm \
                | cut -b 3-100 | sort | uniq | head -n 1
        
        rm -rf /tmp/${build_type}_LOG.txt /tmp/${build_type}_SRPMS.txt
        }

find_old () {
        cd ${buildoutput}/${build_type}/${HOSTTYPE}
        find -type f -maxdepth 1 -mtime +1 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/broken
        find -type f \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/OK
        find -type f -mtime +7 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt

        cd ${buildoutput}/${build_type}/${HOSTTYPE}/problem
        find -type f -mtime +7 \
                | cut -b 3- |sed s/.txt// >> /tmp/${build_type}_BUILD.txt
        
        sort /tmp/${build_type}_BUILD.txt | uniq | head -n 1

        rm -rf /tmp/${build_type}_BUILD.txt
        }

build () {
        echo "Finding BuildRequires for:" ${1};

        find ${buildoutput}/${build_type}/${HOSTTYPE} -name ${1}.txt -exec rm -rf {} \;
        find ${buildoutput}/${build_type}/urpmi/${HOSTTYPE}/ -name ${1}.txt -exec rm 
-rf {} \;

# Test if ${sources}/${1} exists, if the file doesn't exist, no need to rebuild.
        if [ -e ${sources}/${1} ];
                then

# Find obselete BuildRequires in  src.rpm file.
 
# Figure out which packages need to be installed in order to make this package build.
# Install those packages, and write the urpmi log (required for uninstalling later).
# Find BuildRequires: for src.rpm

                for a in `rpm -qpR ${sources}/${1} | cut -d " " -f1 | sort | grep -v 
rpmlib`
                        do
                        for b in `urpmq -p ${a} 2>&1 | cut -d ":" -f2`
                                do
                                urpmq -d -p ${b} | grep -v ${b}
                                urpmq -m -p ${b} | grep -v ${b}
                        done
                done | sort | uniq > ~/tmp/B.txt

# Find the obselete BuildRequires: 
        echo "Installing BuildRequires for:" ${1};

                for a in `rpm -qpR ${sources}/${1} | cut -d " " -f1 | sort | grep -v 
rpmlib`
                do
                        for b in `urpmq -p ${a} 2>&1 | cut -d ":" -f2`
                        do
                                if [ `grep ${b} ~/tmp/B.txt | wc -l` = 0 ]
                                then
                                        echo "### Installing: " ${a} ", " ${b}
                                        sudo /usr/sbin/urpmi --auto -p ${b}
                                else
                                        for c in `grep ${b} ~/tmp/B.txt`
                                        do
                                                if [ ${b} = ${c} ]
                                                then
                                                        echo "### Remove following 
obselete BuildRequires:" ${a} ", " ${b}
                                                else
                                                        echo "### Installing: " ${a} 
", " ${b}
                                                        sudo /usr/sbin/urpmi --auto -p 
${b}
                                                fi
                                        done
                                fi
                        done
                done >> ${buildoutput}/${build_type}/urpmi/${HOSTTYPE}/${1}.txt 2>&1
 
# Cleanup temp file
rm -rf ~/tmp/A.txt
rm -rf ~/tmp/B.txt

                echo "Building:" ${1};

# Rebuild the src.rpm, write output to file.
                rpm --rebuild ${sources}/${1} &> 
${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt;

# Analyze the buildoutput, and move it to the right directory.

# Buildoutput end with "+ exit 0", build is successful.
                if [ "$(tail --lines 1 
${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt)" = "+ exit 0" ];
                then
# Find the "Wrote:" statements in the buildoutput and remove previous packages.
                        for n in `fgrep Wrote: 
${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt | cut -b 8- `
                                do
                                rm -rf ${rpm_output}/${build_type}/`rpm -qp 
--queryformat %{NAME} \
                                ${n}`-[0-9]*{$HOSTTYPE,noarch}.rpm
                        done
                        mv ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt 
${buildoutput}/${build_type}/${HOSTTYPE}/OK/

# If file doesn't exist (error: cannot open) then remove the buildoutput.
                elif [ "$(tail -n1 ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt \
                        | cut -b 0-18)" = "error: cannot open" ];
                then
                        rm -rf ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt

# Architecture excluded.
                elif [ "$(tail -n2 ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt | 
head -n1 \
                        | cut -b 8-19)" = "Architecture" ];
                then
                        mv ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt 
${buildoutput}/${build_type}/${HOSTTYPE}/arch_excl/

# Source package expected, binary found.
                elif [ "$(tail -n2 ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt | 
head -n1 \
                        | cut -b 0-37)" = "source package expected, binary found" ];
                then
                        mv ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt 
${buildoutput}/${build_type}/${HOSTTYPE}/broken/

# Bad exit status == problem.
                elif [ "$(tail -n1 ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt |
cut -b 5-19)" = "Bad exit status" ];
                then
                        mv ${buildoutput}/${build_type}/${HOSTTYPE}/${1}.txt 
${buildoutput}/${build_type}/${HOSTTYPE}/problem/
                fi

# Move resulting binary packages.
#               mv -f ~/RPM/RPMS/alpha/*        ${rpm_output}/${build_type}
#               mv -f ~/RPM/RPMS/i586/*         ${rpm_output}/${build_type}
#               mv -f ~/RPM/RPMS/i686/*         ${rpm_output}/${build_type}
#               mv -f ~/RPM/RPMS/noarch/*       ${rpm_output}/${build_type}
#               mv -f ~/RPM/RPMS/ppc/*          ${rpm_output}/${build_type}
#               mv -f ~/RPM/RPMS/sparc/*        ${rpm_output}/${build_type}

                for r in `cat ${buildoutput}/${build_type}/urpmi/${HOSTTYPE}/${1}.txt 
| grep installing`
                        do
                        for i in `echo ${r} | grep -v installing | sort | cut -d "/" 
-f6 | sed s/.i586.rpm// | sed s/.noarch.rpm//`
                        do
                                echo "Removing" ${i}
                                sudo /usr/sbin/urpme --auto ${i}
                        done
                done >> ${buildoutput}/${build_type}/urpmi/${HOSTTYPE}/${1}.txt 2>&1

        else
                return
        fi
}

while [ `count_new` != 0 ] || [ `count_old` != 0 ] || [ `ls ${sources} | wc -l` = 0 ] 
; do
                while [ `count_new` != 0 ] ; do
                                build `find_new`
                                cleanup
                done
                if [ `count_old` != 0 ]
                then
                        build `find_old`
                fi
                cleanup
done
#!/bin/sh

export PATH=$PATH:/usr/X11R6/bin:/usr/sbin:/sbin

# echo "Finding BuildRequires for:" ${1};

# Find obselete BuildRequires in  src.rpm file.
 
# Figure out which packages need to be installed in order to make this package build.
# Install those packages, and write the urpmi log (required for uninstalling later).
# Find BuildRequires: for src.rpm

for a in `rpm -qpR ${1} | cut -d " " -f1 | sort | grep -v rpmlib`
        do
        for b in `urpmq -p ${a} 2>&1 | cut -d ":" -f2`
                do
                urpmq -d -p ${b} | grep -v ${b}
                urpmq -m -p ${b} | grep -v ${b}
        done
done | sort | uniq > ~/tmp/B.txt

# Find the obselete BuildRequires: 
# echo "Installing BuildRequires for:" ${1};

for a in `rpm -qpR ${1} | cut -d " " -f1 | sort | grep -v rpmlib`
do
        for b in `urpmq -p ${a} 2>&1 | cut -d ":" -f2`
        do
                if [ `grep ${b} ~/tmp/B.txt | wc -l` != 0 ]
#               if [ `grep ${b} ~/tmp/B.txt | wc -l` = 0 ]
#                       echo "### Installing: " ${a} ", " ${b}
#                       sudo /usr/sbin/urpmi --auto -p ${b}
#               else
                then
                        for c in `grep ${b} ~/tmp/B.txt`
                        do
                                if [ ${b} = ${c} ]
                                then
                                        echo "### Remove following obselete 
BuildRequires in" ${1} ":" ${a} "," ${b}
#                               else
#                                       echo "### Installing: " ${a} ", " ${b}
#                                       sudo /usr/sbin/urpmi --auto -p ${b}
                                fi
                        done
                fi
        done
done
# done >> ${buildoutput}/${build_type}/urpmi/${HOSTTYPE}/${1}.txt 2>&1
 
# Cleanup temp file
rm -rf ~/tmp/A.txt
rm -rf ~/tmp/B.txt

Reply via email to