#!/bin/sh
# preinst script for papirus-icon-theme
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#   * <new-preinst> `install'
#   * <new-preinst> `install' <old-version>
#   * <new-preinst> `upgrade' <old-version>
#   * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
	install|upgrade)
		true
		;;
	abort-upgrade)
		exit 0
		;;
	*)
		echo "preinst called with unknown argument \`$1'" >&2
		exit 1
		;;
esac

rm_dir() {
	test -d "$1" || return 0  # is a dir
	test -L "$1" && return 0  # is not a symlink
	echo "Removing directory '$1'..." >&2
	rm -rf "$1"
}

rm_file() {
	test -f "$1" || return 0  # is a file
	echo "Removing file '$1'..." >&2
	rm -f "$1"
}

rm_symlink() {
	test -L "$1" || return 0  # is a symlink
	echo "Removing symlink '$1'..." >&2
	rm -f "$1"
}

PREV_VERSION="$2"

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@20bfc4a
# https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/issues/370
if dpkg --compare-versions "$PREV_VERSION" lt "20170304"; then
	rm_dir /usr/share/icons/Papirus-Dark/22x22/animations
	rm_symlink /usr/share/icons/ePapirus/22x22/animations
	rm_symlink /usr/share/icons/Papirus-Light/22x22/animations
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@e58810d
# https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/issues/720
if dpkg --compare-versions "$PREV_VERSION" lt "20170909"; then
	rm_dir /usr/share/icons/Papirus-Dark/22x22/panel
	rm_dir /usr/share/icons/Papirus-Dark/24x24/panel
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@6fa37d3
if dpkg --compare-versions "$PREV_VERSION" lt "20170920"; then
	rm_dir /usr/share/icons/Papirus-Adapta/22x22/animations
	rm_dir /usr/share/icons/Papirus-Adapta/24x24/animations
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@8a48d2a
if dpkg --compare-versions "$PREV_VERSION" lt "20171002"; then
	rm_symlink /usr/share/icons/Papirus-Light/16x16
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@236b015
if dpkg --compare-versions "$PREV_VERSION" lt "20171004"; then
	rm_symlink /usr/share/icons/Papirus-Light/16x16/actions
	rm_symlink /usr/share/icons/Papirus-Light/16x16/devices
	rm_symlink /usr/share/icons/Papirus-Light/16x16/extra
	rm_symlink /usr/share/icons/Papirus-Light/16x16/places
	rm_symlink /usr/share/icons/Papirus-Light/22x22/actions
	rm_symlink /usr/share/icons/Papirus-Light/24x24/actions
fi

# Broken commit: PapirusDevelopmentTeam/papirus-icon-theme@05bdd26f6
# https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/issues/1462
if dpkg --compare-versions "$PREV_VERSION" lt "20180909"; then
	rm_file "/usr/share/icons/Papirus-Adapta/16x16/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus-Adapta/22x22/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus-Adapta/24x24/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus-Light/16x16/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus-Light/22x22/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus-Light/24x24/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus/16x16/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus/22x22/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/Papirus/24x24/panel/network-cellular-connected .svg"
	rm_file "/usr/share/icons/ePapirus/24x24/panel/network-cellular-connected .svg"
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@5780dfbeac
if dpkg --compare-versions "$PREV_VERSION" lt "20181015"; then
	rm_dir /usr/share/icons/Papirus-Light/16x16/actions
	rm_dir /usr/share/icons/Papirus-Light/16x16/devices
	rm_dir /usr/share/icons/Papirus-Light/16x16/places
	rm_dir /usr/share/icons/Papirus-Light/22x22/actions
	rm_dir /usr/share/icons/Papirus-Light/24x24/actions
fi

# Breaking changes: PapirusDevelopmentTeam/papirus-icon-theme@635c7bc
# Remove ePapirus and ePapirus-Dark to avoid create icon-theme.cache
# files.
# https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/issues/3574
if dpkg --compare-versions "$PREV_VERSION" lt "20231025"; then
	rm_dir /usr/share/icons/ePapirus
	rm_dir /usr/share/icons/ePapirus-Dark
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
