#!/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

rm -fv $PKGSTORE/ap/slackpkg-*
#install -vpm644 $SLACKSOURCE/../slackware/ap/slackpkg-*.tgz $PKGSTORE/ap
# So that the changelog generator script picks up the new package:
#touch $PKGSTORE/ap/slackpkg-*

# But it needs patching for ARMedslack:

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

#tar xvvf $SLACKSOURCE/../slackware/ap/slackpkg-*.tgz
tar xvvf $PORTCWD/sources/slackpkg-*noarch*

# Add ARMedslack mirrors:
rm -fv etc/slackpkg/{mirrors*,slackpkg.conf*}
install -vpm644 $PORTCWD/sources/mirrors.new etc/slackpkg/

# Slackpkg config file.
# This has the ARCH value set to 'ARM' by default.
install -vpm644 $PORTCWD/sources/slackpkg.conf.new etc/slackpkg/

# Switch Slackware GPG key with ARMedslack's, since AS's packages aren't signed
# by Slackware.
sed -i 's/^SLACKKEY.*=\(.*\)$/SLACKKEY="ARMedslack Security (ARMedslack Linux Project Security) <security@armedslack.org>"/' usr/sbin/slackpkg

# Rebuild package:
chown root:root .
makepkg -l y -c n $PKGSTORE/ap/$(basename $PORTCWD/sources/slackp*noarch*) 
