Displaying information on non-installed RPM package? - linux

I googled for this, but couldn't find how to query a non-installed RPM file for its information:
# rpm -qa blackfin-jtag-tools-09r1.1-2.i386.rpm
#
# rpm -qi blackfin-jtag-tools-09r1.1-2.i386.rpm
package blackfin-jtag-tools-09r1.1-2.i386.rpm is not installed
#
# rpm -q blackfin-jtag-tools-09r1.1-2.i386.rpm
package blackfin-jtag-tools-09r1.1-2.i386.rpm is not installed
#
# rpm --info blackfin-jtag-tools-09r1.1-2.i386.rpm
RPM version 4.8.0
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL
Usage: rpm [-aKfgpWHqVcdilsKiv?] [-a|--all] [-f|--file] [-g|--group] [-p|--package] [-W|--ftswalk] [--pkgid] [--hdrid] [--fileid]
[--specfile] [--triggeredby] [--whatrequires] [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles]
[--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] [--nofiledigest] [--nomd5] [--nofiles] [--nodeps]
[...]
Is there a command to read information out of non-installed RPM file?

rpm -qip foo.rpm

#crazyscot did answer the question. Thanks.
Additionally, I found that specific querytags can also be leveraged this way, which wasn't obvious from reading the man page.
So, for example, I found I can do the following:
rpm -qp --queryformat '%{ARCH}\n' foo.rpm
or, even:
xyz="ARCH"; rpm -qp --qf %{${xyz}} foo.rpm; echo ""
This works nicely for RPM's that are not installed, and leveraging the available querytags in the installed rpm
Here is more information about tags

When rpm is not-installed then (this will list the complete info, plus the list of contents in the package);
rpm -qipl <rpm_name.rpm>
When rpm is installed then;
rpm -qi <rpm_name.rpm>
For more on rpm-queries.
For more on handy-queries.

Use rpm -qip:
rpm -qip package_path1 [package_path2 ...]
-q - query the package
-p - get the package name from arguments
It shows the following info:
Name
Version
Release
Architecture
Install Date
Group
Size
License
Signature
Source RPM
Build Date
Build Host
Relocations
Packager
Vendor
URL
Summary
Description
The man page doesn't talk about the -i option in -q context. However, rpm -qp file doesn't produce the right output.

less <rpm_name.rpm>
Displays all that I need, same as 'rpm -qlpv'.
Very good resource: https://blog.packagecloud.io/eng/2015/10/13/inspect-extract-contents-rpm-packages/ .

Related - Display Infos For Installed Package :
rpm -qi InstalledPackageName

there are lot of -i option used in above answers , best way to check :
For one rpms,
rpm -qlp <rpm-name>.rpm
For all rpms , search for your file with grep :
rpm -qpl *.rpm|grep <string or file name>

Related

Why doesn't `nix-env -q` find my installed packages? (NixOS channels, profiles and packages)

