2

I'm creating an rpm installer for a php web application. One of the requirement is to run a php script, an entry script that will update the source, database and execute fix scripts.

To accomplish this requirement, I created a tar file that has the php script and other files needed for the update and stores it on sources directory. And I just needed to call the php script on %post.

%post
cd $RPM_BUILD_ROOT
gunzip %{name}-%{version}.tar
tar -xvf %{name}-%{version}.tar
php install.php

I change directory first to build since I think that is location of tar files. Then uncompress the files and execute the php script. But instead I got the errors below:

gunzip: can't stat: webapp-1.0.tar (webapp-1.0.tar.gz): No such file or directory
tar: Error opening archive: Failed to open 'webapp-1.0.tar'
Could not open input file: install.php

How should I execute the php script? Is this possible?

Also which rpm file should I used to install for final distribution, the one in the directory rpms/i386 or srpms? I'm still developing the rpm.

Any help is appreciated.

[EDIT] I tried to use %setup -c -n %{name} on %post instead of the tar commands. Then I got this message Could not open input file: install.php

  • The problem here is the cd $RPM_BUILD_ROOT command, that doesn't change the directory correctly, because the other commands cannot find the files correctly. You need to find a correct way to change to the desired directory. – Tero Kilkanen Apr 20 '15 at 10:17
  • 1
    Why are you untarring the package at %post? You should be doing this at build time. – Michael Hampton Apr 20 '15 at 14:09
2

if this is a .spec file, use %{buildroot} instead of $RPM_BUILD_ROOT. See the "Macros" chapter here: https://fedoraproject.org/wiki/How_to_create_an_RPM_package

Also try echo %{buildroot} > /tmp/dbg.txt and check /tmp/dbg.txt contents to see where it tries to cd.

I suggest to try using fpm which is able to build all kinds of packages. Just supply the pre-post install scripts as arguments along with the rest. No rpm spec files or deb rule files needed.

  • using cd %{buildroot} still gives an error "No such file or directory" – Pelang Apr 21 '15 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.