PDA

View Full Version : [SOLVED] rpmbuild: cant create dir, permission denied


sea
2nd February 2012, 07:24 PM
Hiyas,

The first try to build a rpm, please be easy.

-- EDIT: Its solved, below is the 'working' spec for script files.

sc.spec file:
Summary: Script Collection to go from minimal install to GUI, and other tools
Name: sc
Version: 0.1.2
Release: 0.1%{?dist}
Group: System Enviroment/Base
Prefix: /usr/sc
License: GPL
URL: http://sea.hostingsociety.com
Source0: http://downloads.sf.net/p/seasc/sc-%{version}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%description
The Script Collection provides tools to easy go for a minimal GUI that are either minimal,
or not in the standart repos of Fedora or other RH based systems. Such as LXDE, Awesome, E16 or Cinnamon.
Further it provides tools like iso2usb which works greate for iso files of many distros, such as RH based, Arch and Debian.

There are also some 'fun' features like BB signature generator, changing plymouth, or the install of multimedia codecs.

And more...

%prep
%setup -q -c sc-%{version}

%build
# nothing to do

%install
rm -rf %buildroot
mkdir -p %{buildroot}/%{_prefix}/sc
mv * %{buildroot}/%{_prefix}/sc/

#
# do not override an existing file
#
mkdir -p %{buildroot}/%{_sysconfdir}/profile.d
cat >> %{buildroot}/%{_sysconfdir}/profile.d/%{name}.sh << EOF
# ----- Script Collection : Open ----- #
export scDir=%{prefix}
export PATH=\$scDir:\$scDir/collection:\$PATH # This lines enables you to run script collection, as well as those scripts located in $scDir/collection (eg: rmtf, yumreset) directly from terminal)
source sc.cfg # see sc-README for commands provided.
# ----- Script Collection : Close ----- #
EOF


%clean
rm -rf %{buildroot}

