Skip to content

Commit e3724ac

Browse files
authored
Merge pull request crowdsecurity#15 from sbs2001/rpm
Add spec file for rpm
2 parents d853f24 + cfaf9bc commit e3724ac

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Name: crowdsec-custom-bouncer
2+
Version: %(echo $VERSION)
3+
Release: %(echo $PACKAGE_NUMBER)%{?dist}
4+
Summary: Custom bouncer for Crowdsec
5+
6+
License: MIT
7+
URL: https://crowdsec.net
8+
Source: cs-custom-bouncer-%(echo $VERSION).tar.gz
9+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
10+
11+
BuildRequires: git
12+
BuildRequires: golang >= 1.14
13+
BuildRequires: make
14+
%{?fc33:BuildRequires: systemd-rpm-macros}
15+
16+
%define debug_package %{nil}
17+
18+
%description
19+
20+
%define version_number %(echo $VERSION)
21+
%define releasever %(echo $RELEASEVER)
22+
%global local_version v%{version_number}-%{releasever}-rpm
23+
%global name crowdsec-custom-bouncer
24+
%global __mangle_shebangs_exclude_from /usr/bin/env
25+
26+
%prep
27+
%setup -n cs-custom-bouncer-%{version}
28+
29+
%build
30+
BUILD_VERSION=%{local_version} make
31+
TMP=`mktemp -p /tmp/`
32+
cp config/%{name}.service ${TMP}
33+
BIN=%{_bindir}/%{name} CFG=/etc/crowdsec/ envsubst < ${TMP} > config/%{name}.service
34+
rm ${TMP}
35+
36+
%install
37+
rm -rf %{buildroot}
38+
mkdir -p %{buildroot}/usr/sbin
39+
install -m 755 -D %{name} %{buildroot}%{_bindir}/%{name}
40+
install -m 600 -D config/%{name}.yaml %{buildroot}/etc/crowdsec/%{name}/%{name}.yaml
41+
install -m 644 -D config/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
42+
43+
%clean
44+
rm -rf %{buildroot}
45+
46+
%files
47+
%defattr(-,root,root,-)
48+
/usr/bin/%{name}
49+
%{_unitdir}/%{name}.service
50+
%config /etc/crowdsec/%{name}/%{name}.yaml
51+
52+
53+
%post
54+
systemctl daemon-reload
55+
56+
57+
START=0
58+
59+
systemctl is-active --quiet crowdsec
60+
61+
if [ "$?" -eq "0" ] ; then
62+
START=1
63+
echo "cscli/crowdsec is present, generating API key"
64+
unique=`date +%s`
65+
API_KEY=`sudo cscli -oraw bouncers add CustomBouncer-${unique}`
66+
if [ $? -eq 1 ] ; then
67+
echo "failed to create API token, service won't be started."
68+
START=0
69+
API_KEY="<API_KEY>"
70+
else
71+
echo "API Key : ${API_KEY}"
72+
fi
73+
fi
74+
75+
TMP=`mktemp -p /tmp/`
76+
cp /etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml ${TMP}
77+
API_KEY=${API_KEY} envsubst < ${TMP} > /etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml
78+
rm ${TMP}
79+
80+
if [ ${START} -eq 0 ] ; then
81+
echo "no api key was generated, won't start service"
82+
fi
83+
84+
echo "please enter the binary path in '/etc/crowdsec/crowdsec-custom-bouncer/crowdsec-custom-bouncer.yaml' and start the bouncer via 'sudo systemctl start crowdsec-custom-bouncer' "
85+
86+
87+
88+
%changelog
89+
* Wed Jun 30 2021 Shivam Sandbhor <[email protected]>
90+
- First initial packaging
91+
92+
%preun
93+
systemctl stop crowdsec-custom-bouncer || echo "cannot stop service"
94+
systemctl disable crowdsec-custom-bouncer || echo "cannot disable service"

0 commit comments

Comments
 (0)