################################################################################ srcdir=src pkgdir=pkg/$pkgname arch="$(uname -m)" DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u' 'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u' 'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u' 'rsync::/usr/bin/rsync -z %u %o' 'scp::/usr/bin/scp -C %u %o') INDENT=' ' msg () { echo "$(tput bold)$(tput setf 2)==>$(tput setf 7) $1" shift 1 for i; do echo "${INDENT}$i" done echo -n "$(tput sgr0)" } msg2 () { echo "$(tput bold)$(tput setf 1) ->$(tput setf 7) $1" shift 1 for i; do echo "${INDENT}$i" done echo -n "$(tput sgr0)" } warning () { echo "$(tput bold)$(tput setf 6)==> WARNING:$(tput setf 7) $1" shift 1 for i; do echo "${INDENT}$i" done echo -n "$(tput sgr0)" } error () { echo "$(tput bold)$(tput setf 4)==> ERROR:$(tput setf 7) $1" shift 1 for i; do echo "${INDENT}$i" done echo -n "$(tput sgr0)" } _init() { mkdir -p "$srcdir" mkdir -p "$pkgdir" srcdir="$(realpath "$srcdir")" pkgdir="$(realpath "$pkgdir")" } _listdeps() { msg "$pkgname $pkgver-$pkgrel" msg2 "Runtime dependencies" printf -- '%s\n' "${depends[@]}" msg2 "Buildtime dependencies" printf -- '%s\n' "${makedepends[@]}" msg2 "Optional dependencies" printf -- '%s\n' "${optdepends[@]}" } _fetch() { msg "Retrieving sources..." for URI in "${source[@]}"; do case "$URI" in http://*|https://*|ftp://*) FILE="${URI##*/}" msg2 "Downloading $FILE..." wget $OPT_FORCE_WGET "$URI" -O "$FILE" ## Strangely enough, wget will not return 0 on success. On error, it ## will still create a 0-byte file. if [ $(du -sb "$FILE" | awk '{print $1}') -eq 0 ]; then error "Failure while downloading $FILE" "Aborting..." exit 1 fi ;; git+*) GITURI="${URI#git+}" if [ -d "${_gitname:-$FILE}/.git" ]; then if ! $OPT_NOCLOBBER; then cd "${_gitname:-$FILE}" git pull fi else git clone "$GITURI" fi ;; *) ## Embedded files (patches, resources...) # Do nothing. esac done } _checksum () { if $OPT_CHECKSKIP; then warning "Skipping verification of source file checksums." return fi RESULT=true case ${#source[*]} in ${#md5sums[*]}) CHECKSUMMER=md5sum;; ${#sha1sums[*]}) CHECKSUMMER=sha1sum;; ${#sha256sums[*]}) CHECKSUMMER=sha256sum;; ${#sha384sums[*]}) CHECKSUMMER=sha384sum;; ${#sha512sums[*]}) CHECKSUMMER=sha512sum;; *) error "Integrity checks are either missing or differ in size." exit 1;; esac msg "Validating source files with ${CHECKSUMMER}s..." ## Here we need to use a numeric index to browse arrays to make sure we get ## same index for both arrays. ## WARNING: this will only work in bash because indexing starts at 0. for i in $(seq 0 $((${#source[@]} -1))); do eval test '${'${CHECKSUMMER}'s[$i]}' = 'SKIP' if [ $? -eq 0 ]; then echo "Skipped" continue fi FILE="${source[$i]##*/}" if [ ! -f "$FILE" ]; then error "$FILE was not found in the build directory and is not a URL." exit fi CHECKSUM="$($CHECKSUMMER "$FILE" | cut -f1 -d' ')" echo -n "$INDENT$FILE ... " ## Note: here we take care to control expansion at the right time. eval test '$CHECKSUM' = '${'${CHECKSUMMER}'s[$i]}' if [ $? -eq 0 ]; then echo "Passed" else echo "FAILED" RESULT=false fi done if ! $RESULT; then error "One or more files did not pass the validity check!" exit 1 fi } _extract () { msg "Extracting sources..." for URI in "${source[@]}"; do FILE="${URI##*/}" case "$FILE" in *.tar.bz2|*.tbz2|*.tar.gz|*.tgz|*.tar.xz|*.txz) msg2 "Extracting $FILE with tar" tar xf "$FILE" -C "$srcdir" $OPT_FORCE_TAR;; *) case "$URI" in git+*) ln -sf "../${_gitname:-$FILE}" "$srcdir";; *) ln -sf "../$FILE" "$srcdir";; esac esac done } _buildhook() { msg "Starting build()..." (cd "$srcdir" && build) } _tidying () { for i in "${options[@]}"; do if [ "$(echo $i | sed 's/\(.\).*/\1/')" = "!" ]; then eval TIDY_$(echo $i | sed 's/^!//')=false else eval TIDY_$i=true fi done if $TIDY_purge; then msg2 "Purging unwanted files..." find * -type f \( -name '.packlist' -o -name '*.pod' \) -delete rm -f "usr/share/info/dir" "usr/info/dir" fi if $TIDY_docs; then msg2 "Compressing man and info pages..." find * -type f -name '*.[0-9]' -exec gzip {} \; fi if $TIDY_strip; then msg2 "Stripping unneeded symbols from binaries and libraries..." find * -type f -executable -exec strip -s {} \; 2>/dev/null fi ## We make sure folder permissions are world accessible. find * -type d -exec chmod o+rx {} \; } _compress() { msg "Creating package \"$pkgname\"..." UNINS="$pkgname-$pkgver-$pkgrel-uninstall.sh" msg2 "Generating $UNINS..." echo '#!/bin/sh' > "$UNINS" (cd "$pkgdir" && \ find * -type f -exec echo "rm /"{} \; && \ find * -type d -exec echo "rmdir /"{} \; ) >> "$UNINS" chmod +x "$UNINS" msg2 "Compressing package..." if [ "$(uname)" = "Linux" ]; then ls "$pkgdir" | tar --numeric-owner --owner=root --group=root \ -C "$pkgdir" -cJf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -T - else ## BSD and others. WARNING: this may not be portable. ls "$pkgdir" | tar --numeric-owner --uid 0 --gid 0 \ -C "$pkgdir" -cJf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -T - fi } _packagehook() { if $OPT_NOCLOBBER && [ $(ls -a1 "$pkgdir" | wc -l) -ne 2 ]; then warning "A package has already been built. Skipping. (Use -f to overwrite.)" return fi rm -rf "$pkgdir" msg "Starting package()..." (cd "$srcdir" && package) msg "Tidying install..." (cd "$pkgdir" && umask 022 && _tidying) _compress } _clean () { msg "Cleaning up..." rm -r "$srcdir" "$pkgdir" } _install() { msg "Installing package $pkgname..." ## Only use sudo if user has write permission to DESTROOT. if [ -w "$OPT_DESTROOT" ]; then tar -xkf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -C "$OPT_DESTROOT" else sudo tar -xkf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -C "$OPT_DESTROOT" fi } _printhelp () { cat <