From 8ab221871ad93f06e7963a1747c81f0fab3925f3 Mon Sep 17 00:00:00 2001 From: Jan Pokorny Date: Dec 08 2010 21:51:03 +0000 Subject: Returning bad revert back to previous state --- diff --git a/luci.spec b/luci.spec index d573326..6bc1ecd 100644 --- a/luci.spec +++ b/luci.spec @@ -5,7 +5,9 @@ # Default root directory for luci state files %global def_lucistatedir %{_sharedstatedir}/%{name} %global def_lucilogdir %{_localstatedir}/log/%{name} -# Default luci-specific user/group (using the same values) +# Default luci-specific user/group (using the same values); +# we want to force one particular system-allocated uid/gid +%global def_luciuserid 141 %global def_luciusername %{name} # Default port running luci binds at %global def_luciport 8084 @@ -13,7 +15,9 @@ # Conditional assignment allowing external redefinition during build stage %{!?lucistatedir: %global lucistatedir %{def_lucistatedir}} %{!?lucilogdir: %global lucilogdir %{def_lucilogdir}} +%{!?luciuserid: %global luciuserid %{def_luciuserid}} %{!?luciusername: %global luciusername %{def_luciusername}} +%{!?lucigroupid: %global lucigroupid %{luciuserid}} %{!?lucigroupname: %global lucigroupname %{luciusername}} %{!?luciport: %global luciport %{def_luciport}} @@ -198,10 +202,48 @@ touch "%{buildroot}%{lucidbfile}" %pre -getent group %{lucigroupname} >/dev/null || groupadd -r %{lucigroupname} -getent passwd %{luciusername} >/dev/null || \ - useradd -r -g %{lucigroupname} -d %{lucistatedir} -s /sbin/nologin \ - -c "%{name} high availability management application" %{luciusername} +# Group preparation +str_groupid=$(getent group "%{lucigroupid}" 2>/dev/null) +str_groupname=$(getent group "%{lucigroupname}" 2>/dev/null) +group_ready=1 +if [ "$str_groupid" == "$str_groupname" ]; then + if [ -z "$str_groupid" ]; then + # Neither such gid nor groupname present yet (perhaps 1st install) + /usr/sbin/groupadd -g "%{lucigroupid}" "%{lucigroupname}" 2>/dev/null + fi + # Otherwise everything is already prepared wrt. groups (perhaps upgrade) +else + echo "ERROR: unexpected state of group \`%{lucigroupname}'" \ + "(gid %{lucigroupid}) encountered (colliding group probably" \ + "created manually beforehand)" >&2 + echo "SOLUTION: make sure there is no group named \`%{lucigroupname}'" \ + "and also no group uses gid %{lucigroupid}, then reinstall;" \ + "alternatively, make sure that mentioned group name matches" \ + "mentioned gid, then reinstall (not recommended)" >&2 + group_ready=0 +fi +if [ $group_ready -eq 1 ]; then + # User preparation + str_userid=$(getent passwd "%{luciuserid}" 2>/dev/null) + str_username=$(getent passwd "%{luciusername}" 2>/dev/null) + if [ "$str_userid" == "$str_username" ]; then + if [ -z "$str_userid" ]; then + # Neither such uid nor username present yet (perhaps 1st install) + /usr/sbin/useradd -r -u "%{luciuserid}" -g "%{lucigroupid}" \ + -d "%{lucistatedir}" -s /sbin/nologin \ + -c "luci user" "%{luciusername}" 2>/dev/null + fi + # Otherwise everything is already prepared wrt. users (perhaps upgrade) + else + echo "ERROR: unexpected state of user \`%{luciusername}'" \ + "(uid %{luciuserid}) encountered (colliding user probably" \ + "created manually beforehand)" >&2 + echo "SOLUTION: make sure there is no user named \`%{luciusername}'" \ + "and also no user uses uid %{luciuserid}, then reinstall;" \ + "alternatively, make sure that mentioned user name matches" \ + "mentioned uid, then reinstall (not recommended)" >&2 + fi +fi exit 0 %post