#!/bin/sh
#  This script is to add a default value for the recycle_min_free item to the
#  gdi-record config if there isn't one already there.  This is following the
#  change in the gdi-record config to have a value set by default instead of
#  relying on the user to set one.  This should help stop the storage disk
#  filling up and having problems.

# Only run once
[ -n "${POST_UPGRADE_CACHE}" ] && touch "${POST_UPGRADE_CACHE}/`basename $0`"

echo " * Checking gdi-record config file for recycle value"

GDIRECORDCFG=/etc/gdi-record/gdi-record.local
DEFAULTRECYCLE=50

# There is only one instance of the gdi-record config file and if it
# doesn't exist then there is something wrong.
if [ ! -r $GDIRECORDCFG ]
then
    echo " * ERROR: No gdi-record config file found"
else
    recycle=`gcs_rwvar 'gcs_get_varcf2' recycle_min_free "${GDIRECORDCFG}" ''`
    echo recycle $recycle >> /tmp/kad
    if [ -z "${recycle}" ]
    then
        echo "   No recycle value found - setting default"
	gcs_rwvar gcs_set_varcf2 "recycle_min_free" "${GDIRECORDCFG}" "${DEFAULTRECYCLE}" ""
    fi
fi

exit 0
