pool-delcd

# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this file, if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

usage_message () {
    echo "Usage: $0 cd-iso-directory cd-contents-directory version-string cd-name iso-name [--verbose]"
}

pushd () {
    OLDCURDIR="$(pwd)"
    cd "$1"
}

popd () {
    cd "$OLDCURDIR"
}

CDBASEDIR=$(readlink --no-newline --canonicalize-existing "$1")

if [ -z "$CDBASEDIR" ]; then
    usage_message
    echo "Unknown cd base directory"
    exit 1
fi

CONTENTSDIR=$(readlink --no-newline --canonicalize-existing "$2")

if [ -z "$CONTENTSDIR" ]; then
    usage_message
    echo "Unknown directory for CD contents"
    exit 1
fi

VERSION="$3"

if [ -z "$VERSION" ]; then
    usage_message
    echo "Unknown version"
    exit 1
fi

NAME="$4"

if [ -z "$NAME" ]; then
    usage_message
    echo "Unknown cd name"
    exit 1
fi

ISONAME="$5"

if [ -z "$ISONAME" ]; then
    usage_message
    echo "Unknown ISO image name"
    exit 1
fi

VERBOSE=FALSE

if [ "$6" = "--verbose" ]; then
    VERBOSE=TRUE
    echo "Verbose messages on"
fi

[ "$VERBOSE" = "TRUE" ] && echo "cd contents: $CONTENTSDIR"

if [ "$VERBOSE" = "TRUE" ]; then
    echo "CDBASEDIR=$CDBASEDIR"
    echo "CONTENTSDIR=$CONTENTSDIR"
    echo "VERSION=$VERSION"
    echo "NAME=$NAME"
    echo "ISONAME=$ISONAME"
fi

VERBOSE_ARG=
[ "$VERBOSE" = "TRUE" ] && VERBOSE_ARG="--verbose"

echo "    Deleting $ISONAME"
if [ -n "$(cat /etc/fstab | grep $CDBASEDIR/cd-$VERSION/$ISONAME )" ]; then
    sudo pool-delcd-from-fstab "$CDBASEDIR" "$CONTENTSDIR" "$VERSION" "$NAME" "$ISONAME" "$VERBOSE_ARG" || exit 1
fi