#
# Copyright (C) by Stefano Falsetto
# e-mail contact ....: mailto:stefko5@inwind.it
#
#    This program 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 program 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 program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Plugin diskspace

begin_diskspace () {
  if [ ! -z "$SPACEDISK" ]; then
    local TMPSPC="$TEMPDIR/diskspace.$$"
    local DFP="$(df -P $SPOOLDIR)"
    local SPACE="$(echo "$DFP"|tail -1|tr -s ' '|cut -d' ' -f4)"
    local VOLUME="$(echo "$DFP"|tail -1|tr -s ' '|cut -d' ' -f1)"

    if [ ! -z "$SPACEDISK" ] && [ $SPACEDISK -eq 700 ]; then
      if [ $SPACE -lt "730000" ]; then
        echoc GREEN "WARNING: Disk space is not enough for a 700Mb CD-R!"
      fi
    else
      if [ $SPACE -lt "680000" ]; then
        echoc GREEN "WARNING: Disk space is not enough for a 650Mb CD-R!"
      fi
    fi
    echoc CYAN "Available space on volume $VOLUME: $SPACE Mb"
    rm -f $TMPSPC
  fi
}

syntax_diskspace () {
  echo "  --spacedisk <700|650>"
  echo "    Check for available disk space before decode all files"
  echo "    CD-R capacity (700Mb or 650Mb) can be specified"
  echo "    Default capacity: $DEF_SPACEDISK"
}

parse_param_diskspace () {
  if [ "$1" = "--spacedisk" ]; then
    if [ "$2" = "650" ] || [ "$2" = "700" ]; then
      SPACEDISK=$2
      SHIFT=2
      return 1
    else
      SPACEDISK=$DEF_SPACEDISK
      SHIFT=1
      return 1
    fi
  fi
}


