#!/bin/sh
set -e

inkscape --version > /dev/null || { echo "Error: Inkscape needed to generate macos iconset files"; exit 1; }

case $1 in
  -*) in=./$1 ;;
  *) in=$1 ;;
esac
case $2 in
  -*) out=./$2 ;;
  *) out=$2 ;;
esac
tmp=`echo "$out"|sed 's/\.zip$//'`

rm -rf "$tmp"
mkdir "$tmp"
for r in 16 32 128 256 512 ; do
  inkscape -w "$r" -h "$r" --export-filename="$tmp/icon_${r}x${r}.png" "$in"
done
for r in 16 128 256 ; do
  d=`expr $r + $r`
  ln "$tmp/icon_${d}x${d}.png" "$tmp/icon_${r}x${r}@2x.png"
done
for r in 32 512 ; do
  d=`expr $r + $r`
  inkscape -w "$d" -h "$d" --export-filename="$tmp/icon_${r}x${r}@2x.png" "$in"
done
rm -f "$out"
zip --move -r "$out" "$tmp"
