#!/bin/bash

# The VERSION is automatically determined at the bottom of this
# script, based on the version number in /usr/doc.
BUILD=2

# 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

tar xvvf $SLACKSOURCE/../slackware*/ap/slackpkg-*.t?z

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

# Set the arch to ARM by default:
sed -i 's?^#ARCH=.*?ARCH=arm?g' etc/slackpkg/slackpkg.conf.new

# Add a new mirror:
install -vpm644 $PORTCWD/mirrors-arm.sample usr/doc/slackpkg-*/

# Switch Slackware GPG key with ARMedslack's, since AS's packages aren't signed
# by Slackware.
# This should have been taken care of by Piterpunk upstream a while ago.
#sed -i 's/^SLACKKEY.*=\(.*\)$/SLACKKEY="ARMedslack Security (ARMedslack Linux Project Security) <security@armedslack.org>"/' usr/sbin/slackpkg

# Rebuild package:
chown root:root .
# Not noarch because we've switched the default Arch to be arm.
VERSION=$( ls -d usr/doc/slackpkg-* | cut -d- -f2 | cut -d/ -f1 )
makepkg -l y -c n $PKGSTORE/ap/slackpkg-$VERSION-arm-$BUILD.tgz

#EOF
