%global debug_package %{nil} %global provider github %global provider_tld com %global project globalcheck %global repo agent # https://github.com/globalcheck/agent %global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo} %global import_path %{provider_prefix} %global commit 39185139d7499a32c7c9a6e87043fca83f50e816 %global shortcommit %(c=%{commit}; echo ${c:0:7}) %if 0%{?fedora} >= 15 || 0%{?rhel} >= 7 %define use_systemd 1 %else %define use_systemd 0 %endif Name: golang-%{provider}-%{project}-%{repo} Version: 0.3.7 Release: 1.git%{shortcommit}%{?dist} License: GPLv2+ Summary: GlobalCheck agent URL: https://%{provider_prefix} Source0: https://%{provider_prefix}/archive/%{commit}/%{repo}-%{shortcommit}.tar.gz Source1: gcagent.service Source2: gcagent.init # e.g. el6 has ppc64 arch without gcc-go, so EA tag is required ExclusiveArch: %{?go_arches:%{go_arches}}%{!?go_arches:%{ix86} x86_64 aarch64 %{arm}} # If go_compiler is not set to 1, there is no virtual provide. Use golang instead. BuildRequires: %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang} %if %{use_systemd} BuildRequires: systemd Requires(post): systemd Requires(preun): systemd Requires(postun): systemd %else Requires(post): chkconfig Requires(preun): chkconfig, initscripts %endif %description %{summary} %prep %setup -q -n %{repo}-%{commit} %build # set up temporary build gopath, and put our directory there mkdir -p ./_build/src/github.com/globalcheck ln -s $(pwd) ./_build/src/github.com/globalcheck/gcagent export GOPATH=$(pwd)/_build:%{gopath} # https://github.com/golang/go/issues/28550 export GOPROXY=https://proxy.golang.org export LDFLAGS="-X main.version=%{version}" %if ! 0%{?gobuild:1} %define gobuild(o:) go build -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n')" -a -v -x %{?**}; %endif %gobuild -o gcagent . %install install -d %{buildroot}%{_bindir} install -d %{buildroot}%{_sysconfdir} install -m 0755 ./gcagent %{buildroot}%{_bindir}/gcagent install -m 0644 ./agent.toml %{buildroot}%{_sysconfdir}/gcagent.toml %if %{use_systemd} install -d %{buildroot}%{_unitdir} install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/gcagent.service %else install -d %{buildroot}%{_initddir} install -m 0755 %{SOURCE2} %{buildroot}%{_initddir}/gcagent install -m 0755 -d %{buildroot}%{_localstatedir}/log/gcagent %endif %post %if %{use_systemd} %systemd_post gcagent.service %else if [ $1 -eq 1 ] then /sbin/chkconfig --add gcagent fi %endif %preun %if %{use_systemd} %systemd_preun gcagent.service %else if [ $1 -eq 0 ] then /sbin/service gcagent stop >/dev/null 2>&1 /sbin/chkconfig --del gcagent fi %endif %postun %if %{use_systemd} %systemd_postun gcagent.service %endif %files %defattr(-,root,root,-) %doc README.md %{_bindir}/gcagent %{_sysconfdir}/gcagent.toml %if %{use_systemd} %{_unitdir}/gcagent.service %else %{_initddir}/gcagent %dir %{_localstatedir}/log/gcagent %endif