Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set permissions after RPM install

I use this spec file to use RPM files

Name:           pack-agent
Version:        1.0
Release:        1%{?dist}
Summary:        Linux Agent installation script
Group:          Utilities
License:        license
Source0:        pack-agent-1.0.tar.gz
BuildArch:      x86_64
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%description

%prep
%setup -q -n opt

%build

%install
#install -m 0755 -d $RPM_BUILD_ROOT/agent
#cp -ap agent/* $RPM_BUILD_ROOT/agent/

install -m 0755 -d %{buildroot}/opt
#cp -a * %{buildroot}/agent
cp -a * %{buildroot}/opt

%clean
rm -rf $RPM_BUILD_ROOT

%files
/opt
%defattr(-,root,root,-)
%attr(777, root, root) /opt/agent/bin/karaf

%doc
%changelog

But after install the files are not executable. I need to start file insight directories tree. Is there anyway to add chmod command insight the spec file and use it to set permissions after RPM install?

like image 319
user1285928 Avatar asked Aug 28 '15 19:08

user1285928


1 Answers

You can add chmod to a %post section if you wanted to but that's the wrong approach to the problem.

You should just make sure that the files are executable in the buildroot during the installation and they should remain so (with that %defattr entry) in the RPM and once installed (though that %defattr entry should be above the /opt line).

Alternatively, you can use the %defattr macro and %attr macros to have RPM apply specific permissions to specific files in the %files section manually.

See Directives For the %files list and Specifying File Attributes for how the directives work.

Example from the second link:

%files
%attr(-, root, root) %doc README
%attr(4755, root, root) /usr/local/bin/cdp
%attr(-, root, root) /usr/local/bin/cdplay
%attr(-, root, rot) /usr/local/man/man1/cdp.1
like image 71
Etan Reisner Avatar answered Sep 20 '22 23:09

Etan Reisner