#!/bin/sh # Grabs the bottom 5 packages of needs-build and builds them in a pbuilder # chroot. set -e log() { printf "%s %s\n" "$(date +'[%Y/%m/%d %H.%M]')" "$@" >> $log_dir/buildd.log } check_restart() { if [ -f "$restart_file" ]; then log "restart file found; restarting..." rm -f "$restart_file" cd $buildd_home exec $0 $greed elif [ -f "$die_file" ]; then log "die file found; see you later" rm -f "$die_file" exit 0 fi } parse_dsc() { IFS=" " while read str str2; do case "$str" in Files:*) break ;; Architecture:*) if [ "$str2" != "$dpkg_arch" ] && [ "$str2" != "any" ]; then echo "not-for-us" return fi ;; esac if expr 'Files:' : "$str" >/dev/null; then break fi done if [ "$1" = dont-download ]; then return fi while read md5 size file; do if [ "$md5" = -----BEGIN ]; then break elif [ -z "$md5" ]; then continue fi if ! wget -q -O $file http://incoming.debian.org/$file; then case "$file" in *.orig.tar.gz) apt-get --tar-only source $package ;; esac fi done } find_dsc_url() { package=$1 version=$2 IFS=" " for line in $(apt-get --print-uris -qq source $1=$2); do url=$(echo "$line" | cut -d' ' -f1 | sed "s/'\(.*\)'/\1/") filename=$(echo "$line" | cut -d' ' -f2) case "$filename" in *.dsc) echo $url; return ;; esac done } get_and_build() { source=$1 package=${source%%_*} version=${source##*_} noe_version="$(echo $version | sed 's/^[0-9]\+://')" dsc="${package}_${noe_version}.dsc" cd $source_dir # see if it's already been built if [ -f "$completed_dir/${package}_${noe_version}_${dpkg_arch}.changes" ]; then log "$dsc is already built (available locally), skipping" return elif apt-get -qq --print-uris install $package=$version 2>/dev/null; then log "$dsc is already built (in archive), skipping" return fi if grep -q "^$source\$" $fail_log; then log "skipping previously failed $source" return fi log "looking for $dsc in incoming" if ! wget -q -O $dsc http://incoming.debian.org/$dsc; then log "not found, looking for $source in archive" url="$(find_dsc_url $package $version)" if [ -n "$url" ] && wget -q -O $dsc $url; then verdict="$(parse_dsc dont-download < $dsc)" if [ -n "$verdict" ]; then log "$dsc is $verdict, skipping for now" return fi if ! apt-get -qq source $package=$version >/dev/null; then log "complete source not found, skipping" return fi else log "dsc not found, skipping" fi else # must parse the dsc for what packages to download verdict="$(parse_dsc < $dsc)" if [ -n "$verdict" ]; then log "$dsc is $verdict, skipping for now" return fi fi log "now building $package ($version) with pbuilder" logfile="$log_dir/${source}_$(date +%Y%m%d.%H%M).log" changes="${binary_dir}${package}_${noe_version}_${dpkg_arch}.changes" if sudo pbuilder build --binary-arch --debbuildopts "-B -m\"$maint\"" --buildresult $binary_dir --logfile $logfile $dsc >/dev/null; then mail -s "[B] $source completed" $mail_to <> $fail_log log "failed to build $source - added to $fail_log" fi let "built_something+=1" } buildd_home=/home/buildd dpkg_arch=$(dpkg --print-architecture) source_dir=$buildd_home/source/ binary_dir=$buildd_home/debs/ log_dir=$buildd_home/logs/ fail_log=$buildd_home/fail force_log=$buildd_home/force restart_file=$buildd_home/restart die_file=$buildd_home/die mail_to=joshk@triplehelix.org maint="quickie-buildd.sh at $(hostname -f) <$mail_to>" completed_dir=$buildd_home/debs/completed min_greed=5 greed=${1:-$min_greed} # Clean up rm -rf $source_dir/* while true; do built_something=0 log "getting new needs-build (greed $greed)" needs_build=$(wget -q -O - http://www.buildd.net/buildd/${dpkg_arch}_needs-build.txt | tail -n $greed) if [ $? -ne 0 ]; then log "retrieving needs-build failed - sleeping for 10 mins.." sleep 600 else IFS=" " for src in $needs_build; do # Check for an override if [ -f "$force_log" ]; then while read fsource; do get_and_build $fsource done < $force_log rm -f $force_log fi check_restart get_and_build $src done # be more greedy, or you'll never get anything done if [ $built_something -eq 0 ]; then let "greed+=5" elif [ $built_something -ne $min_greed ]; then let "greed-=5" fi fi done