#!/bin/sh
set -e

write_cache()
{
if [ -x "$(command -v gtk-update-icon-cache)" ]; then
  for i in Papirus Papirus-Dark Papirus-Light; do
    if ! gtk-update-icon-cache --force --quiet "/usr/share/icons/${i}"; then
      echo "WARNING: icon cache generation failed: /usr/share/icons/${i}"
    fi
  done
fi
}

if [ "$1" = "triggered" ]; then
  write_cache
  exit 0
fi

# We anyway remove ePapirus-related icon-theme.cache in new package's postinst,
# due to the removal of ePapirus icon theme since 20250501-1.
if [ "$1" = "configure" ] ; then
  for i in ePapirus ePapirus-Dark; do
    rm -f "/usr/share/icons/${i}/icon-theme.cache"
  done
fi

write_cache

#DEBHELPER#
