File v2ray-core.spec of Package v2ray-core

#
# spec file for package v2ray-core
#
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# disable fedora debug packages, use explicit glibc-langpack follow openSUSE:Tools/obs-service-tar_scm
%if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version}
%global debug_package %{nil}
%define locale_package glibc-langpack-en
%endif

%define   provider        github
%define   provider_tld    com
%define   project         v2ray
%define   repo            v2ray-core
# https://github.com/shadowsocks/v2ray-plugin
%define   provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo}
%define   import_path     github.com/v2fly/v2ray-core/v4
%define   config_path     release/config

Name:           v2ray-core
Version:        4.44.0
Release:        0
Summary:        A platform for building proxies to bypass network restrictions
License:        MIT
Group:          Productivity/Networking/Web/Proxy
URL:            https://github.com/v2fly/v2ray-core
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        v2ray.service
Source3:        geoip.dat
Source4:        geosite.dat
Source5:        v2ray@.service
Source6:        https://github.com/v2fly/v2ray-core/releases/download/v%{version}/v2ray-extra.zip
Source99:       %{name}-rpmlintrc
BuildRequires:  fdupes
# This package (v4.37.3+) can not be built with go version < 1.16
BuildRequires:  golang(API) = 1.16
%if 0%{?fedora_version}
BuildRequires:  %{locale_package}
%endif
BuildRequires:  systemd-rpm-macros
BuildRequires:  unzip
BuildRequires:  pkgconfig(systemd)
AutoReqProv:    Off
Provides:       %{project} = %{version}-%{release}
Obsoletes:      %{project} < %{version}-%{release}
Conflicts:      v2ray
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%{?systemd_ordering}

%description
Project V is a set of network tools that help you to build your own computer
network. It secures your network connections and thus protects your privacy. See
our website for more information.

%prep
%setup -q -a 1 -a 6 -n %{repo}-%{version}

%build
go build -mod vendor -buildmode pie -ldflags="-s -w" -o v2ray %{import_path}/main
go build -mod vendor -buildmode pie -ldflags="-s -w" -o v2ctl %{import_path}/infra/control/main

%install
install -d %{buildroot}%{_bindir}
install -m0755 v2ray %{buildroot}%{_bindir}/
install -m0755 v2ctl %{buildroot}%{_bindir}/

install -d %{buildroot}%{_unitdir}/v2ray
install -m0644 %{S:2} %{buildroot}%{_unitdir}/
install -m0644 %{S:5} %{buildroot}%{_unitdir}/

install -d %{buildroot}%{_sysconfdir}/v2ray
install -m0644 %{config_path}/config.json %{buildroot}%{_sysconfdir}/v2ray/
install -m0644 %{config_path}/vpoint_socks_vmess.json %{buildroot}%{_sysconfdir}/v2ray/
install -m0644 %{config_path}/vpoint_vmess_freedom.json %{buildroot}%{_sysconfdir}/v2ray/

install -d %{buildroot}%{_sbindir}
ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rcv2ray

install -d %{buildroot}%{_datadir}/v2ray
install -m0644 %{S:3} %{buildroot}%{_datadir}/v2ray/
install -m0644 %{S:4} %{buildroot}%{_datadir}/v2ray/

install -d %{buildroot}%{_datadir}/v2ray/browserforwarder
install -m0644 browserforwarder/index.js %{buildroot}%{_datadir}/v2ray/browserforwarder/
install -m0644 browserforwarder/index.html %{buildroot}%{_datadir}/v2ray/browserforwarder/


%fdupes %{buildroot}

%pre
%if 0%{?suse_version}
%service_add_pre %{project}.service %{project}@.service
## No need for Fedora/CentOS
%endif

%post
%if 0%{?suse_version}
%service_add_post %{project}.service %{project}@.service
%else
%systemd_post %{project}.service %{project}@.service
%endif

%preun
%if 0%{?suse_version}
%service_del_preun %{project}.service %{project}@.service
%else
%systemd_preun %{project}.service %{project}@.service
%endif

%postun
%if 0%{?suse_version}
%service_del_postun %{project}.service %{project}@.service
%else
%systemd_postun_with_restart %{project}.service %{project}@.service
%endif

%files
%defattr(-,root,root)
%doc README.md
%license LICENSE
%{_bindir}/v2ray
%{_bindir}/v2ctl
%{_unitdir}/v2ray.service
%{_unitdir}/v2ray@.service
%dir %{_sysconfdir}/v2ray
%config(noreplace) %{_sysconfdir}/v2ray/*.json
%{_sbindir}/rcv2ray
%dir %{_datadir}/v2ray
%{_datadir}/v2ray/geoip.dat
%{_datadir}/v2ray/geosite.dat
%{_datadir}/v2ray/browserforwarder/

%changelog
openSUSE Build Service is sponsored by