%files
# -- The scripts should be executable by any user, as some parts (LFS) even require to be NOT root !
%defattr(-,root,root,0755)
#%%doc sc-README
%{prefix}/sc
%{prefix}/sc-*
%{prefix}/sc.*
%{prefix}/system/*
%{prefix}/collection/*
%{_sysconfdir}/profile.d/%{name}.sh

%changelog
* Thu Feb 02 2012 Simon A. Erat (sea), arjuna dot erat at web dot de
- %{version}, initial RPM try
- Yay

Run as user makerpm:
rpmbuild -ba $HOME/rpmbuild/SPECS/sc.spec --target noarch

After successfull execution LS should display like:
ls rpmbuild/*

rpmbuild/BUILD:
sc-0.1.2

rpmbuild/BUILDROOT:

rpmbuild/RPMS:
noarch

rpmbuild/SOURCES:
sc-0.1.2.tar.gz

rpmbuild/SPECS:
sc.spec

rpmbuild/SRPMS:
sc-0.1.2-0.1.fc16.src.rpm

marko
2nd February 2012, 08:32 PM
Sea:

I've only used rpmbuild in the "rebuild" mode which is good for building kernels from the src rpm, but from my reading of the man page, -ba is doing a prep, build and install
The spec file is pointing the rpm build to install to "/usr/sc" which you don't have permission to change as the "makerpm" user. What you probably want to do is just do the prep and build, then do the install manually as root.:

rpmbuild -bc ~rpmbuild/SPECS/sc.spec ---> "-bc" does only prep and build (similar to doing a "make")
... when it completes....
su
<root password>
change directory down into the RPMS area where the rpm files are that just built, then install your rpms:

yum install <put your rpm filenames here>

sea
2nd February 2012, 08:51 PM

Thank you Marko, at first execution i was happy it exited with 0, but on a closer look, there is no rpm :(

clear && rpmbuild -bc ./SPECS/sc.spec --target noarch && echo "------------------" && ls *
Building target platforms: noarch
Building for target noarch
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.eHRfck
+ umask 022
+ cd /home/makerpm/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/makerpm/rpmbuild/BUILD
+ rm -rf sc
+ /bin/mkdir -p sc
+ cd sc
+ /usr/bin/gzip -dc /home/makerpm/rpmbuild/SOURCES/sc-0.1.2.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
------------------
BUILD:
collection sc system sc.cfg sc.collect sc-gencmdlist.sh sc-install.sh sc-README sc-update sc-update.bak

BUILDROOT:

RPMS:

SOURCES:
sc-0.1.2.tar.gz

SPECS:
sc.spec

SRPMS:


I am not sure if it matters that i only have scripts?

EDIT:
Do i need to copy the files, as they wont be 'moved' as there is no 'make, make install' ?

marko
2nd February 2012, 09:17 PM
Hm, this is beyond what I know about it. Someone here will see this soon and know what's up.

sea
2nd February 2012, 10:43 PM
After a few tries and modifications, i finaly got 1 step further...
Please see first post for the spec file and command.
[makerpm@l670 rpmbuild]$ ls *
BUILD:
sc-0.1.2

BUILDROOT:
sc-0.1.2-0.1.fc16.noarch

RPMS:

SOURCES:
sc-0.1.2.tar.gz

SPECS:
sc.spec

SRPMS:


But the rpm is still missing.

leigh123linux
2nd February 2012, 11:55 PM
After a few tries and modifications, i finaly got 1 step further...
Please see first post for the spec file and command.


But the rpm is still missing.
Try

rpmbuild -ba = build all (build binary rpm + srpm)
rpmbuild -bb = build binary rpm
rpmbuild -bs = build srpm

LightDot
3rd February 2012, 02:37 AM
Hm. The main problem is that the spec from the initial post has numerous errors in the code, some of them quite dangerous. Ie., the spec is attempting changes to the actual live file system instead of preparing the environment to build the rpm from.

When rpmbuild returns a "permission denied" as in this case, I'd look at it as a blessing. If someone tried building such a .spec file as root, he/she'd have a good chance of damaging the actual OS. This is exactly the case why you should *never* build rpms as root or as a user with important files (documents, etc.) on the system. It's so easy to delete something important.

For example, these two lines from the install section:

mkdir -p %{prefix}
cp -p %{buildroot} %{prefix}

The first line is trying to create a directory on the actual OS! Hence the "permission denied".... The second line is copying the files from the build root to the actual OS again?!

I think you have a major missconception of how rpm building works in regards to buildroot.

I'd advise you to take a closer look into some of the existing Fedora's packages that mainly install files, and compare them with your spec file. Compare to see what they do differently and how buildroot must be used.

There are also other mistakes in this spec, ie. the files section doesn't specify any actual files. Etc. Etc.

It's a good start, but this spec needs some serious debugging before it could possibly work. :)

sea
3rd February 2012, 08:12 AM
Ok so i changed from -ba to -bc and back to -ba..
Tried both, -bs and -ba, both returned:
Building target platforms: noarch
Building for target noarch
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.nQUzv5
+ umask 022
+ cd /home/makerpm/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/makerpm/rpmbuild/BUILD
+ rm -rf sc-0.1.2
+ /bin/mkdir -p sc-0.1.2
+ cd sc-0.1.2
+ /usr/bin/gzip -dc /home/makerpm/rpmbuild/SOURCES/sc-0.1.2.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.PmT3jc
+ umask 022
+ cd /home/makerpm/rpmbuild/BUILD
+ cd sc-0.1.2
+ LANG=C
+ export LANG
+ unset DISPLAY
+ mkdir -p /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch
+ cd /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch
+ tar -axf /home/makerpm/rpmbuild/SOURCES/sc-0.1.2.tar.gz
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.NrLwkj
+ umask 022
+ cd /home/makerpm/rpmbuild/BUILD
+ '[' /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch '!=' / ']'
+ rm -rf /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch
++ dirname /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch
+ mkdir -p /home/makerpm/rpmbuild/BUILDROOT
+ mkdir /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch
+ cd sc-0.1.2
+ LANG=C
+ export LANG
+ unset DISPLAY
+ mkdir -p /usr/sc
mkdir: cannot create directory `/usr/sc': Permission denied
error: Bad exit status from /var/tmp/rpm-tmp.NrLwkj (%install)


RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.NrLwkj (%install)
------------------
[makerpm@l670 rpmbuild]$ ls *
BUILD:
sc-0.1.2

BUILDROOT:
sc-0.1.2-0.1.fc16.noarch

RPMS:

SOURCES:
sc-0.1.2.tar.gz

SPECS:
sc.spec

SRPMS:


Ok, read a bit more about the %files section..
According to: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s05.html
%files
# -- The scripts should be executable by any user, as some parts (LFS) even require to be NOT root !
%defattr(-,root,root,0755)
%doc sc-README changelog
/usr/sc/sc
/usr/sc/sc-*
/usr/sc/sc.*
/usr/sc/system/*
/usr/sc/collection/*
This should work, and due to the permission denial of %install section i commented that part out for now...

Trying now..

EDIT:
Ok, got a question, since the guide only lists the files just as i did above, i wonder if i would need to have /usr/sc as subdir of BUILD/sc-%{version}/ ?
As it is right now:
[makerpm@l670 rpmbuild]$ ls BUILD/sc-0.1.2/
collection system debugfiles.list debuglinks.list debugsources.list sc sc.cfg sc.collect sc-gencmdlist.sh sc-install.sh sc-README sc-update sc-update.bak
And the causing error is:
Processing files: sc-0.1.2-0.1.fc16.noarch
error: File not found: /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch/usr/sc/sc
error: File not found by glob: /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch/usr/sc/sc-*
error: File not found by glob: /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch/usr/sc/sc.*
error: File not found by glob: /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch/usr/sc/system/*
error: File not found by glob: /home/makerpm/rpmbuild/BUILDROOT/sc-0.1.2-0.1.fc16.noarch/usr/sc/collection/*

Skull One
3rd February 2012, 09:16 AM
It is your SPEC file that is buggy.
All the files _have_to_ be installed in the %buildroot directory. It will be considered as the root directory (like in a chroot) when rpmbuild will look for the files.

And your command 'tar -axf ~/rpmbuild/SOURCES/*' is dangerous, since everything wiil be treat. The good way is it declare all the sources in the preambule (like Source1, etc...), and use the corresponding variable to use them: %{SOURCE1}, etc....
Looking at the log, it is also irrelevant: you have a single source, SOURCE0, that is automatically unpacked in the %prep section.

I think that this should work:

%prep
%setup

%build
# nothing to do

%install
rm -rf %buildroot
mkdir -p %{buildroot}/%{_prefix}
mv * %{buildroot}/%{_prefix}/

#
# do not override an existing file
#
mkdir -p %{buildroot}/%{_sysconfdir}/profile.d
cat >> %{buildroot}/%{_sysconfdir}/profile.d/%{name}.sh << EOF
# ----- Script Collection : Open ----- #
export scDir=%{prefix}
export PATH=\$scDir:\$scDir/collection:\$PATH # This lines enables you to run script collection, as well as those scripts located in $scDir/collection (eg: rmtf, yumreset) directly from terminal)
source sc.cfg # see sc-README for commands provided.
# ----- Script Collection : Close ----- #
EOF

sea
3rd February 2012, 11:28 AM
Well there is only 1 tarball, the one that contains all the files, as i have been sharing it previously via sourceforge.

Thank you Skull_One, i have applied your suggestion, and got a list of files as output.
But there are no files/folders anymore populated in ~/rpmbuild/BUILDROOT
And it fails now at %prep, rather than previously with %doc.

Ok changed back from %setup to %setup -q -c sc-%{version} and it fails again at %doc.
Since the readme is not a man-file but a script too, i removed it from the docs.
Figured that with your changes it WOULD install the scripts straight to /usr and the ending sc in %prefix is assumed to be filename, but should be foldername, so during the path creating i've added an extra /sc, so the BUILDROOT content looks more comfortable (less reasons for panic cause).

The cat to profile.d, great, havent thought of that, thank you very much!

So far it looks almost working, but it fails to due "file listed twice" :confused:

.... tested something in between...

its working !! :dance:
At least there's a rpm file :D

Thank you guys!

Going to edit first post to update the working spec file for the use of scripts :)