#!/bin/bash

# The slackpkg package in Slackware is arch neutral and has no
# source package, so we just copy the version in Slackware as-is.

# Record toolchain & other info for the build log:
slackbuildinfo

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PKGNAM
export PORTCWD=$PWD

# Wipe existing package from the tree:
rm -fv $PKGSTORE/ap/slackpkg-*

# Temporary build locations:
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

if [ -f $PORTCWD/sources/slackpkg-*noarch-*.t?z ]; then
   tar xvvf $PORTCWD/sources/slackpkg-*noarch-*.t?z
 else
   tar xvvf $SLACKSOURCE/../slackware*/ap/slackpkg-*.t?z
fi

# Mirrors are included in slackpkg by default - they just need
# uncommenting.

# Set the arch to ARM or AArch64 by default:
sed -i 's?^#ARCH=.*?ARCH='"${SLKPORTARCH}"'?g' etc/slackpkg/slackpkg.conf.new

# Mirror locations are maintained within Slackware ARM, but
# fed back upstream when changed:
# Delete all samples:
rm -f usr/doc/slackpkg-*/mirrors-*sample
# Install only the relevant one for this architecture:
install -vpm644 $PORTCWD/mirrors-${SLKPORTARCH}.sample usr/doc/slackpkg-*/

# Switch Slackware GPG key with the ARM port's:
#sed -i 's/^SLACKKEY.*=\(.*\)$/SLACKKEY="ARMedslack Security (ARMedslack Linux Project Security) <security@armedslack.org>"/' usr/sbin/slackpkg
# No longer needed for 2.83.0 release.
#sed -i 's?ARMedslack Security (ARMedslack Linux Project Security) <security@armedslack.org>?Slackware ARM (Slackware ARM Linux Project) <mozes@slackware.com>?g' usr/libexec/slackpkg/core-functions.sh

# Unbreak ARM:
# https://git.rlworkman.net/slackpkg/patch/?id=30e32fbc7ae3a9990d694b9910ff07a8847ab80c
#pushd usr/libexec/slackpkg/
#auto_apply_patch $PORTCWD/unbreakarm.diff || failpatch
#rm -fv *.orig
#popd

# Rebuild package:
chown root:root .
makepkg -l y -c n $PKGSTORE/ap/slackpkg-$VERSION-noarch-$BUILD.txz

#EOF
