LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 08-17-2017, 07:13 PM   #1
Corrado
Member
 
Registered: Aug 2004
Location: Washington
Distribution: RHEL 5.0
Posts: 145

Rep: Reputation: 16
Building rpm to assign attributes to directory


Am wondering how one assigns permissions, ownership and group to a directory in the spec file for an rpm that I am trying to build.

This is what I have so far and doesn't work.

Code:
%install
install -d -o root -g sw -m 0775 $RPM_BUILD_ROOT/vmguests/win10-7.01
It doesn’t work. Any suggestions on how I get those attributes onto the new directory? I had thought I could do it in %files with %attr but no go.

Thank you.

Last edited by Corrado; 08-17-2017 at 07:16 PM.
 
Old 08-18-2017, 12:29 PM   #2
jsbjsb001
Member
 
Registered: Mar 2009
Location: hopefully earth ;)
Distribution: Any Linux distro that suits my needs. As long as it's Linux, I try not to lock myself into anything!
Posts: 546

Rep: Reputation: 249Reputation: 249Reputation: 249
Quote:
Originally Posted by Corrado View Post
Am wondering how one assigns permissions, ownership and group to a directory in the spec file for an rpm that I am trying to build.

This is what I have so far and doesn't work.

Code:
%install
install -d -o root -g sw -m 0775 $RPM_BUILD_ROOT/vmguests/win10-7.01
It doesn’t work. Any suggestions on how I get those attributes onto the new directory? I had thought I could do it in %files with %attr but no go.

Thank you.
The following is an example of mine that installs Universal Media Server. I added some of my own comments to it, and got it from an openSUSE template spec file.

Code:
#
# spec file for package [spectemplate]
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
# See also http://en.opensuse.org/openSUSE:Specfile_guidelines

# name of rpm package.

Name: ums-centos7-el

# you have to put someting for the "Version:" and "Release:" options.
Version: 6.7.2       
Release: 2.2

Summary: Universal Media Server with ums.service for systemd based distros.

# you have to add something after the following "License:" (you can put anything after it, eg. none).

License: GPLv2 

Group: Servers/Multimedia         
Url: http://www.universalmediaserver.com/

# put name of tar.gz file after "Source:".

Source: ums.tar.gz

# for no arch use "noarch", comment out "BuildArch:" for 64 bit packages, as this is usually the default anyway.

#BuildArch:

Distribution: CentOS/RHEL/EL 
Vendor: James
Packager: James
Requires: java

%description

