Skip to content

Commit

Permalink
Fix warts in setting up user in spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Apr 29, 2023
1 parent 041b3d9 commit a17cc05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/debian/salt-common.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ case "$1" in
echo "..done"
fi
# 2. create homedir if not existing
test -d $SALT_HOME || mkdir $SALT_HOME
test -d $SALT_HOME || mkdir -p $SALT_HOME
# 3. create user if not existing
if ! getent passwd | grep -q "^$SALT_USER:"; then
echo -n "Adding system user $SALT_USER.."
Expand Down
16 changes: 7 additions & 9 deletions pkg/rpm/salt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,18 @@ rm -rf %{buildroot}
%pre
# create user to avoid running server as root
# 1. create group if not existing
if ! getent group | grep -q "^%{_SALT_GROUP}:" ; then
addgroup --quiet --system %{_SALT_GROUP} 2>/dev/null ||true
if ! getent group %{_SALT_GROUP}; then
groupadd --system %{_SALT_GROUP} 2>/dev/null ||true
fi
# 2. create homedir if not existing
test -d %{_SALT_HOME} || mkdir %{_SALT_HOME}
test -d %{_SALT_HOME} || mkdir -p %{_SALT_HOME}
# 3. create user if not existing
# -g %{_SALT_GROUP} \
if ! getent passwd | grep -q "^%{_SALT_USER}:"; then
adduser --quiet \
--system \
--ingroup %{_SALT_USER} \
adduser --system \
--no-create-home \
--disabled-password \
-s /sbin/nlogin \
-g %{_SALT_GROUP} \
%{_SALT_USER} 2>/dev/null || true
fi
# 4. adjust passwd entry
Expand All @@ -382,8 +381,6 @@ usermod -c "%{_SALT_NAME}" \
%{_SALT_USER}
# 5. adjust file and directory permissions
chown -R %{_SALT_USER}:%{_SALT_GROUP} %{_SALT_HOME}
chmod u=rwx,g=rxs,o= %{_SALT_HOME}


# assumes systemd for RHEL 7 & 8 & 9
%preun master
Expand All @@ -400,6 +397,7 @@ chmod u=rwx,g=rxs,o= %{_SALT_HOME}


%post
chown -R %{_SALT_USER}:%{_SALT_GROUP} %{_SALT_HOME}
ln -s -f /opt/saltstack/salt/spm %{_bindir}/spm
ln -s -f /opt/saltstack/salt/salt-pip %{_bindir}/salt-pip

Expand Down

0 comments on commit a17cc05

Please sign in to comment.