diff options
-rwxr-xr-x | fullpkg | 227 |
1 files changed, 106 insertions, 121 deletions
@@ -1,4 +1,9 @@ #!/bin/bash +# set -x # uncomment for debug +# Builds packages from ABS recursively. It tries to find dependencies that +# aren't built or need update and then makepkg them in order. + +# TODO move __build to chroot source /etc/makepkg.conf source /etc/abs.conf @@ -15,7 +20,7 @@ elif [ -e $XDG_CONFIG_HOME/libretools/libretools.conf ]; then fi -function usage { +usage() { echo "cd to a dir containing a PKGBUILD and run:" echo "$0 [options]" @@ -36,27 +41,26 @@ function usage { } -function remove_buildorder { # Removes a package from the buildorder +# Removes a package from the buildorder # $1 package name # $2 buildorder file - +remove_buildorder() { grep -Evw "${1}" ${2} > ${2}2 mv -f ${2}2 ${2} + return $? } -function guess_repo { # Get repo name. Asumes ${ABSROOT}/repo/package/PKGBUILD - - basename $(dirname $(pwd)) # Variable in prfullpkg - +# Get repo name. Asumes ${ABSROOT}/repo/package/PKGBUILD +guess_repo() { + basename $(dirname $(pwd)) } -function get_fullver { # return : full version spec, including epoch (if necessary), pkgver, pkgrel - +# return : full version spec, including epoch (if necessary), pkgver, pkgrel # usage : get_fullver( ${epoch:-0}, $pkgver, $pkgrel ) - +get_fullver() { if [[ $1 -eq 0 ]]; then - # zero epoch case, don't include it in version +# zero epoch case, don't include it in version echo $2-$3 else echo $1:$2-$3 @@ -64,52 +68,60 @@ function get_fullver { # return : full version spec, including epoch (if necessa } -function cleanup { # Cleans the build_dir. +# Cleans the build_dir. +cleanup() { +# Do nothing or already cleaned. + [[ "${do_cleanup}" = false || ! -d ${build_dir} ]] && return 0 - [ ! -d "${build_dir}" -o "${build_only}" = 'y' ] && return 0 # Do nothing or already cleaned. +# Only do cleanup on level 0. + msg "Cleaning up..." + [ $level -eq 0 ] && rm -rf $build_dir/ - - if [ $level -eq 0 ]; then # Only do cleanup on level 0. - msg "Cleaning up ${build_dir}" - rm -rf "$build_dir/*" - fi } -function find_deps { # Checks ABSROOT and look for target pkg deps. Adds them if not built or outdated. - - source PKGBUILD ## Check this level. +# Checks ABSROOT and look for target pkg deps. Adds them if not built or outdated. +find_deps() { +# Check this level + source PKGBUILD local repo=${repo:-$(guess_repo)} local pkgbase=${pkgbase:-${pkgname[0]}} +# Provide a default 0 to epoch local epoch=${epoch:-0} local fullver=$(get_fullver ${epoch} ${pkgver} ${pkgrel}) if is_built "${pkgbase}>=${fullver}"; then - exit 0 # pkg is built and updated +# pkg is built and updated + exit 0 fi - echo "${level}:${pkgbase}" >> "${build_dir}/BUILDORDER" # greater levels are built first - - if [ -d "${build_dir}/${pkgbase}" ]; then # PKGBUILD is already there +# greater levels are built first + echo "${level}:${pkgbase}" >> "${build_dir}/BUILDORDER" +# PKGBUILD is already there + if [ -d "${build_dir}/${pkgbase}" ]; then exit 0 - else # Copy dir to build_dir -## variable block for prfullpkg +# Copy dir to build_dir + else cp -r ../${pkgbase}/ ${build_dir}/ - echo "repo=$repo" > "${build_dir}/${pkgbase}/.INFO" # to identify repo later +# to identify repo later + echo "repo=$repo" > "${build_dir}/${pkgbase}/.INFO" fi - - msg2 "%${level}s${pkgbase}-${fullver}" # current package plus a space for every level - declare -i next_level=$level+1 ## Check next levels +# current package plus a space for every level + msg2 "%${level}s${pkgbase}-${fullver}" + +## Check next levels + declare -i next_level=$level+1 +# All deps in separate line, only once, without version. deps=$(echo "${depends[@]} ${makedepends[@]}" | \ sed "s/[=<>]\+[^ ]\+//g" | \ tr ' ' "\n" | \ - sort -u) # All deps in separate line, only once, without version. + sort -u) for _dep in ${deps[@]}; do @@ -118,48 +130,26 @@ function find_deps { # Checks ABSROOT and look for target pkg deps. Adds them i # TODO ask toru where the pkgbuild is for _repo in ${REPOS[@]}; do - if [ -e "${ABSROOT}/${_repo}/${_dep}/PKGBUILD" ]; then # ABSROOT/repo/package - +# ABSROOT/repo/package + if [ -e "${ABSROOT}/${_repo}/${_dep}/PKGBUILD" ]; then + pushd "${ABSROOT}/${_repo}/${_dep}" > /dev/null - $0 -c -d ${build_dir} -l ${next_level} # run this cmd on dep's PKGBUILD dir - [ $? -eq 20 ] && return 20 # probable circular deps +# run this cmd on dep's PKGBUILD dir + $0 -c -d ${build_dir} -l ${next_level} +# probable circular deps + [ $? -eq 20 ] && return 20 popd > /dev/null local found=true - break 1 # found, end cycle +# found, end cycle + break 1 fi - - done - - if ( ${found} ); then - - continue 1 # go to next dep - - else # pkgsplit, needs guess - - for _repo in ${REPOS[@]}; do - if _dir=($(find "$ABSROOT/${_repo}" -type f \ - -name PKGBUILD -print0 2>/dev/null | \ - "xargs" -0 -e grep -HEw "pkgname=|pkgbase=|provides=" | \ - grep -w "$_dep" 2>&1)); - - then - - _dir=$(dirname $(echo $_dir | cut -d: -f1)) - plain "guess for $_dep -> $_dir" - pushd "$_dir" > /dev/null - $0 -c -d ${build_dir} -l ${next_level} # run this cmd on dep's PKGBUILD dir - [ $? -eq 20 ] && return 20 # probable circular deps - popd > /dev/null - local found=true - break 1 # found, end cycle - fi + done - done - fi if ( ${found} ); then - continue 1 # go to next dep +# go to next dep + continue 1 else echo "dep_not_found:$_dep" >> $build_dir/log fi @@ -175,10 +165,11 @@ function find_deps { # Checks ABSROOT and look for target pkg deps. Adds them i options install changelog source noextract md5sums build check package } -function __build () { +__build() { pushd ${build_dir} > /dev/null - build_packages=($(sort -gr $buildorder | cut -d: -f2)) # greater levels must be built first +# greater levels must be built first + build_packages=($(sort -gr $buildorder | cut -d: -f2)) while [ ${#build_packages[@]} -ge 1 ]; do pushd $build_dir/${build_packages[0]} > /dev/null @@ -188,28 +179,33 @@ function __build () { msg2 "Checking for non free deps" pkgbuild-check-nonfree || { - if [ $? -eq 15 ]; then # this error means nonfree others means fail. +# this error means nonfree others means fail. + if [ $? -eq 15 ]; then echo "nonfree:$(basename $PWD)" >> $build_dir/log - remove_buildorder "$(basename $PWD)" $buildorder # take out package from $buildorder +# take out package from $buildorder + remove_buildorder "$(basename $PWD)" $buildorder - continue # build next package +# build next package + continue fi } msg2 "Building $(basename $PWD)" - $FULLBUILDCMD; r=$? # this buildcmd is on libretools.conf +# this buildcmd is on libretools.conf + $FULLBUILDCMD; r=$? case $r in - 0) ## Succesfull build +## Succesfull build + 0) plain "The build was succesful." if source .INFO && [ -n $repo ]; then - # Calls a local release script if it's used +# Calls a local release script if it's used if [ ! -z $HOOKLOCALRELEASE ]; then find -name "*.pkg.tar.?z" -print0 | xargs -0 $HOOKLOCALRELEASE $repo fi @@ -224,7 +220,8 @@ function __build () { echo "built:$(basename $PWD)" >> $build_dir/log ;; - *) ## Build failed +## Build failed + *) error "There were errors while trying to build the package." echo "failed:$(basename $PWD)" >> $build_dir/log ;; @@ -232,7 +229,8 @@ function __build () { remove_buildorder "${build_packages[0]}" $buildorder || true - build_packages=($(sort -gr $buildorder | cut -d: -f2)) # which is next package? +# which is next package? + build_packages=($(sort -gr $buildorder | cut -d: -f2)) popd > /dev/null done @@ -259,7 +257,8 @@ function __build () { popd > /dev/null } -function trap_exit { # End inmediately but print a useful message +# End inmediately but print a useful message +trap_exit() { error "$@" warning "Leftover files left on $build_dir" @@ -299,16 +298,18 @@ while getopts 'ha:b:cCd:l:nm:r:' arg; do c) check_deps_only=true ;; C) do_cleanup=true;; d) build_dir="$OPTARG" ;; - l) level=$OPTARG ;; # hidden option to know dep level. - n) noupdate='y';; +# hidden option to know dep level. + l) level=$OPTARG ;; + n) noupdate=true;; m) max_level=$OPTARG ;; r) FULLBUILDCMD="$OPTARG" ;; esac done -if [ ! ${build_only} ]; then +if [[ ! ${build_only} ]]; then - if [ ! -r PKGBUILD ]; then # Check if we are actually on a build directory. Do this early. +# Check if we are actually on a build directory. Do this early. + if [ ! -r PKGBUILD ]; then error "This isn't a build directory" usage fi @@ -321,25 +322,29 @@ fi if [ $level -eq 0 ]; then - if [ ! -d ${build_dir} ]; then # in case of custom -d option - mkdir -p ${build_dir} +# use -d option or else mktemp + build_dir=${build_dir:-$(mktemp -d /tmp/fullpkg.XXXXXX)} + +# in case of custom -d option + if [ ! -d ${build_dir} ]; then + mkdir -p ${build_dir} else - cleanup # files already there can screw find_deps +# files already there can screw find_deps + cleanup fi - build_dir=${build_dir:-$(mktemp -d /tmp/fullpkg.XXXXXX)} # use -d option or else mktemp - - touch ${build_dir}/{log,BUILDORDER} ${ban_file} # make files for log and buildorder +# make files for log and buildorder + touch ${build_dir}/{log,BUILDORDER} ${ban_file} buildorder=${build_dir}/BUILDORDER - if [ ! ${noupdate} ]; then + if ! (( noupdate )); then msg "Updating pacman db and packages" sudo pacman -Syu --noconfirm || true fi - if [ ${build_only} ]; then + if (( build_only )); then msg "Build Packages" @@ -352,51 +357,31 @@ if [ $level -eq 0 ]; then msg "Checking dependencies" fi -[ $level -ge $max_level ] && exit 20 # Probable circular deps +# Probable circular deps +[ $level -ge $max_level ] && exit 20 find_deps || { - if [ $? -eq 20 ]; then # Probable circular deps +# Probable circular deps + if [ $? -eq 20 ]; then - if [ $level -eq 0 ]; then # Show error only on level 0 +# Show error only on level 0 + if [ $level -eq 0 ]; then error "Check for circular deps on $build_dir/BUILDORDER"; fi fi - exit 20 # Pass message 20 +# Pass message 20 + exit 20 } -[ $check_deps_only = 'y' -o $level -gt 0 ] && exit 0 # only build on level 0 - -if [ $level -eq 0 -a -d $build_dir ]; then # Sanity check - - if [ ! -w $ban_file -o ! -r $ban_file ]; then # Check ban_file permisions - - chmod a+rw $ban_file || error "Ban file is not readable/writable ($ban_file)" - - else - - rsync -e ssh -aq $PARABOLAHOST:mips64el/ban >/dev/null 2>&1 || { - - warning "Failed to get ban list" && [ -r ${ban_file} ] && { # use local copy if it exist - - search=$(cat ${ban_file} | tr "\n" "|") - - egrep -w "$search" ${buildorder} >> ${build_dir}/banned # Keep track of banned files - - egrep -vw "$search" ${buildorder} > ${buildorder}2 # Take banned packages out of buildorder - - mv -f ${buildorder}2 ${buildorder} - - unset search - } - } - fi -fi +# only build on level 0 +$( (( check_deps_only )) || [ $level -gt 0 ] ) && exit 0 msg "Building packages:" -__build # Build the packages +# Build the packages +__build echo msg2 "Check if your system works fine and librerelease if it does" |