#!/bin/bash

shopt -s extglob # needed to find package names

#   echo "Syntax: slackmp [-p]"
# is prepend symlink creation code.

if [ -z "$SLACKPACKAGE" ]; then
   echo "Variable SLACKPACKAGE is not set"
   exit 1
fi

if [ -z "$PKGSERIES" ]; then
   echo "Variable PKGSERIES is not set"
   exit 1
fi
if [ -z "$PKGSTORE" ]; then
   echo "Variable PKGSTORE is unset"
   exit 1
fi

# Delete old package from the t?z stash?
if [ "${DELETEOLDPKGS}" = "Yes" ]; then
   echo "Removing old versions of $PKGNAM from $PKGSTORE/$PKGSERIES"
   rm -fv $PKGSTORE/$PKGSERIES/$PKGNAM-+([^-])-+([^-])-+([^-]).{t?z,txt,asc}
fi

echo "Running makepkg $1 -l y -c n $PKGSTORE/$PKGSERIES/$SLACKPACKAGE"
mkdir -vpm755 $PKGSTORE/$PKGSERIES
makepkg $1 -l y -c n $PKGSTORE/$PKGSERIES/$SLACKPACKAGE
if [ "$PKGSERIES" = "/" ]; then
    echo "**** YOUR PACKAGE NEEDS TO BE MANUALLY MOVED FROM $PKGSTORE ****"
 fi
