github.com/crowdsecurity/crowdsec@v1.6.1/rpm/SPECS/crowdsec.spec (about) 1 2 Name: crowdsec 3 Version: %(echo $VERSION) 4 Release: %(echo $PACKAGE_NUMBER)%{?dist} 5 Summary: Crowdsec - An open-source, lightweight agent to detect and respond to bad behaviors. It also automatically benefits from our global community-wide IP reputation database 6 7 License: MIT 8 URL: https://crowdsec.net 9 Source0: https://github.com/crowdsecurity/%{name}/archive/v%(echo $VERSION).tar.gz 10 Source1: 80-%{name}.preset 11 Patch0: user.patch 12 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) 13 14 BuildRequires: systemd 15 Requires: crontabs 16 %{?fc33:BuildRequires: systemd-rpm-macros} 17 %{?fc34:BuildRequires: systemd-rpm-macros} 18 %{?fc35:BuildRequires: systemd-rpm-macros} 19 %{?fc36:BuildRequires: systemd-rpm-macros} 20 21 %define debug_package %{nil} 22 23 %description 24 25 %define version_number %(echo $VERSION) 26 %define releasever %(echo $RELEASEVER) 27 %global name crowdsec 28 %global __mangle_shebangs_exclude_from /usr/bin/env 29 30 %prep 31 %setup -q -T -b 0 32 33 %patch0 34 35 %build 36 sed -i "s#/usr/local/lib/crowdsec/plugins/#%{_libdir}/%{name}/plugins/#g" config/config.yaml 37 38 %install 39 rm -rf %{buildroot} 40 mkdir -p %{buildroot}/etc/crowdsec/hub 41 mkdir -p %{buildroot}/etc/crowdsec/patterns 42 mkdir -p %{buildroot}/etc/crowdsec/console/ 43 mkdir -p %{buildroot}%{_sharedstatedir}/%{name}/data 44 mkdir -p %{buildroot}%{_presetdir} 45 46 mkdir -p %{buildroot}%{_sharedstatedir}/%{name}/plugins 47 mkdir -p %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 48 mkdir -p %{buildroot}%{_libdir}/%{name}/plugins/ 49 50 51 install -m 755 -D cmd/crowdsec/crowdsec %{buildroot}%{_bindir}/%{name} 52 install -m 755 -D cmd/crowdsec-cli/cscli %{buildroot}%{_bindir}/cscli 53 install -m 755 -D wizard.sh %{buildroot}/usr/share/crowdsec/wizard.sh 54 install -m 644 -D debian/crowdsec.service %{buildroot}%{_unitdir}/%{name}.service 55 install -m 644 -D config/patterns/* -t %{buildroot}%{_sysconfdir}/crowdsec/patterns 56 install -m 600 -D config/config.yaml %{buildroot}%{_sysconfdir}/crowdsec 57 install -m 644 -D config/simulation.yaml %{buildroot}%{_sysconfdir}/crowdsec 58 install -m 644 -D config/profiles.yaml %{buildroot}%{_sysconfdir}/crowdsec 59 install -m 644 -D config/console.yaml %{buildroot}%{_sysconfdir}/crowdsec 60 install -m 644 -D config/context.yaml %{buildroot}%{_sysconfdir}/crowdsec/console/ 61 install -m 750 -D config/%{name}.cron.daily %{buildroot}%{_sysconfdir}/cron.daily/%{name} 62 install -m 644 -D %{SOURCE1} %{buildroot}%{_presetdir} 63 64 install -m 551 cmd/notification-slack/notification-slack %{buildroot}%{_libdir}/%{name}/plugins/ 65 install -m 551 cmd/notification-http/notification-http %{buildroot}%{_libdir}/%{name}/plugins/ 66 install -m 551 cmd/notification-splunk/notification-splunk %{buildroot}%{_libdir}/%{name}/plugins/ 67 install -m 551 cmd/notification-email/notification-email %{buildroot}%{_libdir}/%{name}/plugins/ 68 install -m 551 cmd/notification-sentinel/notification-sentinel %{buildroot}%{_libdir}/%{name}/plugins/ 69 70 install -m 600 cmd/notification-slack/slack.yaml %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 71 install -m 600 cmd/notification-http/http.yaml %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 72 install -m 600 cmd/notification-splunk/splunk.yaml %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 73 install -m 600 cmd/notification-email/email.yaml %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 74 install -m 600 cmd/notification-sentinel/sentinel.yaml %{buildroot}%{_sysconfdir}/crowdsec/notifications/ 75 76 77 %clean 78 rm -rf %{buildroot} 79 80 %files 81 %defattr(-,root,root,-) 82 %{_bindir}/%{name} 83 %{_bindir}/cscli 84 %{_datadir}/%{name}/wizard.sh 85 %{_libdir}/%{name}/plugins/notification-slack 86 %{_libdir}/%{name}/plugins/notification-http 87 %{_libdir}/%{name}/plugins/notification-splunk 88 %{_libdir}/%{name}/plugins/notification-email 89 %{_libdir}/%{name}/plugins/notification-sentinel 90 %{_sysconfdir}/%{name}/patterns/linux-syslog 91 %{_sysconfdir}/%{name}/patterns/ruby 92 %{_sysconfdir}/%{name}/patterns/nginx 93 %{_sysconfdir}/%{name}/patterns/junos 94 %{_sysconfdir}/%{name}/patterns/cowrie_honeypot 95 %{_sysconfdir}/%{name}/patterns/redis 96 %{_sysconfdir}/%{name}/patterns/firewalls 97 %{_sysconfdir}/%{name}/patterns/paths 98 %{_sysconfdir}/%{name}/patterns/java 99 %{_sysconfdir}/%{name}/patterns/postgresql 100 %{_sysconfdir}/%{name}/patterns/bacula 101 %{_sysconfdir}/%{name}/patterns/mcollective 102 %{_sysconfdir}/%{name}/patterns/rails 103 %{_sysconfdir}/%{name}/patterns/haproxy 104 %{_sysconfdir}/%{name}/patterns/nagios 105 %{_sysconfdir}/%{name}/patterns/mysql 106 %{_sysconfdir}/%{name}/patterns/ssh 107 %{_sysconfdir}/%{name}/patterns/tcpdump 108 %{_sysconfdir}/%{name}/patterns/exim 109 %{_sysconfdir}/%{name}/patterns/bro 110 %{_sysconfdir}/%{name}/patterns/modsecurity 111 %{_sysconfdir}/%{name}/patterns/aws 112 %{_sysconfdir}/%{name}/patterns/smb 113 %{_sysconfdir}/%{name}/patterns/mongodb 114 %config(noreplace) %{_sysconfdir}/%{name}/config.yaml 115 %config(noreplace) %{_sysconfdir}/%{name}/simulation.yaml 116 %config(noreplace) %{_sysconfdir}/%{name}/profiles.yaml 117 %config(noreplace) %{_sysconfdir}/%{name}/console.yaml 118 %config(noreplace) %{_sysconfdir}/%{name}/console/context.yaml 119 %config(noreplace) %{_presetdir}/80-%{name}.preset 120 %config(noreplace) %{_sysconfdir}/%{name}/notifications/http.yaml 121 %config(noreplace) %{_sysconfdir}/%{name}/notifications/slack.yaml 122 %config(noreplace) %{_sysconfdir}/%{name}/notifications/splunk.yaml 123 %config(noreplace) %{_sysconfdir}/%{name}/notifications/email.yaml 124 %config(noreplace) %{_sysconfdir}/%{name}/notifications/sentinel.yaml 125 %config(noreplace) %{_sysconfdir}/cron.daily/%{name} 126 127 %{_unitdir}/%{name}.service 128 129 %ghost %{_sysconfdir}/%{name}/hub/.index.json 130 %ghost %{_localstatedir}/log/%{name}.log 131 %dir /var/lib/%{name}/data/ 132 %dir %{_sysconfdir}/%{name}/hub 133 134 %ghost %{_sysconfdir}/crowdsec/local_api_credentials.yaml 135 %ghost %{_sysconfdir}/crowdsec/online_api_credentials.yaml 136 %ghost %{_sysconfdir}/crowdsec/acquis.yaml 137 138 %pre 139 140 #systemctl stop crowdsec || true 141 142 if [ $1 == 2 ];then 143 if [[ ! -d /var/lib/crowdsec/backup ]]; then 144 cscli config backup /var/lib/crowdsec/backup 145 fi 146 fi 147 148 149 %post -p /bin/bash 150 151 #install 152 if [ $1 == 1 ]; then 153 154 if [ ! -f "/var/lib/crowdsec/data/crowdsec.db" ] ; then 155 touch /var/lib/crowdsec/data/crowdsec.db 156 fi 157 158 echo $SHELL 159 . /usr/share/crowdsec/wizard.sh -n 160 161 echo Creating acquisition configuration 162 if [ ! -f "/etc/crowsec/acquis.yaml" ] ; then 163 set +e 164 SILENT=true detect_services 165 SILENT=true TMP_ACQUIS_FILE_SKIP=skip genacquisition 166 set +e 167 fi 168 if [ ! -f "%{_sysconfdir}/crowdsec/online_api_credentials.yaml" ] ; then 169 install -m 600 /dev/null /etc/crowdsec/online_api_credentials.yaml 170 cscli capi register --error 171 fi 172 if [ ! -f "%{_sysconfdir}/crowdsec/local_api_credentials.yaml" ] ; then 173 install -m 600 /dev/null /etc/crowdsec/local_api_credentials.yaml 174 cscli machines add -a --force --error 175 fi 176 177 cscli hub update 178 CSCLI_BIN_INSTALLED="/usr/bin/cscli" SILENT=true install_collection 179 180 echo "Get started with CrowdSec:" 181 echo " * Detailed guides are available in our documentation: https://docs.crowdsec.net" 182 echo " * Configuration items created by the community can be found at the Hub: https://hub.crowdsec.net" 183 echo " * Gain insights into your use of CrowdSec with the help of the console https://app.crowdsec.net" 184 185 #upgrade 186 elif [ $1 == 2 ] && [ -d /var/lib/crowdsec/backup ]; then 187 cscli config restore /var/lib/crowdsec/backup 188 if [ $? == 0 ]; then 189 rm -rf /var/lib/crowdsec/backup 190 fi 191 192 if [[ -f %{_sysconfdir}/crowdsec/online_api_credentials.yaml ]] ; then 193 chmod 600 %{_sysconfdir}/crowdsec/online_api_credentials.yaml 194 fi 195 196 if [[ -f %{_sysconfdir}/crowdsec/local_api_credentials.yaml ]] ; then 197 chmod 600 %{_sysconfdir}/crowdsec/local_api_credentials.yaml 198 fi 199 fi 200 201 %systemd_post %{name}.service 202 203 if [ $1 == 1 ]; then 204 API=$(cscli config show --key "Config.API.Server") 205 if [ "$API" = "nil" ] ; then 206 LAPI=false 207 else 208 PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2) 209 fi 210 if [ "$LAPI" = false ] || [ -z "$(ss -nlt "sport = ${PORT}" | grep -v ^State)" ] ; then 211 %if 0%{?fc35} || 0%{?fc36} 212 systemctl enable crowdsec 213 %endif 214 systemctl start crowdsec || echo "crowdsec is not started" 215 else 216 echo "Not attempting to start crowdsec, port ${PORT} is already used or lapi was disabled" 217 echo "This port is configured through /etc/crowdsec/config.yaml and /etc/crowdsec/local_api_credentials.yaml" 218 fi 219 fi 220 221 %preun 222 223 #systemctl stop crowdsec || echo "crowdsec was not started" 224 225 %systemd_preun %{name}.service 226 227 %postun 228 229 %systemd_postun_with_restart %{name}.service 230 231 if [ $1 == 0 ]; then 232 rm -rf /etc/crowdsec/hub 233 fi 234 235 #systemctl stop crowdsec || echo "crowdsec was not started" 236 237 %changelog 238 * Tue Feb 16 2021 Manuel Sabban <manuel@crowdsec.net> 239 - First initial packaging