#!/bin/sh set -e # FIXME: Woraround for a bug in dh_auto_clean export MAKELEVEL= # For the 'local' repository: BASE_URL=http://boole/svn/debs/components # we keep a place (on shared NFS) where all the tarballs are saved. # may be a useful optimization BUILD_AREA=build-area SVN_TOP="svn://anonscm.debian.org/svn/pkg-voip" #SVN_TOP="svn+ssh://alioth/svn/pkg-voip" # Variables set in the Makefile: # PBUILDER_PARAMS # ARCH # DISTRO # LOCAL_REPO # LOCAL_DISTRO # TARBALLS_DIR # SOURCES_SPEC SOURCES_FILE=${SOURCES_SPEC:-sources} REPREPRO="reprepro -b $LOCAL_REPO" LOGS_DIR="$LOCAL_REPO/logs" say() { echo >&2 "$0: $@" } mkdir -p $BUILD_AREA packages_filter='('`echo $* | tr ' ' '|'`')' get_new_version() { new_rev="$1" dpkg-parsechangelog | awk '/^Version:/{print $2}' | perl -p -e \ "s/[0-9]*\$/(\$&-1).'.'.$new_rev/e" } parse_opts() { opt_rev='' opt_hook_args='' opt_not_for='' opt_only_for='' rev_arg='' for arg in "$@"; do case "$arg" in rev=*) opt_rev=`echo $arg | cut -d= -f2-`;; hook_args=*) opt_hook_args=`echo $arg | cut -d= -f2-`;; not_for=*) opt_not_for=`echo $arg | cut -d= -f2-`;; only_for=*) opt_only_for=`echo $arg | cut -d= -f2-`;; esac done if [ "$opt_rev" != '' ]; then rev_arg="-r $opt_rev" fi rev="$opt_rev" } is_distro_disabled() { dists_not_for="$1" dists_only_for="$2" if [ "$dists_only_for" != '' ] && echo $dists_only_for | grep -vwq "$DISTRO" then say "Skipping $package: disabled for $DISTRO: only_for." return 0 fi if echo $dists_not_for | grep -wq "$DISTRO" then say "Not building $package (Disabled for $DISTRO: not_for)" return 0 fi return 1 } egrep $packages_filter "$SOURCES_SPEC" | while read package repo branch opts do if [ "$package" = 'quit' ]; then say "echo Stopping build due to 'quit'" exit 0 fi case "$package" in '#'*|'') continue;; esac # ignore blanks and comments # In case a package does not reside in the top level under components/ . # Currently this is used for freepbx-modules-* package_full="$package" package=`echo $package_full| sed -e 's|.*/||'` say "Checking $package" parse_opts $opts if is_distro_disabled "$opt_not_for" "$opt_only_for"; then continue fi dummy_mod_package=no case "$package" in *zaptel-modules|*dahdi-modules) dummy_mod_package=yes ;; esac # don't build a package that is already in the repository # when to build: # * if no version was specificed: check if we have the latest in the # specified branch # * If revision was given: check that we have exactly that revision. package_repo_ver=`$REPREPRO -T dsc list $LOCAL_DISTRO $package 2>/dev/null | awk '/\|source:/{print $3}'` expected_package_version=`echo $package_repo_ver | sed -e 's/^.*\.\([^.]*$\)/\1/'` if [ "$rev" != "" ] && [ "$rev" = "$expected_package_version" ]; then continue fi # Don't check the version of zaptel-modules. Zaptel's addition invalidates # old versions (see below). if [ "$dummy_mod_package" = 'yes' ] && $REPREPRO listfilter $LOCAL_DISTRO Package | grep -q $package then continue; fi case "$repo" in local) repo_base=$BASE_URL;; debian-pkg-voip) repo_base=$SVN_TOP;; *) say "Error: unknown repository $repo (package $package). Aborting" exit 1 ;; esac url_with_rev="$rev_arg $repo_base/$package_full/$branch" #ver=`svn cat $url_with_rev/debian/changelog | head -n 1 | cut -d '(' -f 2' | cut -d - -f 1| cut -d ')' -f 1` # IIRC the dir nameneeds tobe of the format '$packge-$version' . I don't # want to start a complicated parsing to get the version number. Let's just get # it from the dir name. svn_checkout_base=$BUILD_AREA/$package-svn svn_checkout_dir=$svn_checkout_base/svn # Give us a clean start. There will be only one .changes file when we # finish building rm -rf $svn_checkout_base mkdir -p $svn_checkout_base # Set the stage for svn-buildpackage: ln -s . $svn_checkout_base/build-area ln -s $TARBALLS_DIR $svn_checkout_base/tarballs svn co -q $url_with_rev $svn_checkout_dir # if we did not ask for a specific revision, get the revision number of current if [ "$rev" = '' ]; then rev=`svn info $svn_checkout_dir | awk -F: '/^Last Changed Rev: /{print $2}' | cut -d' ' -f2` if [ "$rev" = "$expected_package_version" ]; then say "Skipping $package: revision exists in repository." continue fi fi if [ -x tools/hooks/$package/setup ]; then tools/hooks/$package/setup $svn_checkout_dir $opt_hook_args fi # Build: origdir=$PWD cd $svn_checkout_dir case "$branch" in tags/*) tag_ver=`echo $branch | sed -e 's|.*tags/||'` if [ "$tag_ver" = `echo $package_repo_ver | sed -e 's/.*://'`'' ]; then say "Skipping $package: tag exists in repository." cd $origdir continue fi ;; *) dch --append "Revision: $rev, Branch: $branch" new_version=`get_new_version $rev` sed -i -e "1s/(\([^)]*\))/($new_version)/" debian/changelog ;; esac full_version=`dpkg-parsechangelog| awk '/^Version:/{print $2}' | sed -e 's/.*://'` version=`echo $full_version | sed -e 's/-[^-]*$//'` # A backporting script: for hook_name in $DISTRO $DISTRO.xorcom; do hook=debian/backports/$hook_name if [ -x $hook ]; then $hook fi done tarball_base=${package}_$version.orig.tar.gz tarball=../tarballs/${tarball_base} if [ ! -r "$tarball" ] && echo $full_version | sed -e 's/.*_//' | grep -q -- - ; then debian/rules get-orig-source if [ -r ${tarball_base} ] && [ ! -r ${tarball} ]; then mv ${tarball_base} ${tarball} fi fi # svn-buildpackage prompts the user in case of a failure. let's provide # it with the answer: if [ "$USE_PBUILDER" != '' ] then echo "$PBUILDER_PARAMS" >../pbuilder_params echo q | svn-buildpackage --svn-dont-clean --svn-dont-purge --svn-ignore-new \ --svn-builder="pdebuild $PBUILDER_PARAMS --buildresult $origdir/$svn_checkout_base -- --pkgname-logfile" else echo q | svn-buildpackage -rfakeroot -sa -uc -us --svn-dont-clean --svn-dont-purge --svn-ignore-new fi cd $origdir # Commit: changes_file=$svn_checkout_base/${package}_${full_version}_$ARCH.changes build_log_file=$svn_checkout_base/${package}_${full_version}_$ARCH.build # finished building. commit package to repository if [ "$dummy_mod_package" = 'yes' ]; then # commit the embedded packages rather than the dummy package dummy_deb=$svn_checkout_base/$package-dummy_${full_version}_all.deb debs_base=$svn_checkout_base/debs rm -rf $debs_base dpkg -x $dummy_deb $debs_base # FIXME: unsigned: for deb in $debs_base/usr/lib/dummy-debs/*.deb; do $REPREPRO --ignore=wrongdistribution includedeb $LOCAL_DISTRO $deb done fi $REPREPRO --ignore=wrongdistribution include $LOCAL_DISTRO $changes_file cp -a $build_log_file $LOGS_DIR/ # Commiting a new version of zaptel invalidates zaptel-modules case "$package" in zaptel) mods_package='zaptel-modules';; dahdi-linux) mods_package='dahdi-modules';; *)mods_package='';; esac if [ "$mods_package" != '' ]; then packs_to_remove=`$REPREPRO listfilter $LOCAL_DISTRO 'Package' | awk "/$mods_package/"'{print $2}'` if [ "$packs_to_remove" != '' ]; then $REPREPRO remove $LOCAL_DISTRO $packs_to_remove fi fi # TODO: update the buildroot after every package built?? if [ "$USE_PBUILDER" != '' ]; then make update_buildimg fi done