#!/bin/bash # TODO # * Do version checking # * Detect circular builds # * Detect pkgnames by provides, replaces, etc. instead of dir tree [[ ! -r PKGBUILD ]] && { echo "This isn't a build directory" exit 1 } tmp_dir=$(mktemp -d /tmp/$(basename $PWD).XXXXXX) queue_file=$(mktemp /tmp/queue.XXXXXX) ban_file=$(mktemp) [[ ! -w $queue_file ]] && exit 1 [[ ! -w $ban_file ]] && exit 1 source /etc/makepkg.conf source /etc/abs.conf source /etc/libretools.conf [[ -r ~/.config/libretools/libretools.conf ]] && \ source ~/.config/libretools/libretools.conf # Queue Management # * Always get the queue list from the server # * Add/Remove from queue # * Check if a package is listed # TODO # * Check for concurrence guess_repo() { basename $(dirname $(pwd)) } # Get the queue list from the server get_queue() { rsync -e ssh -aq $PARABOLAHOST:mips64el/queue $queue_file >/dev/null 2>&1 || { error "Failed to retrieve queue list" return 1 } } # Put the queue list on the server put_queue() { rsync -e ssh -aq $queue_file $PARABOLAHOST:mips64el/queue >/dev/null 2>&1 || { error "Failed to put queue list" return 1 } } # Add packages to the queue update_queue() { get_queue || return $? basename $PWD | sed "s/$/:$PACKAGER/" >> $queue_file || return 2 put_queue || return $? } # Remove a package from the queue remove_queue() { get_queue || return $? grep -vw "^$(basename $PWD)" $queue_file > $queue_file.2 cat $queue_file.2 > $queue_file put_queue || return $? } # Checks if a package is listed check_queue() { get_queue || return $? packager=$(grep -w "$(basename $PWD)" ${queue_file} | cut -d ':' -f2) [[ ! -z $packager ]] && [[ "$packager" != "$PACKAGER" ]] && { warning "$(basename $PWD) is being packaged by $packager. Please wait." return 1 } return 0 } # Checks if the package is banned from building is_banned() { rsync -e ssh -aq $PARABOLAHOST:mips64el/ban $ban_file >/dev/null 2>&1 || { echo ":: Failed to get ban list" return 0 } grep -w $1 $ban_file >/dev/null 2>&1 return $? } # TODO keep track of spawned fullpkgs quit() { remove_queue exit 1 } repo=${1:-$(guess_repo)} source PKGBUILD msg "Building ${repo:-missing repo}/${pkgbase:-${pkgname[@]}}: $pkgdesc" is_built "${pkgbase:-${pkgname[0]}}>=${pkgver}-${pkgrel}" && exit 0 #sudo pacman -Sy trap "quit" TERM KILL INT if is_banned ${pkgbase:-$pkgname}; then error "This package is banned from building. Check the ban list" exit 1 fi check_queue || exit 1 failed=() missing=() if ! grep mips64el PKGBUILD >/dev/null; then msg "Adding mips64el arch" sed -i "s/^\(arch=([^)anym]\+\))/\1 'mips64el')/" "PKGBUILD" fi # Gets the dependency list from the package_* functions #pkgdeps=($(cat PKGBUILD | \ # tr -d "\n" | \ # sed -n "s/depends=(\([^)]\+\))/\n::\1\n/pg" | \ # grep --color=never "^::" | \ # tr -d [:\'\"] | \ # tr " " "\n" | \ # sort -u)) # Clean version checking deps=$(echo "${depends[@]} ${makedepends[@]} ${pkgdeps[@]}" | \ sed "s/[=<>]\+[^ ]\+//g" | \ tr ' ' "\n" | \ sort -u) msg "Checking dependencies" plain "${deps[@]}" #msg "Syncing database" #sudo pacman -Sy for _dep in ${deps[@]}; do is_banned $_dep && continue for _repo in ${REPOS[@]}; do # TODO find split packages [[ -e "$ABSROOT/${_repo}/$_dep/PKGBUILD" ]] && { source "$ABSROOT/${_repo}/$_dep/PKGBUILD" msg2 "Checking for $_dep>=$pkgver-$pkgrel" # If this version is built, continue with the next dep if is_built "$_dep>=$pkgver-$pkgrel"; then msg2 "No need to build this one" break fi cp -r "$ABSROOT/$_repo/$_dep" $tmp_dir/ || { error "Can't copy $_dep to the work dir." exit 1 } # Enter the work dir and run this command in it pushd $tmp_dir/$_dep >/dev/null $0 $_repo [[ $? -ne 0 ]] && { failed=(${failed[@]} $_dep) } popd >/dev/null break # } || { # The package can't be found # This can happen if: # * The package is built inside a split package # * The package is provided by some other package (ie by *-libre packages) # echo "==> Missing package $_dep" # missing=(${missing[@]} $_dep) } done done # TODO probably not elegant enough # [[ ${#failed[@]} -gt 0 ]] || [[ ${#missing[@]} -gt 0 ]] && { [[ ${#failed[@]} -gt 0 ]] && { error "This packages failed to build: ${failed[@]}" exit 1 } # [[ ${#missing[@]} -gt 0 ]] && { # echo ":: This packages are missing: ${missing[@]}" # } # exit 1 #} # Let everybody know we're building this update_queue || { warning "Couldn't update the queue, let your partners know about this." } cp -r ../$(basename $PWD) $tmp_dir/ pushd $tmp_dir/$(basename $PWD) >/dev/null msg "Syncing database" sudo pacman -Syu --noconfirm makepkg --noconfirm -sLcr ; r=$? case $r in 0) msg "The build was succesful." mipsrelease *.pkg.tar.* librestage $repo sudo pacman -Sy ;; 1) error "There were errors while trying to build the package." ;; 2) error "The build failed." ;; esac # Remove from queue remove_queue exit $r