From f52561a12f1cb20071bb78f75589204f3a31d92c Mon Sep 17 00:00:00 2001 From: Jan Pokorny Date: Dec 08 2010 20:47:03 +0000 Subject: spec: user/group creation not violating convention rules --- diff --git a/luci.spec b/luci.spec index 000b991..fbdfb4f 100644 --- a/luci.spec +++ b/luci.spec @@ -5,9 +5,7 @@ # 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); -# we want to force one particular system-allocated uid/gid -%global def_luciuserid 141 +# Default luci-specific user/group (using the same values) %global def_luciusername %{name} # Default port running luci binds at %global def_luciport 8084 @@ -15,9 +13,7 @@ # 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}} @@ -202,48 +198,10 @@ touch "%{buildroot}%{lucidbfile}" %pre -# 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 +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} exit 0 %post