%global debug_package %{nil}
%define import_path github.com/restic/restic

Name:           restic
Version:        0.16.2
Release:        2
Summary:        Backup program with deduplication and encryption
License:        BSD-2-Clause
Group:          Productivity/Archiving/Backup
URL:            https://restic.net
Source0:        https://github.com/restic/restic/releases/download/v%{version}/%{name}-%{version}.tar.gz
Source1:        https://github.com/restic/restic/releases/download/v%{version}/%{name}-%{version}.tar.gz.asc
Source2:        %{name}.keyring
Source3:        vendor.tar.xz
BuildRequires:  bash-completion
BuildRequires:  zsh
BuildRequires:  golang >= 1.18

Patch0001:	0001-restic-uos-add-sw_64-and-mips64el.patch

%description
restic is a backup program. It supports verification, encryption,
snapshots and deduplication.

%package bash-completion
Summary:        Bash Completion for %{name}
Group:          System/Shells
Requires:       %{name} = %{version}
Supplements:    packageand(restic:bash-completion)
BuildArch:      noarch

%description bash-completion
Bash command line completion support for %{name}.

%package zsh-completion
Summary:        Zsh Completion for %{name}
Group:          System/Shells
Requires:       %{name} = %{version}
Supplements:    packageand(restic:zsh)
BuildArch:      noarch

%description zsh-completion
Zsh command line completion support for %{name}.

%prep
%setup -q -a 3
%ifarch sw_64 mips64el
%patch1	-p1
%endif

%build
# Set up GOPATH.
export GOPATH="$GOPATH:$HOME/go"
mkdir -p $HOME/go/src/%{import_path}
cp -rT $PWD $HOME/go/src/%{import_path}

# Build restic. We don't use build.go because it builds statically, uses go
# modules, and also restricts the Go version in cases where it's not actually
# necessary. We disable go modules because restic still provides a vendor/.
%ifarch sw_64 mips64el
GO111MODULE=off go build -o %{name} -buildmode=exe \
	-ldflags "-s -w -X main.version=%{version}" \
	%{import_path}/cmd/restic
%else
GO111MODULE=off go build -o %{name} -buildmode=pie \
	-ldflags "-s -w -X main.version=%{version}" \
	%{import_path}/cmd/restic
%endif

%install
install -D -m0755 %{name} %{buildroot}%{_bindir}/%{name}
install -d %{buildroot}%{_mandir}/man1
./%{name} generate --man %{buildroot}%{_mandir}/man1
install -Dm0644 doc/bash-completion.sh %{buildroot}%{_datadir}/bash-completion/completions/%{name}
install -Dm0644 doc/zsh-completion.zsh %{buildroot}%{_sysconfdir}/zsh_completion.d/%{name}

%files
%defattr(-,root,root)
%doc *.md
%doc doc/
%license LICENSE
%{_bindir}/restic
%{_mandir}/man1/restic*.1*

%files bash-completion
%{_datadir}/bash-completion/completions/%{name}

%files zsh-completion
%config %{_sysconfdir}/zsh_completion.d/%{name}

%changelog
* Fri Feb 28 2025 zhangshaoning <zhangshaoning@uniontech.com> - 0.16.2-2
- Add sw_64 and mips64el support

* Wed Jan 03 2024 Paul Thomas <paulthomas100199@gmail.com> 0.16.2-1
- update to version 0.16.2

* Mon Sep 06 2021 yinzehao <yinzehao@uniontech.com> - 0.12.1-1
- Package init

