pool-delcd-from-fstab

#!/bin/sh

# 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 cd-mirror-dir iso-name [--verbose]"
}

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

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

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

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

VERSION="$3"

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

NAME="$4"

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

ISONAME="$5"

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

VERBOSE_ARG="$6"

VERBOSE=FALSE
if [ -n "$6" ]; then
    VERBOSE=TRUE
fi

umount $CONTENTSDIR/$VERSION/$NAME || exit 1

if [ "$VERBOSE" = "TRUE" ]; then 
    echo "CDBASEDIR=$CDBASEDIR"
    echo "CONTENTSDIR=$CONTENTSDIR"
    echo "VERSION=$VERSION"
    echo "NAME=$NAME"
    echo "ISONAME=$ISONAME"
    echo ""
#    echo '( cat /etc/fstab | grep -v "fuseiso#$CDBASEDIR/cd-$VERSION/$ISONAME $CONTENTSDIR/$VERSION/$NAME fuse defaults,allow_other 0 0"  >>/etc/fstab.new ) || exit 1'
    echo '( cat /etc/fstab | grep -v "$CDBASEDIR/cd-$VERSION/$ISONAME   $CONTENTSDIR/$VERSION/$NAME iso9660 defaults,loop   0   0"  >>/etc/fstab.new ) || exit 1'
fi
# ( cat /etc/fstab | grep -v "fuseiso#$CDBASEDIR/cd-$VERSION/$ISONAME   $CONTENTSDIR/$VERSION/$NAME   fuse   defaults,allow_other   0   0"  >>/etc/fstab.new ) || exit 1
( cat /etc/fstab | grep -v "$CDBASEDIR/cd-$VERSION/$ISONAME   $CONTENTSDIR/$VERSION/$NAME   iso9660   defaults,loop   0   0"  >>/etc/fstab.new ) || exit 1
mv /etc/fstab.new /etc/fstab || exit 1

exit 0