%define _disable_source_fetch 0
%define _proj_name WhiteSur-icon-theme

%define base_ver %(curl -A "request" -fsSL "https://api.github.com/repos/vinceliuice/WhiteSur-icon-theme/tags" | jq -r '.[0].name' | sed 's/-//g')
%define git_refspec %(curl -A "request" -fsSL "https://api.github.com/repos/vinceliuice/WhiteSur-icon-theme/commits" | jq -r '.[0].sha')
%define git_refspec_short %(echo %{git_refspec} | cut -c -7)
%define build_timestamp %(date +%s)

Name: whitesur-icon-theme
Version: %{base_ver}git.%{build_timestamp}.%{git_refspec_short}
Release: 0%{?dist}
Summary: MacOS Big Sur style icon theme for linux desktops
 
License: GPLv3 and Fedora Trademark Guidelines
URL: https://github.com/vinceliuice/%{_proj_name}
Source0: %{url}/tarball/%{git_refspec}#/%{name}-%{git_refspec}.tar.gz
Source1: https://cdn.discordapp.com/attachments/873096743741452318/877520229259968532/distributor-logo-fedora-flat.svg
BuildArch: noarch
BuildRequires: make gtk-update-icon-cache
Requires: gtk-update-icon-cache

%description
MacOS Big Sur like icon theme for linux desktops

%prep
%setup -qn vinceliuice-%{_proj_name}-%{git_refspec_short}
chmod +x ./install.sh

%install
mkdir -p %{buildroot}/%{_datadir}/icons
./install.sh -d %{buildroot}/%{_datadir}/icons -a
find %{buildroot} -name 'icon-theme.cache' -type f | xargs rm -fv

export THEMES="WhiteSur WhiteSur-dark"
for t in $THEMES; do
    mkdir -p %{buildroot}%{_datadir}/icons/$t
    /bin/touch %{buildroot}%{_datadir}/icons/$t/icon-theme.cache
done

mkdir -p %{buildroot}/%{_datadir}/icons/WhiteSur/apps/scalable/
cp -v %{SOURCE1} %{buildroot}/%{_datadir}/icons/WhiteSur/apps/scalable/distributor-logo-fedora.svg
mkdir -p %{buildroot}/%{_datadir}/icons/WhiteSur-dark/apps/scalable/
cp -v %{SOURCE1} %{buildroot}/%{_datadir}/icons/WhiteSur-dark/apps/scalable/distributor-logo-fedora.svg

%post
export THEMES="WhiteSur WhiteSur-dark"
for t in $THEMES; do
    /bin/touch --no-create %{_datadir}/icons/$t &>/dev/null || :
done

pushd %{_datadir}/icons/WhiteSur
ln -nvfs apps/scalable/distributor-logo-fedora.svg launcher-icon.svg
sha512sum launcher-icon.svg > whitesur-icon-theme-fedora.SHA512_CHECKSUM
popd

pushd %{_datadir}/icons/WhiteSur-dark
ln -nvfs apps/scalable/distributor-logo-fedora.svg launcher-icon.svg
sha512sum launcher-icon.svg > whitesur-icon-theme-fedora.SHA512_CHECKSUM
popd

%postun
export THEMES="WhiteSur WhiteSur-dark"
for t in $THEMES; do
    if [ $1 -eq 0 ] ; then
        /bin/touch --no-create %{_datadir}/icons/$t &>/dev/null
        /usr/bin/gtk-update-icon-cache %{_datadir}/icons/$t &>/dev/null || :
    fi
done

pushd %{_datadir}/icons/WhiteSur
sha512sum -c whitesur-icon-theme-fedora.SHA512_CHECKSUM
if [ ${?} == 0 ]; then
  rm -v launcher-icon.svg
fi
popd

pushd %{_datadir}/icons/WhiteSur-dark
sha512sum -c whitesur-icon-theme-fedora.SHA512_CHECKSUM
if [ ${?} == 0 ]; then
  rm -v launcher-icon.svg
fi
popd

%posttrans
export THEMES="WhiteSur WhiteSur-dark"
for t in $THEMES; do
    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/$t &>/dev/null || :
done

%files
%{_datadir}/icons/WhiteSur
%{_datadir}/icons/WhiteSur-dark
%ghost %{_datadir}/icons/WhiteSur/icon-theme.cache
%ghost %{_datadir}/icons/WhiteSur-dark/icon-theme.cache