python3 setup.py install --single-version-externally-managed -O1 --root=%{buildroot} --record=INSTALLED_FILES

# make sure we also own the top level and egg-info raw dir to make things easy on uninstall
echo "%{python3_sitelib}/%{name}-*egg-info" >> INSTALLED_FILES
echo "%{python3_sitelib}/%{name}" >> INSTALLED_FILES

install -m 0644 -D package/systemd/decisionengine.service %{buildroot}/usr/lib/systemd/system/decisionengine.service
echo "%attr(0644,root,root) /usr/lib/systemd/system/decisionengine.service" >> INSTALLED_FILES

install -m 0644 -D package/systemd/decisionengine_sysuser.conf %{buildroot}/usr/lib/sysusers.d/decisionengine.conf
echo "%attr(0644,root,root) /usr/lib/sysusers.d/decisionengine.conf" >> INSTALLED_FILES

mkdir -p %{buildroot}/%{_localstatedir}/log/decisionengine
echo "%attr(0750,decisionengine,decisionengine) %{_localstatedir}/log/decisionengine" >> INSTALLED_FILES

mkdir -p %{buildroot}/%{_sharedstatedir}/decisionengine
echo "%attr(0750,decisionengine,decisionengine) %{_sharedstatedir}/decisionengine" >> INSTALLED_FILES

mkdir -p %{buildroot}/%{_sysconfdir}/decisionengine/config.d
cp -r config/* %{buildroot}/%{_sysconfdir}/decisionengine/

echo "%dir %attr(0750,decisionengine,decisionengine) %{_sysconfdir}/decisionengine/" >> INSTALLED_FILES
echo "%attr(0640,decisionengine,decisionengine) %config(noreplace) /%{_sysconfdir}/decisionengine/decision_engine.jsonnet" >> INSTALLED_FILES

echo "%dir %attr(0750,decisionengine,decisionengine) %{_sysconfdir}/decisionengine/config.d/" >> INSTALLED_FILES
[ "$(ls -A %{buildroot}/%{_sysconfdir}/decisionengine/config.d)" ] && echo "%attr(0640decisionengine,decisionengine) %config(noreplace) %{_sysconfdir}/decisionengine/config.d/*" >> INSTALLED_FILES

install -m 0644 -D package/systemd/decisionengine_sysconfig %{buildroot}/%{_sysconfdir}/sysconfig/decisionengine
echo "%attr(0640,root,decisionengine) %config(noreplace) %{_sysconfdir}/sysconfig/decisionengine" >> INSTALLED_FILES

mkdir -p %{buildroot}/%{_defaultdocdir}/%{name}/datasources/
echo "%doc %{_defaultdocdir}/%{name}" >> INSTALLED_FILES
