[SOLVED] Building rpm to assign attributes to directory
Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.