#!/bin/sh -e

chmod a+x /opt/wagic/wagic
chmod a+x /opt/wagic/launcher
chmod -R a+rw /home/user/wagic
if grep -q /home/user/MyDocs /proc/mounts; then
# FAT partition mounted
  mkdir -p /home/user/MyDocs/wagic
  mkdir -p /home/user/MyDocs/wagic/Res
# Size needed on the FAT partition
  dirSize=`du -s /home/user/wagic/Res | awk '{print $1}'`
# Size available on the FAT partition
  avaSize=`df | grep /dev/mmcblk0p1 | awk '{print $4}'`
  if [ /home/user/wagic/Res/sets/primitives/mtg.txt -nt /home/user/MyDocs/wagic/Res/sets/primitives/mtg.txt ];
    then if [ $avaSize -gt $dirSize ]
    then
      echo "Copying resources on the FAT partition to ease customization"
      cp -rf /home/user/wagic/Res/* /home/user/MyDocs/wagic/Res
    fi
  fi
fi

gtk-update-icon-cache -f /usr/share/icons/hicolor

exit 0
