我正在使用RPM在目标计算机上创建一堆文件和目录,每个RPM都有一组不同的文件/目录权限。我创建了一个spec文件,它构建了这个RPM。 spec文件如下所示:
Name: testMultipleFiles
Version: 1.0
Release: 2
Summary: Demo how to package multiple files
Group: DCCA Deployment
License: GPLv2
Source: testMultipleFiles.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
AutoReqProv: on
%description
Authors:
--------
Name Raj Kumar Sanpui
%prep
%setup -q
%build
%install
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir1
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir2
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir3
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir4
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir5
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir6
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir7
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir8
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir9
mkdir -p $RPM_BUILD_ROOT/opt/insiteone/dir10
install file1.sh $RPM_BUILD_ROOT/opt/insiteone/dir1
install file2.sh $RPM_BUILD_ROOT/opt/insiteone/dir2
install file3.sh $RPM_BUILD_ROOT/opt/insiteone/dir3
install file4.sh $RPM_BUILD_ROOT/opt/insiteone/dir4
install file5.sh $RPM_BUILD_ROOT/opt/insiteone/dir5
install file6.sh $RPM_BUILD_ROOT/opt/insiteone/dir6
%clean
rm -rf $RPM_BUILD_ROOT
%post
%postun
%files
%defattr(644,insite1,insite1,0755)
/opt/insiteone/dir1/file1.sh
/opt/insiteone/dir2/file2.sh
/opt/insiteone/dir3/file3.sh
%attr(644,insite1,insite1)/opt/insiteone/dir4/file4.sh
%attr(644,insite1,insite1)/opt/insiteone/dir5/file5.sh
%attr(644,insite1,insite1)/opt/insiteone/dir6/file6.sh
%dir %attr(777,insite1,insite1)/opt/insiteone/dir4
%dir %attr(700,insite1,insite1)/opt/insiteone/dir5
%dir %attr(644,insite1,insite1)/opt/insiteone/dir6
%dir %attr(640,insite1,insite1)/opt/insiteone/dir7
%dir %attr(600,insite1,insite1)/opt/insiteone/dir8
%dir %attr(744,insite1,insite1)/opt/insiteone/dir9
%dir %attr(644,insite1,insite1)/opt/insiteone/dir10
但是,当我构建此RPM时,没有错误并且构建成功但构建日志说:
Checking permissions and ownerships - using the permissions files
/tmp/Check.perms.gv6tJD
setting /var/tmp/testMultipleFiles-1.0-build/ to root:root 0755. (wrong owner/group build:users)
setting /var/tmp/testMultipleFiles-1.0-build/opt to root:root 0755. (wrong owner/group build:users)
表示设置为root:root而不是insite1:insite1作为用户和组。
这是完整的构建日志。
build@SLES11SP4-185:~/rpmbuild/SPECS> rpmbuild -bb testmulti.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.14760
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd /home/build/rpmbuild/BUILD
+ rm -rf testMultipleFiles-1.0
+ /usr/bin/gzip -dc /home/build/rpmbuild/SOURCES/testMultipleFiles.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd testMultipleFiles-1.0
++ /usr/bin/id -u
+ '[' 1001 = 0 ']'
++ /usr/bin/id -u
+ '[' 1001 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.14760
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ /bin/rm -rf /var/tmp/testMultipleFiles-1.0-build
++ dirname /var/tmp/testMultipleFiles-1.0-build
+ /bin/mkdir -p /var/tmp
+ /bin/mkdir /var/tmp/testMultipleFiles-1.0-build
+ cd testMultipleFiles-1.0
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.14760
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd testMultipleFiles-1.0
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir1
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir2
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir3
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir4
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir5
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir6
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir7
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir8
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir9
+ mkdir -p /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir10
+ install file1.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir1
+ install file2.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir2
+ install file3.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir3
+ install file4.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir4
+ install file5.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir5
+ install file6.sh /var/tmp/testMultipleFiles-1.0-build/opt/insiteone/dir6
+ /usr/lib/rpm/brp-lib64-linux
sf@suse.de: if you find problems with this script, drop me a note
+ RPM_BUILD_ROOT=/var/tmp/testMultipleFiles-1.0-build
+ export RPM_BUILD_ROOT
+ test -x /usr/sbin/Check -a 1001 = 0 -o -x /usr/sbin/Check -a '!' -z /var/tmp/testMultipleFiles-1.0-build
+ echo 'I call /usr/sbin/Check...'
I call /usr/sbin/Check...
+ /usr/sbin/Check
Checking permissions and ownerships - using the permissions files
/tmp/Check.perms.gv6tJD
setting /var/tmp/testMultipleFiles-1.0-build/ to root:root 0755. (wrong owner/group build:users)
setting /var/tmp/testMultipleFiles-1.0-build/opt to root:root 0755. (wrong owner/group build:users)
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-symlink
Processing files: testMultipleFiles-1.0-2
Finding Provides: /usr/lib/rpm/find-provides testMultipleFiles
Finding Requires: /usr/lib/rpm/find-requires testMultipleFiles
Finding Supplements: /usr/lib/rpm/find-supplements testMultipleFiles
Requires(interp): /bin/sh /bin/sh
Requires(rpmlib): rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1
Requires(post): /bin/sh
Requires(postun): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/testMultipleFiles-1.0-build
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/testMultipleFiles-1.0-build
Wrote: /home/build/rpmbuild/RPMS/x86_64/testMultipleFiles-1.0-2.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.14760
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd testMultipleFiles-1.0
+ rm -rf /var/tmp/testMultipleFiles-1.0-build
+ exit 0
请注意: insite1:insite1用户和组将预先出现在目标计算机中,安装了RPM,并且RPM构建计算机中不存在任何内容,因为没理由让我创造它们。
添加:我观察到,它继续以适当的权限安装所有文件和目录,在具有用户和组的目标计算机中存在(insite1:insite1),然而目录dir1,dir2和dir3仍设置为root:root 但是0755,我希望它是insite1:insite1基于%defattr
设置。 是否无法设置默认目录权限?
答案 0 :(得分:2)
当你输入%files
时:
/opt/insiteone/dir1/file1.sh
这意味着在rpm中只获取file1.sh
。并且defattr仅适用于该文件。当然文件带有一些路径。因此,如果路径不存在,则创建它。使用当前用户(通常是root)。
所以你应该说:
%files
/opt/insiteone/dir1
将dir1及其中的所有内容(递归)。 或者:
%files
%dir /opt/insiteone/dir1
/opt/insiteone/dir1/file1.sh
BTW正确的包应该检查用户和组&#34; insite1&#34;存在。您可以使用此%前摘录https://fedoraproject.org/wiki/Packaging:UsersAndGroups?rd=Packaging/UsersAndGroups#Dynamic_allocation
执行此操作