View RPM scripts with rpm --scripts -qp - linux

When I run rpm -qlp I get the file contents of the RPM as you can see below, but when I run rpm --scripts -qp CBS0.0.0_10.0.i386.rpm I get the scripts' contents, but not their filename.
My question is why can't I see the script names in the RPM contents (ie, where does the script s come from?)
$ rpm -qlp CS0.0.0_10.0.i386.rpm
/home/thy_diff/rt
/home/thy_diff/rt/Cerse-zip
/home/thy_diff/rt/Configure_rht.properties
/home/thy_diff/rt/UFE_Install.sh
/home/thy_diff/M_client
/home/thy_diff/M_client/Crse-CLIENT.zip
/home/thy_diff/M_client/Configure_client.properties
/home/thy_diff/M_client/UF_Install.sh

AFAIK scripts are part of RPM package meta-data, there are no files for scripts. The commands of scripts are written directly into spec-file just next to other meta-data like "description" or "license".
For example, see here the %post section. It contains a script of a single command. I believe all other scripts are written just the same.

Try with following command:
rpm -qlp --scripts CS0.0.0_10.0.i386.rpm
You can see the script contents

Related

Get user while packaging rpm

I am trying to get USER-NAME in my spec file while packaging rpm. "$HOME" command gives me USER in case of running in bash.
Spec file also works like bash but when I run the similar command in %post section of spec file, I get 'root' as output.
This might be happening as user run rpm package using sudo.
Kindly help how to get USER name in Spec file
In the .spec a %define macro would get you the username. Here is an example, how it might look like inside the .spec file.
Source0: %{name}-%{version}.tar.gz
# User defined function to get who built the RPM
%define packagername %(who am i | awk '{print $1}')
%description
...
%prep
...
# Then in the post section call the macro %{packagername}
%post
echo "Packager is: %{packagername}"
Note, %post section will be run only when install the .rpm file. Above will print the information into stdout.
Output
$ sudo rpm -ivh simple-0-1.x86_64.rpm
Preparing... ########################################### [100%]
1:simple ########################################### [100%]
Packager is: iamauser
In order to use this macro globally on the system, one can define it inside /etc/rpm/macros.<somename>.
$ cat /etc/rpm/macros.username
# Get who is the packager
%packagername %(who am i | awk '{print $1}')
With the global definition one doesn't need to define it inside the .spec file.
If you don't have permission to write into /etc/rpm, then defining it in ~/.rpmmacros file would make that macro available only to you.

How find file in RPM file

I was looking for a file with a gpg extension, and when I do grep gpg */*, it looks like it's in the rpm file. I'm trying to locate it, but I'm not finding it.
I tried rpm -qpl Directory/filename.rpm, but it's not listing the gpg file. It must be in a subdirectory so it's not turning up.
Does anyone know a good way to get it to list the subdirs out in the rpm, so I can find the gpg file?
you can list all files in a rpm with:
rpm -qlp mypackage.rpm
If you need to extract the rpm:
rpm2cpio mypackage.rpm | cpio -idv

What does it mean in Linux for installing script

I am trying to install some scripts into linux and follwoing line is given as instruction.
Install the xyz script into some convenient directory in $PATH.
but I'm unable to understand what exactly does it mean.How do I install given script in $PATH directory.Script is placed under /users/username/ Dir.
In a terminal type echo $PATH. You will see a list of directories. Put your script, or a link to your script in one of those directories, typically in /usr/local/bin.
its a bad description of the script-author :) usually, in your $PATH are multiple directories mentioned, separated by colon.
you can echo them:
echo $PATH
What the Author means: just copy the script in a directory which is in your $PATH, e.g. /usr/local/bin
$PATH is a list of directories where bash looks for executables.
The given instruction suggests that yours scripts should be put in one of these directories.
An alternative is to put your scripts in any directory and add that directory to $PATH. In your case, add the following line in your $HOME/.bash_profile configuration file:
export PATH=$PATH:/users/username

Passing user defined argument to RPM is possible while installing?

Passing User defined argument to RPM is possible while installing?.
for example:
~>rpm -i sample.rpm -license_path=/path/
or
~>rpm -i -license_path=/path/ sample.rpm
or
~>rpm -i -somearg sample.rpm
-Sakthi
RPMs aren't meant to take user defined arguments.
See RPM - Install time parameters
Another similar question is at https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm
One workaround is to have the rpm's postinstall script ask for input from stdin, in which case you can pass in the answers by redirecting stdio from a file or here document.
>rpm -i sample.rpm <<__NOT_RECOMMENDED__
somearg
__NOT_RECOMMENDED__
It looks like you are trying to create a relocatable RPM.
In the preamble of your .spec file, put the prefix of the file path that can be relocated.
For example, if the full path to your file is
/base/path/to/my/file
then /base can be changed during RPM installation but /path/to/my/file will remain the same.
Here's what you put in your .spec file:
#Preamble: Summary, Name, etc.
Prefix: /base
Ensure that you mention this prefix while listing all relocatable files in the %install and %files sections in the .spec file. There are conditions where a relocatable RPM may not work, so check out these things to consider as well.
%files
%{prefix}/path/to/my/file
Now when you install the RPM, you can specify a different prefix.
rpm -i sample.rpm --prefix /tmp
This will install the file in /tmp/path/to/my/file.

how to update a pre-existing config file using rpmbuild?

I've been looking into how to use an rpmbuild spec file to update an already existing config file.
As an example, in my rpm I'd like to add lines to a config file e.g. /etc/stunnel/stunnel
[SomeAppName]
accept = 8006
connect = 127.0.0.1:5006
I've currently got this in my %install section:
cat stunnel/stunnel.conf >> %{buildroot}/etc/stunnel/stunnel.conf
Now clearly this is rubbish because each time I run the rpm it will add these same lines to the config file.
I also don't want the /etc/stunnel/stunnel.conf file to be part of my rpm as I don't want it removed when I erase my rpm package.
My questions are:
How can I exclude the /etc/stunnel/stunnel.conf from being part of my rpm?
What is the correct way to add lines to a config file during an rpm?
Please could someone provide some links where I can see how to get this working or example of a few lines that I can use in my spec file.
I've look at the official guide over at Max Rpm but so far I've not found the answer to my issue.
a) Many more modern tools also support a .d configuration directory parallel to flat files for this exact reason. For example, my Debian wheezy distribution treats /etc/stunnel as a directory in which each .conf file is a separate stunnel configuration.
b) The established alternative seems to be a conditional construct like
grep -q '[SomeAppName]' %{buildroot}/etc/stunnel/stunnel.conf || cat ...
(or, if not sure if stunnel.conf already exists)
grep -s '[SomeAppName]' %{buildroot}/etc/stunnel/stunnel.conf || cat ...

Resources