I recently installed NixOS and I ended up with 3 profiles:
bruno (a user profile),
default (used by root), and
system (used by NixOS).
I found it convenient to use a stable channel for the system profile and an unstable channel for me (bruno profile):
~> nix-channel --list
unstable https://nixos.org/channels/nixos-unstable
~> sudo nix-channel --list
nixos https://nixos.org/channels/nixos-17.09
I have then declaratively installed a few packages through /etc/nixos/configuration.nix:
environment.systemPackages = with pkgs; [
firefox
chromium
htop
# ...
];
And some imperatively: nix-env --install firefox.
Now listing my installed packages, I'd expect to also see the ones provided by the system profile (as they are available in my user profile):
~> htop --version
htop 2.0.2 - (C) 2004-2016 Hisham Muhammad
Released under the GNU GPL.
~> nix-env -q | grep htop
~> nix-env -q | grep firefox
firefox-57.0
Only Firefox is listed. Let's try using the root profile:
~> sudo nix-env -q | grep htop
Same thing, it's actually completely empty.
Maybe using the system profile:
~> sudo nix-env -p /nix/var/nix/profiles/system -q
Still nothing.
Coming from traditional package managers (Debian, Red Hat), I find confusing that Nix being defined as "The Purely Functional Package Manager" does not seem to provide a tool to query packages universally - nix-env is mentioned throughout the manuals and feels like Debian apt's alter ego.
Is there such a tool, or is this a non-problem, that is, people are generally fine with not having a list of all packages present across profiles/environments?
nix-env -q will only report packages that are installed into imperative 'environments', like those created by nix-env -i.
nix-env is a tool for imperative package management that is a thin layer over the otherwise declarative and immutable Nix system. The profiles mechanism provides a means for mutability and nix-env creates manifest.nix in the profile to record the set of packages that are in the environment.
A NixOS system only uses the profiles but does not provide a manifest.nix file. This makes sense, because a NixOS system gets rebuilt from scratch every time, which makes it nicely declarative.
As a consequence nix-env can not query a NixOS profile.
So, nix-env -q queries your imperatively installed user packages. sudo nix-env -q shows those imperatively installed by root, which does not include your NixOS packages, because they are part of your system, declaratively. Pointing nix-env -q -p at your NixOS system gives an empty list, because it's not an environment created by nix-env.
The reason your user can use system commands is not because the system is part of the (Nix) environment in the user profile, but because your (UNIX) environment variables point to both profiles.
$ which firefox
/home/user/.nix-profile/bin/firefox
$ which cp
/run/current-system/sw/bin/cp
$ echo $PATH
[...]
To figure out what is installed on your system, you may run the following commands:
nix-env -q to figure out what is installed in an imperative user environment.
nixos-option environment.systemPackages to query the set of packages that will appear in /run/current-system/sw when your configuration is built and activated. To quote its documentation, "These packages are automatically available to all users."
nix-store -q --requisites /run/current-system ~/.nix-profile the combined closure of dependencies of the current system and your user profile
nix-store -q --references /run/current-system direct dependencies of the current system
See --query section or nix-store --help for more options.

How to build openmpi rpm from srpm cuda aware

