#!/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

# Automatically added by dh_icons/13.24.2
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if command -v update-icon-caches >/dev/null; then
		update-icon-caches /usr/share/icons/Papirus /usr/share/icons/Papirus-Dark /usr/share/icons/Papirus-Light
	fi
fi
# End automatically added section

