I have an RPM that installs a shell script. Puppet code needs to access this RPM, retrieve the shell script packaged in the RPM and execute it. How do I do that?
You can extract rpm scriptlets by
rpm -qp --script foo.rpm
Just beware that it contains ALL scripts (%pre, %post, %postun...) so you need to use sed or something similar to extract just that one script, save it to file and the run.
You'll need a package statement to install the rpm, and then an exec to run the shell script. Assuming your rpm is called my-shellscript.rpm, and is located in your module's files directory, and the rpm defines the install location as /tmp/my-shellscript.sh, then you'll have something like this,
class example {
package { 'my-shellscript.rpm' :
ensure => 'installed',
provider => 'rpm',
source => 'puppet:///modules/example/my-shellscript.rpm',
}
exec { 'my-shellscript.sh':
command => '/tmp/my-schellscript.sh',
require => Package['my-shellscript.rpm'],
}
}
To execute the script from your code, you need to perform the following steps :
Extract the contents of your rpm in some temporary directory.You can use rpmcpio utility for that.
rpm2cpio test.rpm |cpio -idmv
Find the location of script in your rpm file. you can use rpm command for that.
rpm -qpl test.rpm |grep "script.sh"
In your code, execute the script from the temporary location where you had extracted your rpm contents.
sh /tmp/test/xxx/script.sh
Related
I want to copy the installed rpm file to some directory during %post. Like
%post
cp rpm_path %_prefix/rpm/
Is there any way to get rpm file path in spec file?
It is not possible.
However, you can achieve it on the DNF level, by using local plugin. Or writing a similar plugin.
https://github.com/rpm-software-management/dnf-plugins-core/blob/master/plugins/local.py
Can someone please list out the directories where the Apache RPM install files.
I searched over Internet but was not able to find any proper solution
You can use the query files list option of rpm command to find out the directory.
If you have installed the package
rpm -ql <package-name>
and if you have the rpm file
rpm -qlp <package-name>.rpm
You will get something like this(the sample is for httpd)
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf/extra/httpd-autoindex.conf
/etc/httpd/conf/extra/httpd-dav.conf
/etc/httpd/conf/extra/httpd-default.conf
/etc/httpd/conf/extra/httpd-info.conf
/etc/httpd/conf/extra/httpd-languages.conf
//
//Output truncated
The sample output shows /etc/httpd is a folder that httpd creates/installs to
Add the very verbose flag to the rpm command line to see all it does. E.g.:
rpm -Ivv <packagefile.rpm>
I have created an rpm without source using the binary file I had been provided. In a nutshell, I am trying to automate a silent install of sybase client via an rpm. However I need help whether we can put the following silent install command in the %install section of the spec file -
setup.bin –f <responseFileName> -i silent -DAGREE_TO_SYBASE_LICENSE=true -DRUN_SILENT=true
Any help will be much appreciated.
If you want a script to be executed when you install a package, it must be put in the %post section. According to your comment, this is what you did.
The problem is that if you run the install script that way, rpm will not be able to track the installed files. It will not know that those files belong to the package, will not remove them when you uninstall the rpm, will not handle updates properly, etc. You will have a broken rpm.
If you can't build a proper rpm, just use a simple install script that does what you want.
I am working with RPM package manager for about a month now. Currently I want to use rpm -U to upgrade already existing content from previous RPM execution but I need to know the rpm package location on the file system.
The only way I can think of is searching whole file system for rpm name in %pre script but I would really like to avoid that option. Is there any way to get the path of the rpm package (package can be anywhere on the system) as a variable inside the spec file (%pre and %post script). Hope I explained my issue clearly enough.
Any help or proposal is welcome.
There isn't one location (or path) where a package is installed,
so I'm not sure what you are asking.
The files that are installed by a installed rpm package called "foo"
can be displayed with
rpm -ql foo
There is no common prefix on the paths except "/" in general.
I am using Fedora 10, I have created an rpm file for my software. It removes all the files from the installed directory. If i use yum remove command or rpm -e command. but after installation my application automatically creates some extra folders in home directory. If I uninstall my application then file from home directories do not get removed. So what I have to do. Is there anything that I have to write in my spec file?
You need to create a post-uninstall script inside your rpm.
The %postun Script
The %postun script executes after the package has been removed. It is the last chance for a package to clean up after itself. Quite often, %postun scripts are used to run ldconfig to remove newly erased shared libraries from ld.so.cache.
See: Maximum RPM: Taking the Red Hat Package Manager to the Limit