#!/bin/sh

for x in bzip2 cairo fontconfig freetype2 gimp210 gtkcore
do
    LD_LIBRARY_PATH=$PRODTREE/$x/lib:$LD_LIBRARY_PATH
done
export LD_LIBRARY_PATH

DIR=$HOME/.config/GIMP/2.10
mkdir -p $DIR $DIR/gradients
GRCFILE=$DIR/gimprc

if [ \! -f $GRCFILE ]; then
    WHO=`whoami`
    WHODIR=/var/tmp/gimp/$WHO
    mkdir -p $WHODIR

    cat  > $GRCFILE << END
(temp-path "$WHODIR")
(swap-path "$WHODIR")
(num-processors 4)
(tile-cache-size 512M)
(theme "System")
(icon-theme "Color")
END
fi

PRODGIMP=$PRODTREE/gimp210
cp -p $PRODGIMP/share/gimp/2.0/sessionrc $DIR/

if [ \! -f $DIR/tags.xml ]; then
    cp -p $PRODGIMP/share/tags.xml $DIR/
fi

str="$1"
if [ "@$1" \!= "@" ]; then
    if [ "@$2" == "@" ]; then
        str="$1"
        cvtname=`echo "$str" | sed -e 's@\.avif$@.png@'`
        if [ "@$str"  \!= "@$cvtname" ]; then
            convert "$str" "$cvtname"
            exec $PRODGIMP/bin/gimp-2.10.bin "$cvtname"
        fi
    fi
fi

exec $PRODGIMP/bin/gimp-2.10.bin $*
