Skip to content

Commit

Permalink
[JENKINS-23273] Change ownership only if needed
Browse files Browse the repository at this point in the history
* Now /var/cache%{name} /var/log/%{name} and workdir files are chowned
only if parent folder is not already owned by appropriate user
* Also added sticky bit to that folders so only the appropriate user can
create files there
  • Loading branch information
raul-arabaolaza committed Jan 16, 2017
1 parent 5083f2e commit 679fbfe
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rpm/build/SPECS/jenkins.spec
Expand Up @@ -79,6 +79,23 @@ rm -rf "%{buildroot}"
%post
/sbin/chkconfig --add %{name}

# Ensure the right ownership on files only if not owned by JENKINS_USER
. /etc/sysconfig/%{name}
if test x"$JENKINS_INSTALL_SKIP_CHOWN" != "xtrue"; then
owner=$(ls -ld /var/cache/%{name} | awk 'NR==1 {print $3}')
if [ "$owner" != "${JENKINS_USER:-%{name}}" ] ; then
chown -R ${JENKINS_USER:-%{name}} /var/cache/%{name}
fi
owner=$(ls -ld /var/log/%{name} | awk 'NR==1 {print $3}')
if [ "$owner" != "${JENKINS_USER:-%{name}}" ] ; then
chown -R ${JENKINS_USER:-%{name}} /var/log/%{name}
fi
owner=$(ls -ld ${JENKINS_HOME:-%{workdir}}| awk 'NR==1 {print $3}')
if [ "$owner" != "${JENKINS_USER:-%{name}}" ] ; then
chown -R ${JENKINS_USER:-%{name}} ${JENKINS_HOME:-%{workdir}}
fi
fi

%preun
if [ "$1" = 0 ] ; then
# if this is uninstallation as opposed to upgrade, delete the service
Expand Down

0 comments on commit 679fbfe

Please sign in to comment.