#!/bin/bash #set -x # # mk # # mk automates the use of iurt for the test building of packages against a private local http mirror, # which is also accessible over ssh (using private keys) from the build machine. # Built packages are added to a local media repository and are immediately available (with '-e' option) # to build further packages requiring them as dependencies. This is acheived by linking the new 'extra' # repository into the local mirror, such that it is seen as part of that mirror. # The 'cronsync' script [1] is used to sync the mirror and incorporates the ability to re-add the 'extra' # media as each sync session completes. # # Usage: # $ mk [options] # options: # -m Build using mock rather than iurt. (iurt is default) # -x Build for x86_64 (default) # -c Build for Cauldron (default) # -i Build for i586 # -e Build using 'extra' media # -f Skip rpmlint - just build it # -t Built for tainted # -n Build for nonfree # Examples: # $ cd # $ mk // Builds package for Cauldron x86_64 using default media # # $ mk -i -8 -e -n // Builds package for Mageia 8 i586 using default and extra media # # # Notes: The extra/release media is created from any packages built by this script and merged into # the local mirror (on my 'zmhost' server) by 'cronsync' [1] when it syncs the mirror, or when called with -e. # # [1] http://mtf.no-ip.co.uk/pub/linux/barjac/soft/cronsync # # This was only written for my own use and is made available AS IS with no warranty of any kind. # If you find it useful please let me know - if you can improve it - great - tell me how! :) ########################## # Check we are not root (((UID))) || { echo "You must NOT be root to run $0"; exit 1; } ########################## # Config builduser=baz mirror="http://zmhost/pub/linux/Mageia/distrib" #mirror="http://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib" #mirror="http://www.mirrorservice.org/sites/mageia.org/pub/mageia/distrib" #mirror="http://192.168.1.64/pub/linux/Mageia/distrib" verbose="-v 10" #pdb="perl -d:ptkdb" #pub/linux/Mageia/distrib/cauldron/x86_64/media/nonfree/release/ #http://192.168.1.64/pub/linux/Mageia/distrib/cauldron/x86_64/media/nonfree/release/ extra= stop= extra_media= debug= dos= buildsys="iurt" arch="x86_64" release="cauldron" usage() { echo "$0 usage:" && grep "[[:space:]].) #" $0 | sed 's/#//' ; exit 0; } #usage() { echo "$0 usage:" && grep " .)\ #" $0; exit 0; } while getopts "mfetniaxrhs6789" arg; do case $arg in m) # Use Mock. buildsys=mock ;; f) # Skip using rpmlint on src.rpm before build. skiprpmlint=1 ;; e) # Also use 'extra' media as packages source. extra=1 ;; t) # Also use 'tainted' media as packages source (mock only). extra_media="$extra_media --media tainted/release" t="-tainted" ;; n) # Also use 'nonfree' media as packages source (mock only). extra_media="--media nonfree/release" n="-nonfree" ;; i) # Build for i586 arch. arch="i586"; linux="linux32" ;; x) # Build for x86_64 arch. arch="x86_64" ;; a) # Build for aarch64 arch (mock only). arch="aarch64" ;; r) # Build for armv7hl arch (mock only). arch="armv7hl" ;; s) # Drop to shell in iurt shell="--shell" ;; 7) # Build for Mageia 7. release="7"; distrel="$arg_bcj" ;; 8) # Build for Mageia 8. release=$arg; distrel="$arg_bcj" ;; 9) # Build for Mageia 9. release="cauldron" ; distrel="9_bcj" ;; #shell) # Drop to shell in iurt using one of "p c i l b a s" # for stop_arg in p c i l b a s; do # [[ $@ =~ "--stop $stop_arg" ]] && stop="--stop $stop_arg" # done # shell=1 # ;; h) # Display help. usage exit 0 ;; *) # No parameter. exit 0 ;; esac done cat < /dev/null 2>&1 [[ $@ =~ "-m" ]] && buildsys=mock [[ $@ =~ "-f" ]] && skiprpmlint=1 [[ $@ =~ "-e" ]] && extra=1 [[ $@ =~ "-d" ]] && debug="--debug" [[ $@ =~ "-dos" ]] && dos="--delete-on-success" [[ $@ =~ "-x" ]] && arch="x86_64" [[ $@ =~ "-i" ]] && { arch="i586"; linux="linux32"; } [[ $@ =~ "-6" ]] && { release="6"; distrel="6_bcj"; } [[ $@ =~ "-7" ]] && { release="7"; distrel="7_bcj"; } [[ $@ =~ "-8" ]] && { release="8"; distrel="8_bcj"; } [[ $@ =~ "-9" ]] && { release="cauldron"; distrel="9_bcj"; } [[ $@ =~ "--shell" ]] && shell=1 [[ ${#release} = 0 ]] && { release="cauldron"; distrel="9_bcj"; } [[ ${#arch} = 0 ]] && arch="x86_64" for stop_arg in p c i l b a s; do [[ $@ =~ "--stop $stop_arg" ]] && stop="--stop $stop_arg" done [[ $@ =~ "-n" ]] && { extra_media="--media nonfree/release"; n="-nonfree"; } [[ $@ =~ "-t" ]] && { extra_media="$extra_media --media tainted/release"; t="-tainted"; } EOF # Set up extra media on mirror as needed ( if '-e' passed ) if [[ $extra = 1 ]]; then xstring="with extra media" if ! ssh -l baz zmhost [[ -e .cronsync_extra ]] ; then ssh -l baz zmhost touch .cronsync_extra ssh -l baz zmhost ./cronsync e extramedia="/pub/linux/Mageia/distrib/$release/$arch/extra/release" fi else xstring= if ssh -l baz zmhost [[ -e .cronsync_extra ]] ; then ssh -l baz zmhost rm -f .cronsync_extra fi ssh -l baz zmhost ./cronsync n fi # Valid stop arguments (rpmbuild stages) are 'p c i l b a s' (see iurt --help) # --stop a # Pass --shell to drop to shell in chroot # Check we have SPECS above us [[ -d "SPECS" ]] || { echo "Not in an rpm build tree root"; exit 1; } # Remember where we are currdir=$(pwd) pkgname=$(echo $currdir | rev | cut -d/ -f1 |rev) #[[ ${#shell} > 0 ]] && shell="--shell" echo "########################################################" echo "Building $pkgname for Mageia $release$t $arch $xstring"using $buildsys echo "########################################################" # make new srpm bm --short-circuit -s [[ $? = 0 ]] || { echo "SRPM build failed !"; exit 1; } # get name of newest file in SRPMS dir files=(SRPMS/*) newest=${files[0]} for f in "${files[@]}"; do if [[ $f -nt $newest ]]; then newest=$f fi done # Save it (handy to use to tailf the build output) echo $newest > ~/newest #echo $newest #pkgname=$(echo $newest|cut -d/ -f2|cut -d- -f1) pkgver=$(echo $newest|cut -d/ -f2|cut -d- -f2) #echo $pkgname #echo $pkgver #exit 0 if [[ $skiprpmlint != 1 ]]; then # Run rpmlint rpmlint $newest echo -e "\nAny key to continue - CTRL/c to exit" read fi # Mount remote mirror dir on uploads folder using sshfs (key access) if ! mount | grep -q "baz@zmhost:/zm-repo/pub/linux/barjac/distrib/ on /home/baz/iurt_uploads/iurt"; then sshfs -o allow_other -o default_permissions baz@zmhost:/zm-repo/pub/linux/barjac/distrib/ $HOME/iurt_uploads/iurt/ [[ $? = 0 ]] || { echo "Failed to mount remote file system"; exit 1; } fi mkdir -p $HOME/iurt_uploads/iurt/$release/$arch # Test for network conection for interface in $(ls /sys/class/net/ | grep -v lo); do if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then OnLine=1; fi done if ! [ $OnLine ]; then echo "Not Online" > /dev/stderr; exit; fi # Run build ############################ if [[ "$buildsys" == "mock" ]] ; then # Run mock build ############## echo "mock --root mageia-$release-$arch$n$t --rebuild $currdir/$newest --resultdir $HOME/iurt_uploads/iurt/$release/$arch" export LC_ALL=C mock --root mageia-$release-$arch$n$t --rebuild $currdir/$newest --resultdir $HOME/iurt_uploads/iurt/$release/$arch echo "############ mock done $? #################" # Move log to usual (iurt) location mkdir -p /home/baz/iurt_uploads/iurt/$release/$arch/log/$pkgname-$pkgver/ mv $HOME/iurt_uploads/iurt/$release/$arch/build.log \ /home/baz/iurt_uploads/iurt/$release/$arch/log/$pkgname-$pkgver/build.log echo "############ log move done $? #################" else # Run iurt build ######################## echo "LC_ALL=C $linux $pdb /usr/bin/iurt $debug $dos --rpmmacros '%dist .mga$distrel' $verbose $stop $shell --chrooted-urpmi $mirror --build-user $builduser $extra_media -r $release $arch $newest" LC_ALL=C $linux $pdb /usr/bin/iurt $debug $dos --rpmmacros "%dist .mga$distrel" $verbose $stop $shell --chrooted-urpmi $mirror --build-user $builduser --clean baz $extra_media -r $release $arch $newest || \ { echo "build failed"; exit 1; } fi cd $HOME/iurt_uploads/iurt/$release/$arch echo "Copying rpms to server..." mkdir -p media/extra/release mv *.rpm media/extra/release/ > /dev/null 2>&1 if [[ $? = 0 ]]; then echo "Running genhdlist2 and createrepo_c" cd media genhdlist2 extra/release --xml-info --allow-empty-media --no-bad-rpm createrepo_c --update extra/release echo "Success! \o/" retval=0 else echo "Failed :(" retval=1 fi cd $currdir # Restore extra media if disabled if ! ssh -l baz zmhost [[ -e .cronsync_extra ]] ; then ssh -l baz zmhost touch .cronsync_extra ssh -l baz zmhost ./cronsync e fi exit $retval