#!/usr/bin/env sh # exit on error set -e # variables unbound_dir="/tmp/unbound" src_dir="$unbound_dir/src" # functions function checkEnvironment() { [[ -n "$VERSION" ]] && return printf "environment variable 'VERSION' is unset, defaulting to 'latest'...\n" VERSION="latest" } function checkAndExtractArchive() { cd "$src_dir" archive="$(find "$src_dir" -type f -iname 'unbound*.tar.gz' -exec basename {} \;)" [[ -n "$archive" ]] && tar -xzf "$archive" && rm -f "$archive" && return archive="$(find "$src_dir" -type f -iname 'unbound*.zip' -exec basename {} \;)" [[ -z "$archive" ]] && return unzip -q "$archive" -d "$(basename -s ".zip" $archive)" && rm -f "$archive" } function getPkgVersion() { pkgver="$(find "$src_dir" -type d -iname 'unbound*' -exec sh -c "realpath {} | cut -d "-" -f2" \;)" } function downloadSources() { mkdir -p "$src_dir" cd "$src_dir" wget "https://nlnetlabs.nl/downloads/unbound/unbound-$VERSION.tar.gz" tar -xzf "unbound-$VERSION.tar.gz" rm -f "unbound-$VERSION.tar.gz" } # main routine printf "starting build process for unbound with redis support...\n" # check if an archive is in "$src_dir" present and extract it checkAndExtractArchive # check if a valid version has been copied to "$src_dir" getPkgVersion # if no valid version could be found, start a download if [[ -z "$pkgver" ]]; then checkEnvironment downloadSources getPkgVersion fi # exit if no unbound version could be determined [[ -z "$pkgver" ]] && printf "error: could not determine unbound version\n" && exit 1 # replace version in APKBUILD file sed -i "s/pkgver=0.0.0/pkgver=$pkgver/" "$unbound_dir/APKBUILD" # generate key pairs printf "\n" | abuild-keygen -a # generate checksums and start the build cd "$unbound_dir" abuild -F checksum abuild -F -r # move the built packages [[ ! -d "/build" ]] && mkdir -p "/build" rm -rf "/build/"* find $HOME/packages -type f -iname '*.apk' -exec mv {} /build \; # clean up rm -rf "$unbound_dir" printf ".apk files can be found at '/build'\n" cd "/build" ls -1