%define packager       Jinming Wu, Patrick <me@patrickwu.space>
Summary: A collection of utilities for the Windows Subsystem for Linux
Name: wslu
Version: 4.1.4
Release: 1
Source: wslu-4.1.4.tar.gz
BuildArch: noarch
Requires(pre,preun): desktop-file-utils
BuildRequires: make gzip
Requires: bc psmisc
Requires(post): %{_sbindir}/update-alternatives %{_bindir}/update-desktop-database %{_bindir}/desktop-file-install
Requires(postun): %{_sbindir}/update-alternatives %{_bindir}/update-desktop-database
BuildRoot: %{_tmppath}/%{name}-%{version}-build
URL: https://github.com/wslutilities/wslu/
License: GPL-3.0-or-later

%description
This is a collection of utilities for Windows 10 Linux Subsystem, such as converting WSL path to Windows path or creating your favorite linux app shortcuts on Windows 10 Desktop. Requires Windows 10 Creators Update and higher.

%prep
%setup -q

%build
make

%install
# for os <= 7
mkdir -p %{?buildroot}/usr/share/man/man1/
mkdir -p %{?buildroot}/usr/share/man/man7/
mkdir -p %{?buildroot}/usr/share/applications/
mkdir -p %{?buildroot}/usr/share/wslu/
mkdir -p %{?buildroot}/usr/bin/
mkdir -p %{?buildroot}/etc/wslu/
# normal part
make PREFIX=/usr DESTDIR=%{?buildroot} install
ln -sf /usr/bin/wslview %{?buildroot}/usr/bin/wview
ln -sf /usr/bin/wslview %{?buildroot}/usr/bin/wslstart
ln -sf /usr/bin/wslview %{?buildroot}/usr/bin/wstart
ln -sf /usr/share/man/man1/wslview.1.gz %{?buildroot}/usr/share/man/man1/wview.1.gz
ln -sf /usr/share/man/man1/wslview.1.gz %{?buildroot}/usr/share/man/man1/wslstart.1.gz
ln -sf /usr/share/man/man1/wslview.1.gz %{?buildroot}/usr/share/man/man1/wstart.1.gz

%post
%{_sbindir}/update-alternatives --install %{_bindir}/www-browser www-browser %{_bindir}/wslview 1
%{_sbindir}/update-alternatives --install %{_bindir}/x-www-browser x-www-browser %{_bindir}/wslview 1
date +"%s" | tee /usr/share/wslu/updated_time >/dev/null
desktop-file-install --dir=/usr/share/applications /usr/share/wslu/wslview.desktop
update-desktop-database

%postun
if [ -f /usr/share/wslu/updated_time ]; then
    rm /usr/share/wslu/updated_time
fi
if [ -f /usr/share/applications/wslview.desktop ]; then
    rm /usr/share/applications/wslview.desktop
    update-desktop-database
fi
%{_sbindir}/update-alternatives --remove www-browser %{_bindir}/wslview
%{_sbindir}/update-alternatives --remove x-www-browser %{_bindir}/wslview

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%{_bindir}/wslusc
%{_bindir}/wslfetch
%{_bindir}/wslsys
%{_bindir}/wslupath
%{_bindir}/wslview
%{_bindir}/wview
%{_bindir}/wstart
%{_bindir}/wslstart
%{_bindir}/wslact
%{_bindir}/wslvar
%{_bindir}/wslgsu
%{_bindir}/wslclip
/usr/share/wslu/
/usr/share/applications/
/etc/wslu
%doc /usr/share/man/

%changelog
* Sun Nov 17 2024 Jinming Wu, Patrick <me@patrickwu.space> - 4.1.4-1
- Please check https://github.com/wslutilities/wslu/releases/latest for changelog