%global themename tela
%global upname Tela
%global filename %{themename}-icon-theme
%global gitdate 20230608
%global gitrev 45f1bf7f
%global gitcommit %{gitdate}git%{gitrev}

Name:           %{themename}-icon-theme
Version:        0
Release:        1%{?gitcommit:.%{gitcommit}}%{?dist}
Summary:        A flat, colorful icon theme 
License:        GPLv3
URL:            https://github.com/vinceliuice/Tela-icon-theme 
Source0:        %{filename}-%{version}%{?gitcommit:-%{gitcommit}}.tar.xz
Requires:       hicolor-icon-theme, adwaita-icon-theme, breeze-icon-theme
Requires(posttrans,postun): gtk-update-icon-cache
BuildArch:      noarch

%description
A flat, colorful icon theme


%package -n %{themename}-dark-icon-theme
Summary:        A flat, colorful icon theme 
Requires:       hicolor-icon-theme, adwaita-icon-theme, breeze-icon-theme
Requires:       %{name} = %{version}-%{release}
Requires(posttrans,postun): gtk-update-icon-cache

%description -n %{themename}-dark-icon-theme
A flat, colorful icon theme


%prep
%autosetup -n %{upname}-icon-theme


%build
## disable gtk-update-icon-cache from the install script
sed -i 's/^\(\s*\)gtk-update-icon-cache/##\1gtk-update-icon-cache/' install.sh


%install
install -m 755 -d $RPM_BUILD_ROOT%{_datadir}/icons
./install.sh -d $RPM_BUILD_ROOT%{_datadir}/icons


%post
touch --no-create %{_datadir}/icons/%{upname} &> /dev/null || :

%post -n %{themename}-dark-icon-theme
touch --no-create %{_datadir}/icons/%{upname}-dark &> /dev/null || :


%posttrans
gtk-update-icon-cache %{_datadir}/icons/%{upname} &> /dev/null || :

%posttrans -n %{themename}-dark-icon-theme
gtk-update-icon-cache %{_datadir}/icons/%{upname}-dark &> /dev/null || :


%postun
if [ $1 -eq 0 ] ; then
  touch --no-create %{_datadir}/icons/%{upname} &> /dev/null || :
  gtk-update-icon-cache %{_datadir}/icons/%{upname} &> /dev/null || :
fi

%postun -n %{themename}-dark-icon-theme
if [ $1 -eq 0 ] ; then
  touch --no-create %{_datadir}/icons/%{upname}-dark &> /dev/null || :
  gtk-update-icon-cache %{_datadir}/icons/%{upname}-dark &> /dev/null || :
fi


%files
%license COPYING
%doc AUTHORS README.md
%{_datadir}/icons/%{upname}

%files -n %{themename}-dark-icon-theme
%license COPYING
%doc AUTHORS README.md
%{_datadir}/icons/%{upname}-dark


%changelog
* Fri Jun 09 2023 Andrea Santilli - 0-1.20230608git45f1bf7f
- Initial RPM release.