I would like to build the OpenMPI 1.10.2 rpm from the srpm.
But I need to build it cuda aware.
According to the documentation (https://www.open-mpi.org/faq/?category=buildcuda) I need to add ./configure --with-cuda
Is there any way to do that while creating the rpm?
I tried:
rpmbuild -bb --with cuda openmpi-1.10.2.spec
rpmbuild -ba openmpi-1.10.2.spec --define '--with-cuda'
But no success.
Use the second one, but edit the spec file. Find the call to ./configure or the %configure macro being called, and add your --with-cuda to that line.
rpmbuild -ba openmpi-1.10.2.spec

repackage an rpm from an installed rpm

On linux can we repackage a installed rpm if so how.I remember that the a rpm can be generated from the installed binaries
rpm -??? > my.rpm
Also the later i.e, the newer rpm should work on a different machine
There is also rpmrebuild
http://rpmrebuild.sourceforge.net
Actually there is a simple but "tricky" way; it is just : rpm -e --repackage package-name
It will output the RPM in /var/spool/repackage/.
Example:
# rpm -e --repackage samba3x-client
# file /var/spool/repackage/samba3x-client-3.5.4-0.83.el5_7.2.i386.rpm
/var/spool/repackage/samba3x-client-3.5.4-0.83.el5_7.2.i386.rpm: RPM v3 bin i386 samba3x-client-3.5.4-0.83.el5_7
Why tricky? Because it actually remove the program prior packaging it, just so you know.
This is possible, but not with the rpm command. I wrote a perl script that does this; it crafts a spec file based on the outputs of rpm -q and does a "build" which just copies the installed files from the system.
You can find it here: https://github.com/cormander/rogue-beret-tools/blob/master/scripts/rpm-repack
Usage example, re-packaging the mailx rpm:
Query it:
$ rpm -ql mailx
/bin/mail
/etc/mail.rc
/usr/bin/Mail
/usr/lib/mail.help
/usr/lib/mail.tildehelp
/usr/share/man/man1/Mail.1.gz
/usr/share/man/man1/mail.1.gz
Repack it:
$ ./rpm-repack -p mailx
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.9773
+ umask 022
+ cd /usr/src/redhat/BUILD
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: mailx-8.1.1-44.2.2
Provides: mailx
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.3) libc.so.6(GLIBC_2.3.4) libc.so.6(GLIBC_2.4) rtld(GNU_HASH)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/tlkN4yrYEi
Wrote: ~/rpmbuild/RPMS/i386/mailx-8.1.1-44.2.2.i386.rpm
Query the newly built package:
$ rpm -qpl ~/rpmbuild/RPMS/i386/mailx-8.1.1-44.2.2.i386.rpm
/bin/mail
/etc/mail.rc
/usr/bin/Mail
/usr/lib/mail.help
/usr/lib/mail.tildehelp
/usr/share/man/man1/Mail.1.gz
/usr/share/man/man1/mail.1.gz
The code isn't at all elegant, but functional. It does copy a lot of the rpm info (everything from rpm -qi and most of the scripts), but it isn't by any means comprehensive. Also, it can't copy the GPG signature, nor will it have the same checksums as the original RPM file.
NOTE: This is not a "proper" way to build and distribute RPM packages, and was mainly written for troubleshooting and educational purposes.
I think that most rpm based distributions how have official package rpmrebuild (or in the almost official 3'rd party repos like epel, rpmfusion ... etc). I think nowadays this would be your best option for repackaging installed packages.

How to determine the OS version for which was compiled rpm?

How can i determine the Linux version (distribution) for which was compiled rpm packet?
I believe this is what you are after.
$ rpm -q gnome-speech --queryformat '%10{NAME} %20{VENDOR} %20{RELEASE} %20{ARCH}\n'
gnome-speech Red Hat, Inc. 1.fc6 i386
$ rpm -q hwdata --queryformat '%10{NAME} %20{VENDOR} %20{RELEASE} %20{ARCH}\n'
hwdata Red Hat, Inc. 1.el5 noarch
There are lots of nifty bits you can go after with queryformat, see this guide for a reference.
General reference on rpm-philosophy-multi-architecture.
There is no such ways to determine the OS name and version from the content of the file.
Normally a RPM file name contains all these details. According to the RPM file naming convention the file name must be like :
name-version-release.architecture.rpm
Please check this link for details.
You can use rpm -q to get the OS data from the OS tag in the RPM, but you need to specify a queryformat as it is not in the normal -i output. You can use -p to refer to a specific RPM file for the testing.
$ rpm -q -p myfiletotest.rpm --queryformat '%10{NAME} %10{OS} %10{VERSION} %10{RELEASE} %10{ARCH}\n'
mypackage linux 2.2.10 1_14.el6 x86_64
The OS name is the second field in this output. The RPM does not distinguish between releases of the OS though; you will only see 'linux', 'aix', 'darwin', and so on - not 'centos-6'.

rpmbuild generates RPM in which subdirectory

rpmbuild generates RPM under which directory?
I checked the RPMS directory:-
[root#tom adil]# ls /usr/src/redhat/
BUILD RPMS SOURCES SPECS SRPMS
[root#tom adil]# ls /usr/src/redhat/RPMS/
athlon i386 i486 i586 i686 noarch
[root#tom adil]#
How to decide rpmbuild outputs in which of the above sub-directories?
Is it controlled by spec file? What is the default option?
I thought uname -p but its not the case probable uname -i is used.
Linked to my last question Difference between "machine hardware" and "hardware platform"
The binary package is named according to the %_build_name_fmt macro. By default this macro contains %{ARCH}/ at the beginning, so that is where the binary package is placed.
Following on from your last comment, by default the RPM will go into the subdirectory that matches the platform you're building on. You can override this by passing the --target parameter to rpmbuild, but this only applies where valid; for example, you can use --target i386 on an x86_64 system to build a 32-bit RPM, but you can't build a 64-bit RPM on a 32-bit platform.
The RPM goes to the RPMS folder and the source RPM to the SRPMS. This is not controlled by the spec file - this is convention. What exactly are you trying to do?

Resources