#!/bin/sh --

for i in pngtopnm pnmscale pnmtopng
do
  which $i >/dev/null 2>/dev/null
  if test $? = 1; then
    me=`basename $PWD`
    echo "*******************************************************************************"
    echo
    echo "\"$i\" not found."
    echo "This means it will not be possible to create/complete this iconset, \"$me\"."
    echo "If you don't care, ignore this message, otherwise, read on."
    echo
    echo "Possible reasons:"
    echo "- you don't have the netpbm package"
    echo "- netpbm is old or incomplete"
    echo "- netpbm binaries are in a directory not in PATH"
    echo
    echo "Possible fix:"
    echo "- Install a recent netpbm and make sure the binaries are found."
    echo
    echo "*******************************************************************************"
    exit
  fi
done

HERE=$PWD

cd ../indigo_128
cp mime.icons $HERE 2>/dev/null
cp README?* $HERE 2>/dev/null

mask=$HERE/mask

echo "MASK IS $mask"

find . -name "*.png"|while read j
do
  i=`basename $j`
  d=`dirname $j`
  mkdir -p "$HERE/$d" 2>/dev/null
  echo "$j -> $HERE/$d/$i"
  pngtopnm -alpha $j|pnmscale -width 96 -height 96 > $mask
  pngtopnm $j|pnmscale -width 96 -height 96|pnmtopng -alpha $mask > $HERE/$d/$i
  echo
done

rm $mask

cd $HERE

find . -name "_*.png"|while read o
do
  d=`dirname $o`
  i=`basename $o`
  j=`echo $i|cut -c 2-`
  echo "Overriding \"$j\" (with \"$i\")..."
  i="$d/$j"
  cp $o $i
done
