#!/bin/bash

# Wipe a Slackware package file from the package tree.
# This has to be a separate script because of the shopt setting below.
# I can't figure out how to include this in the main script and have the
# globbing functions *work* -- (e.g. include shopt -s and use the +([^-])
# stuff below - bash doesn't like it).
#
# This is particularly useful for KDE.SlackBuild and x11.SlackBuild since
# some packages have the same package name prefix - xcb-util- for example.
#
# To use this script from another:
# ensure PKGNAM, PKGSERIES and PKGSTORE are set and then call it directly
# /usr/share/slackdev/slackwipepkg
#
shopt -s extglob # needed to find package names

if [ -z "$PKGNAM" ]; 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

echo "Removing old versions of $PKGNAM from $PKGSTORE/$PKGSERIES"
rm -fv $PKGSTORE/$PKGSERIES/$PKGNAM-+([^-])-+([^-])-+([^-]).{t?z,txt,asc}
