#!/bin/bash #(C)DatuX 2005 - all rights reserved BUILDFILE=$1 DEPTH=$2 IGNORE_REGEX='/CVS/|md5$|/\.git|/\.svn|/\.cvs|/docs|~$|\.depver$|\.arch$|\.version$|\.major$|\.check$|\.build$|\.check\.ok$'; if [ ! "`id -u`" = "0" ]; then echo "root priviliges required. Quiting..."; exit 1; fi shift shift for PAR in $*; do eval "$PAR=1" &>/dev/null; done if ! [ "$BUILDFILE" ]; then echo "Usage:" echo " $0 " echo " $0 " echo "To ignore changes to the package:" echo " $0 '' ignoremd5" echo "To regenerate md5 sum of a package, without rebuilding:" echo " $0 '' regenmd5" echo "To force rebuilding of a package that doesnt need it:" echo " $0 '' force" exit 1 fi msg() { echo "$DEPTH$*" } #buildfile meegeven? if ! [ -f "$BUILDFILE" ]; then #pkgname in plaats van rechstreekse buildfile meegegeven? BUILDFILE=`./findbuild $BUILDFILE`.SlackBuild if ! [ -f "$BUILDFILE" ]; then msg "ERROR: $BUILDFILE not found. (specify the syn-3 pkgname or path to .SlackBuild file)" exit 1 fi fi #kijk of een directory veranderd is. #(dit is puur om rebuild check sneller te maken en md5 checks te skippen) dir_changed() { DIR=$1 MD5=`ls -lR "$DIR"|md5sum` ! grep -x "$MD5" "$DIR/.signature" &>/dev/null } #bewaar signature store_dir() { DIR=$1 ls -lR "$DIR"|md5sum > "$DIR/.signature" } # bepaald absoluut path DIRNAME=`dirname $BUILDFILE` BASENAME=`basename $BUILDFILE` pushd $DIRNAME >/dev/null || exit 1 BUILDFILE="`pwd`/$BASENAME" popd >/dev/null if [ "$fast" ] && grep -x $BUILDFILE .tmp/builded &>/dev/null; then exit 0 fi DEPS=`cat "$BUILDFILE" |grep '^#DEP:'|cut -f2 -d':'` #### controleer of MD5 van al onze files nog kloppen #-negeer cvs dirs, md5sums en hidden files, backup files #-negeer ook andere arch en version files! DIR=`dirname $BUILDFILE` MD5FILE=`echo $BUILDFILE|sed 's/.SlackBuild$//g'`.md5 if ! [ "$ignoremd5" ]; then pushd "$DIR" >/dev/null || exit 1 find . -type f | #negeer bepaalde files egrep -v $IGNORE_REGEX | while read FILE; do MD5=`md5sum "$FILE"` #md5 sum gewijzigd of ontbreekt? if ! grep "$MD5" "$MD5FILE" &>/dev/null; then msg "Rebuild required: $FILE has changed!" exit 2 #exit 2, rebuild dus fi done RET=$? popd >/dev/null if [ "$RET" == "2" ]; then REBUILD=1 elif [ "$RET" != "0" ]; then msg "ERROR!" exit 1 fi fi #### controleer of er DEPS zijn die een ANDER major nummer hebben, waardoor we opnieuw moeten compilen DEPVERFILE=`echo $BUILDFILE|sed 's/.SlackBuild$//g'`.depver DEPERROR=0 for DEP in $DEPS; do if DEPBUILDNAME=`./findbuild "$DEP"`; then DEPMAJOR=`cat "$DEPBUILDNAME.major" 2>/dev/null` if ! [ "$DEPMAJOR" ]; then DEPMAJOR=0 fi MAJOR=`cat $DEPVERFILE 2>/dev/null |grep "^$DEP[[:space:]]"| cut -f2|head -1` if ! [ "$MAJOR" ]; then MAJOR=0 #FIXME: should be -1, but the requires a rebuild of a lot of old packages fi # echo "$DEP is '$DEPMAJOR' en '$MAJOR'" if [ "$DEPMAJOR" -ne "$MAJOR" ]; then msg "Rebuild required: $DEP major is now $DEPMAJOR, but this package was build was against $MAJOR." DEPERROR=1 fi fi done #if we need to rebuild because of a DEPERROR, check our direct dependencys first so that we rebuild the #"deepest" stuff first. if ! [ "$ignoredep" ] && [ "$DEPERROR" == "1" ]; then for DEP in $DEPS; do #zoek de buildbase op, als deze er al is if BUILDBASE=`./findbuild "$DEP"` 2>/dev/null; then msg "Dependency check $DEP" #note: niet de parameters meegeven, anders gaat hij alles rebuilden bij een force ./rebuildcheck "$BUILDBASE.SlackBuild" "|-$DEPTH" || exit 1 fi done fi if [ "$DEPERROR" == "1" ]; then REBUILD=1 fi if [ "$REBUILD" == "1" ] && [ "$nobuild" == "1" ]; then msg "Need to rebuild $BUILDFILE" msg "(no building because you specified nobuild)" REBUILD= fi if [ "$force" == "1" ]; then REBUILD=1 fi fatal(){ echo -e "Error while rebuilding $BUILDFILE!\a"; exit 1; } #### rebuild nodig? if [ "$REBUILD" == "1" ]; then if [ ! "$regenmd5" ] ; then msg "REBUILDING $BUILDFILE:" if grep '#NOBUILDROOT' "$BUILDFILE" >/dev/null; then msg "Building package without buildroot!" ( cd `dirname $BUILDFILE` || exit 1 $BUILDFILE $* || exit 1 ) || fatal else ( cd ../builder ./runrooted "$BUILDFILE" $* ) || fatal fi #show all packages contents: for PKG in `dirname $BUILDFILE`/*.pkg; do echo echo "################## Contents of $PKG:" tar -tvzf $PKG || fatal echo "################## end of $PKG " done #show all diffs: for PKG in `dirname $BUILDFILE`/*.pkg; do if [ "`git status --porcelain $PKG|grep -v '^?'`" != "" ]; then echo echo "################## DIFF of $PKG:" ./diffpkg $PKG echo "################## end of DIFF $PKG " fi done msg "Updating build numbers for $BUILDFILE..." pushd $DIR > /dev/null for PKG in *.pkg; do BUILD_FILE=`echo "$PKG"| sed 's/.pkg$//'`.build BUILD=`cat $BUILD_FILE 2>/dev/null` if [ "$BUILD" == "" ]; then BUILD=1 else (( BUILD=BUILD+1 )) fi echo $BUILD > $BUILD_FILE || exit 1 done popd >/dev/null else msg "Not building, only updating md5 sums.." fi msg "Updating md5 for $BUILDFILE..." #bepaal en bewaar major versies waartegen we gebuild hebben rm $MD5FILE &>/dev/null pushd $DIR >/dev/null find . -type f| sort | #negeer bepaalde files egrep -v $IGNORE_REGEX | while read FILE; do md5sum "$FILE" >> $MD5FILE done popd > /dev/null msg "Updating dependency information for $BUILDFILE..." DEPVERFILE=`echo $BUILDFILE | sed 's/.SlackBuild$//g'`.depver rm "$DEPVERFILE" &>/dev/null for DEP in $DEPS; do if DEPBUILDNAME=`./findbuild "$DEP"`; then DEPMAJOR=`cat "$DEPBUILDNAME.major" 2>/dev/null`; if ! [ "$DEPMAJOR" ]; then DEPMAJOR=0 fi echo -e "$DEP\t$DEPMAJOR" >> $DEPVERFILE || exit 1 fi done fi echo "$BUILDFILE" >> .tmp/builded if ! [ "$DEPTH" ]; then echo -e "All rebuilds completed.\a" fi #store_dir "$DIR" exit 0