diff --git a/grafana.spec b/grafana.spec index 53d9f67..9b85b4d 100644 --- a/grafana.spec +++ b/grafana.spec @@ -18,6 +18,7 @@ %define GRAFANA_USER %{name} %define GRAFANA_GROUP %{name} +%define GRAFANA_HOME %{_datadir}/%{name} Name: grafana Version: 5.0.0 @@ -108,17 +109,10 @@ ln -s %{_bindir}/phantomjs %{buildroot}%{_datadir}/%{name}/tools/phantomjs/phant %pre %service_add_pre %{name}-server.service -if [ $1 -eq 1 ]; then -if ! %{_bindir}/id %{GRAFANA_USER} &>/dev/null; then -echo -n "Create a new group %{GRAFANA_GROUP}:" -%{_sbindir}/groupadd -r %{GRAFANA_GROUP} ||: -echo "... done" -echo -n "Create a new user %{GRAFANA_USER}:" -%{_sbindir}/useradd -r -g %{GRAFANA_GROUP} -d %{_datadir}/%{name} \ --s /sbin/nologin -c "%{GRAFANA_USER} user" %{GRAFANA_GROUP} -echo "... done"; -fi -fi +echo "Creating user %{GRAFANA_USER} and group %{GRAFANA_GROUP} if not present" +getent group %{GRAFANA_GROUP} > /dev/null || groupadd -r %{GRAFANA_GROUP} +getent passwd %{GRAFANA_GROUP} > /dev/null || useradd -r -g %{GRAFANA_GROUP} \ +-d %{GRAFANA_HOME} -s /sbin/nologin -c "%{GRAFANA_USER} user" %{GRAFANA_GROUP} %post %{fillup_only -n %{name}-server} @@ -129,11 +123,6 @@ fi %postun %service_del_postun %{name}-server.service -if [ $1 -eq 0 ]; then -userdel %{GRAFANA_USER} || logger "User \"%{GRAFANA_USER}\" could not be deleted." -groupdel %{GRAFANA_GROUP} || logger "Group \"%{GRAFANA_GROUP}\" could not be deleted." -rm -rf %{_localstatedir}/lib/%{name} -rm -rf %{_localstatedir}/log/%{name}; fi %files %defattr(-,root,root)