Universal Media Server version 6.7.2 with configuration (/etc/ums/*) and ums.service for systemd based distros, this package has *only* been tested on CentOS 7 (64 bit). 
But as long as Java is working, it should work on RHEL/Fedora/etc, among most other rpm software package and systemd based Linux distros.

UMS itself is installed to the /opt/ums folder, while the system-wide confioguration files for UMS, are located at /etc/ums in this package.

UMS documentation for installed package, is located at: /usr/share/doc/ums-6.7.2/ and /usr/share/doc/ums-6.7.2/html/ (for HTML UMS documentation)

You may need to configure UMS.conf located in the /etc/ums/ folder, to get UMS to work for you (eg. headless server).

# Put commands here that should be run before anything else (eg. setup system accounts, etc). 

%pre
/usr/sbin/groupadd -r ums
/usr/sbin/useradd -r -d /opt/ums -s /sbin/nologin -g ums ums

%prep

# following has to be the same name as the .tar.gz source file archive, after "setup -n".

%setup -n ums

%install

rm -rf "$RPM_BUILD_ROOT"

# make the folders on the root file system for files and folders in this rpm package.

mkdir -p "$RPM_BUILD_ROOT/opt/ums/"
mkdir -p "$RPM_BUILD_ROOT/usr/lib/systemd/system/"
mkdir -p "$RPM_BUILD_ROOT/etc/ums/"
mkdir -p "$RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/"
mkdir -p "$RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/"
mkdir -p "$RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/css/"
mkdir -p "$RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/"

# copy the tar.gz archive to the ~/rpmbuild/BUILDROOT folder.

cp -R * "$RPM_BUILD_ROOT/opt/ums/"

# remove files and folders from top level dir, that are supossed to be sumwhere else (eg. in this case for example; /etc/ums/).

# Note: The top level dir in this package is "/opt/ums/" and is the first line after "rm -rf "$RPM_BUILD_ROOT", 
# at the start of the "install" section of this rpm spec file.    

rm "$RPM_BUILD_ROOT/opt/ums/CHANGELOG.txt"
rm "$RPM_BUILD_ROOT/opt/ums/README.txt"
rm "$RPM_BUILD_ROOT/opt/ums/LICENSE.txt"
rm "$RPM_BUILD_ROOT/opt/ums/INSTALL.txt"
rm -rf "$RPM_BUILD_ROOT/opt/ums/documentation/"
rm "$RPM_BUILD_ROOT/opt/ums/ums.service"
rm "$RPM_BUILD_ROOT/opt/ums/UMS.conf"
rm "$RPM_BUILD_ROOT/opt/ums/WEB.conf"

# install the files in this rpm package, to the root file system on hard drive/storage media Linux is installed upon.

install -m 644 CHANGELOG.txt $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/
install -m 644 README.txt $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/
install -m 644 LICENSE.txt $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/
install -m 644 INSTALL.txt $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/
install -m 644 documentation/applications.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/avisynth.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/commandline.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/coreavc.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/css/style.css $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/css/
install -m 644 documentation/general_configuration.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/images/autonegotiation.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/btn_donateCC_LG.gif $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/coreavc1.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/coreavc2.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/coreavc3.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/netzwerkverbindungen.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-eng-general1.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-eng-general.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-engines1.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-engines2.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-eng-status1.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-eng-status2.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/pms-searching.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/ps3-browsing.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/ps3screen.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/ps3-server.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/setupwin1.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/setupwin2.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/setupwin3.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/setupwin4.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/ssdp.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/images/topology_ps3.jpg $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/images/
install -m 644 documentation/index.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/installation.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/introduction.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/links.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/ 
install -m 644 documentation/navigation_share.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/ 
install -m 644 documentation/networking.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/plugins.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/transcoding.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 documentation/videolan.html $RPM_BUILD_ROOT/usr/share/doc/ums-6.7.2/html/
install -m 644 ums.service $RPM_BUILD_ROOT/usr/lib/systemd/system/
install -m 644 UMS.conf $RPM_BUILD_ROOT/etc/ums/
install -m 644 WEB.conf $RPM_BUILD_ROOT/etc/ums/

# put all of the top level folders here, except the first folder listed under the "install" section of this rpm spec file.

%files
/opt/ums/
/usr/lib/systemd/system/
# change /etc/ums/ folder ownership from the root user account to the ums account, so it can have permission to write to the /etc/ums/ folder.
%defattr(-,ums,ums)
/etc/ums/

## configuration files for ums ##

# So the config files for ums show up in rpm package query's.

%config /etc/ums/UMS.conf
%config /etc/ums/WEB.conf

%defattr(-,root,root)
%config /usr/lib/systemd/system/ums.service

## documentation files for ums ##
# give file and folder ownership to the root user account, for all of the docs.

%defattr(-,root,root)
%docdir /usr/share/doc/ums-6.7.2/
/usr/share/doc/ums-6.7.2/CHANGELOG.txt
/usr/share/doc/ums-6.7.2/README.txt
/usr/share/doc/ums-6.7.2/LICENSE.txt
/usr/share/doc/ums-6.7.2/INSTALL.txt
/usr/share/doc/ums-6.7.2/html/applications.html
/usr/share/doc/ums-6.7.2/html/avisynth.html
/usr/share/doc/ums-6.7.2/html/commandline.html
/usr/share/doc/ums-6.7.2/html/coreavc.html
/usr/share/doc/ums-6.7.2/html/css/style.css
/usr/share/doc/ums-6.7.2/html/general_configuration.html
/usr/share/doc/ums-6.7.2/html/images/autonegotiation.jpg
/usr/share/doc/ums-6.7.2/html/images/btn_donateCC_LG.gif
/usr/share/doc/ums-6.7.2/html/images/coreavc1.jpg
/usr/share/doc/ums-6.7.2/html/images/coreavc2.jpg
/usr/share/doc/ums-6.7.2/html/images/coreavc3.jpg
/usr/share/doc/ums-6.7.2/html/images/netzwerkverbindungen.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-eng-general1.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-eng-general.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-engines1.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-engines2.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-eng-status1.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-eng-status2.jpg
/usr/share/doc/ums-6.7.2/html/images/pms-searching.jpg
/usr/share/doc/ums-6.7.2/html/images/ps3-browsing.jpg
/usr/share/doc/ums-6.7.2/html/images/ps3screen.jpg
/usr/share/doc/ums-6.7.2/html/images/ps3-server.jpg
/usr/share/doc/ums-6.7.2/html/images/setupwin1.jpg
/usr/share/doc/ums-6.7.2/html/images/setupwin2.jpg
/usr/share/doc/ums-6.7.2/html/images/setupwin3.jpg
/usr/share/doc/ums-6.7.2/html/images/setupwin4.jpg
/usr/share/doc/ums-6.7.2/html/images/ssdp.jpg
/usr/share/doc/ums-6.7.2/html/images/topology_ps3.jpg
/usr/share/doc/ums-6.7.2/html/index.html
/usr/share/doc/ums-6.7.2/html/installation.html
/usr/share/doc/ums-6.7.2/html/introduction.html
/usr/share/doc/ums-6.7.2/html/links.html
/usr/share/doc/ums-6.7.2/html/navigation_share.html
/usr/share/doc/ums-6.7.2/html/networking.html
/usr/share/doc/ums-6.7.2/html/plugins.html
/usr/share/doc/ums-6.7.2/html/transcoding.html
/usr/share/doc/ums-6.7.2/html/videolan.html

# put stuff here that should be removed when package is uninstalled (eg. delete system accounts created by this package, etc).

%postun
/usr/sbin/userdel ums

# remove build files after package has been built.
%clean
rm -rf $RPM_BUILD_ROOT

%changelog
* Mon Jul 24 2017 James
- v6.7.2-2.2 package will now create ums accounts for headless server, yay!!
* Sun Jul 23 2017 James
- RPM .spec file updated.
- v6.7.2-2; moved html docs to docdir.
- v6.7.2-2.1 changed package name from ums-config-and-systemd.service to ums-centos7-el
- v6.7.2-2.1 RPM spec file update and cleanup.
- v6.7.2-2.1 TODO: get package to create ums account and change ownership of /etc/ums/ to, support UMS in headless mode (ums.service).
Good luck!
 
Old 08-18-2017, 12:59 PM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,125
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
have you tried %defattr in the %files section? It has attributes for both files and directories.

%defattr(0644, root, root, 0755)
 
Old 08-20-2017, 01:04 AM   #4
Corrado
Member
 
Registered: Aug 2004
Location: Washington
Distribution: RHEL 5.0
Posts: 145

Original Poster
Rep: Reputation: 16
I think I have figured it out. I think this is what I am after.....

Code:
%dir%attr(0644, root, root, 0755)
What do you think?
 
Old 08-20-2017, 04:22 AM   #5
jsbjsb001
Member
 
Registered: Mar 2009
Location: hopefully earth ;)
Distribution: Any Linux distro that suits my needs. As long as it's Linux, I try not to lock myself into anything!
Posts: 546

Rep: Reputation: 249Reputation: 249Reputation: 249
Quote:
Originally Posted by Corrado View Post
I think I have figured it out. I think this is what I am after.....

Code:
%dir%attr(0644, root, root, 0755)
What do you think?
Can you post your rpm spec file?

And also you may what to have a look at this: http://ftp.rpm.org/max-rpm/s1-rpm-in...irectives.html and: https://docs.fedoraproject.org/en-US...h09s05s04.html

Last edited by jsbjsb001; 08-20-2017 at 04:24 AM. Reason: added fedora link
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File and Directory attributes messed up after a RAID controller failure mubashirabbas Linux - Newbie 5 07-03-2012 07:24 PM
error in building rpm of open ldap from source using rpm package manager Infotechie Linux - Software 2 05-02-2012 01:10 AM
[SOLVED] ls shows directory attributes as question marks daisychick Linux - Newbie 5 04-30-2012 03:19 PM
rpm spec attributes in scons jacobselvin Programming 0 03-05-2012 01:42 AM
Question marks in the directory attributes, need help fixing. jason143 Linux - Software 5 06-22-2009 01:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration