rpmbuild change compression format - compression

I try to pack some map files for our geoserver in an internal rpm package. For the build part, this is just to copy the files. I think this works as expected. But it takes terribly long to pack those 20GB of images.
I've read that rpm internally compresses the data and that this can be done with several different compression algorithms. But, I don't have a clue which compression my rpm chooses and how I can influence this. I could not find any options for the rpmbuild command, nor for the specfile nor for the general rpm options I can list with rpmbuild --showrc
I´m not very experienced with rpmbuild and specfiles, but after reading lots of man pages and tutorials on rpm.org I have no further ideas.
The specfile I use looks like:
%define debug_package %{nil}
%global mapsversion 0.9
# If this is a snapshot, put the date here and uncomment
#global snapshot_version 20100519
# This is the version in a form acceptable
# an an RPM version string (i.e. no '-')
# Hier werden die Makros definiert.
%global rpmversion %(echo %{mapsversion} | tr '-' '_')
%global pkgversion %{mapsversion}%{?snapshot_version:-SNAPSHOT}
%global pkgname %{name}
Name: geoserver-maps-part2
Version: %{rpmversion}
Release: 1%{?dist}
Summary: Swiss Maps for GeoServer
Group: Application/ourApp
License: Copyright (c) 2011
URL: http://doc.polyalert.local
#Source0: %{name}-%{version}.tgz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: geoserver
%define mapshome /opt/geoserver/swisstopo
%define mapssource /home/user/polyalert_env/geoserver/swisstopo
%description
Swiss Maps for GeoServer
%prep
%build
/bin/true
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{mapshome}
cp -a %{mapssource}/pk100 $RPM_BUILD_ROOT%{mapshome}
%clean
rm -rf $RPM_BUILD_ROOT
%pre
%post
%preun
%files
%{mapshome}/pk100
%changelog
* Tue Feb 14 2012 user - 1.0
- First version of specfile
I call rpmbuild like this:
rpmbuild -bb --define "_topdir $TOP_DIR" --define "_gpg_name ourkey" --define "_signature gpg" --sign $TOP_DIR/SPECS/$SPEC_FILE_NAME $RPM_BUILD_PARAMETER
Any suggestions?

I was working with some RPM stuff today and accidentally stumbled upon the answer for ya!
Put these in your spec file:
%define _source_payload w0.gzdio
%define _binary_payload w0.gzdio
That will still use gzip but pass it -0 for a level, which should just store. On my RPM, it made it grow from 21MB to 76MB, so I'm pretty sure this is your answer!
BTW, I found that in one of the macro files - you can also do bzdio and any number from 0 to 9 to use bzip2. This was on RHEL4; later versions of RPM seem to support more compression options; but again, for what you want, the above should be what you need.

Please check the file /usr/lib/rpm/macros in your build machine, (the file maybe diff in path), it has a total support list of compression methods there: e.g.:
329 # Compression type and level for source/binary package payloads.
330 # "w9.gzdio" gzip level 9 (default).
331 # "w9.bzdio" bzip2 level 9.
332 # "w7.xzdio" xz level 7, xz's default.
333 # "w7.lzdio" lzma-alone level 7, lzma's default
334 #
335 #%_source_payload w9.gzdio
336 #%_binary_payload w9.gzdio
so here just as Aaron said, you can set it here for universal, or set specifically for your proj. spec.

I have used "%define _binary_payload w9.xzdio" on RHEL 6.6. As I understand, the default compression tool used in RHEL 6 is xz, but the default compression level appears to be 2, even though 7 is supposed to be xz's default. I kicked it up to 9 and some giant RPMs went from 653MB to 439MB. I was able to save a total of 1 gigabyte over the default compression.

I ran into the same issue with Ant building a runnable Jar RPM with Spring Boot Loader complaining of this:
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/accessors-smart-1.2.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
My ant build task was like this:
<exec executable="rpmbuild" failonerror="true">
<env key="version" value="${fullversion}" />
<arg value="-ba" />
<arg value="--clean" />
<arg value="${specfile}" />
</exec>
My solution to build an RPM with a runnable JAR was to disable the repacking, setting the macro definitions on the spec file did not do it for me.
Adding this to the spec file was what worked for me:
#Disable jar unpacking
%define __jar_repack 0
Reference:
https://bugzilla.redhat.com/show_bug.cgi?id=219731
Thanks to the previous posters for helping to focus in on the issue too.
Erion

Related

Failure to "opam init", how to manually specify index.tar.gz?

I cannot opam init:
$ opam init --verbose
[NOTE] Will configure from built-in defaults.
Checking for available remotes: rsync and local, git, mercurial.
- you won't be able to use darcs repositories unless you install the darcs command on your system.
<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Could not update repository "default": OpamDownload.Download_fail(_, "Curl failed: \"/usr/bin/curl --write-out %{http_code}\\\\n --retry 3 --retry-delay 2
--user-agent opam/2.0.7 -L -o /tmp/opam-1697-6d07ae/index.tar.gz.part https://opam.ocaml.org/index.tar.gz\" exited with code 28")
[ERROR] Initial download of repository failed
However, I've manually downloaded index.tar.gz. How to manually specify index.tar.gz to opam init?
System info:
$ uname -a
CYGWIN_NT-10.0-19043 xxx 3.4.5-1.x86_64 2023-01-19 19:09 UTC x86_64 Cygwin
P.S. I'm trying to build one project using OCaml, but it turned out that it is very tricky: either OCaml complains about compatibility (is not a compiled interface for this version of OCaml followed by It seems to be for an older version of OCaml; does it mean that OCaml is not backward compatible?), either opam init fails, either <whatever>.
Your error message indicates that you either have network problems or very poor connection. Also, you opam version is very old, so it might not handle bad networks very well, I would suggest your installing a newer version of opam (at least 2.1.x), or, if it is possible, switching to docker or a virtual machine.
Answering your original question: I don't think there is a way (at least officially supported to specify your own downloaded index). Also, if you have trouble with downloading the index it most likely means that you will have more trouble in the future with your network when opam will start downloading actual packages.

Need a better understanding of installing AWS-Nuke for Mac

Im sure this this just a lack of knowledge on my end but im having a hard time understand how to install aws-nuke following there documentation. I have downloaded the latest release but install instructions are not so clear for me https://github.com/rebuy-de/aws-nuke#:~:text=Use%20Released%20Binaries,Run%20%24%20aws%2Dnuke%2Dv2.16.0%2Dlinux%2Damd64
Any suggestions would be appreciated.
On a Mac you can run aws-nuke using the following steps:
Open a terminal (Command + Space and write terminal)
Grab the latest version of the aws-nuke. Currently the latest version is 2.17.0 but obviously this will change in the future. In order to download aws-nuke, we can run the following command:
For M1 Mac:
wget https://github.com/rebuy-de/aws-nuke/releases/download/v2.17.0/aws-nuke-v2.17.0-darwin-arm64.tar.gz
For intel Mac:
wget https://github.com/rebuy-de/aws-nuke/releases/download/v2.17.0/aws-nuke-v2.17.0-darwin-amd64.tar.gz
Extract the package using the following command (note: use amd64 instead of arm64 if you are on an intel Mac):
tar -xvf aws-nuke-v2.17.0-darwin-arm64.tar.gz
Create a config.yml file with the following content and place it nearby the extracted executable:
regions:
- global
account-blocklist:
- "999999999999" # leave it as it is, since the current version wont work if you don't provide a blocklist
accounts:
"000000000000": {} # fill in your own AWS account number
Run the following command:
./aws-nuke-v2.17.0-darwin-arm64 -c config.yml
This should list the resources which might be deleted. If you are ok with the list, append --no-dry-run to the previous command.

Abnormally large drivers/modules directories when building a custom kernel on Ubuntu 18.04 / 20.04

I'm currently tiptoeing into custom kernel building.
I first started on a VM in VirtualBox, installing a fresh distribution of Ubuntu Server 20.04.
I followed the following procedure:
# getting the archive
cd ~/src/linux/
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.91.tar.xz
tar -xf linux-5.4.91.tar.xz
cd linux-5.4.91/
# getting the config of the kernel currently running
cp -v /boot/config-$(uname -r) .config
# adapting the config to the target kernel, selecting the default for everything
make oldconfig
# adding manually a suffix to the kernel name: "-tony"
make menuconfig
# building and installing modules & image
time make -j $(nproc)
sudo make modules_install
sudo make install
Everything goes fine, although the build takes a bit longer than expected (~30 minutes on a 6-core AMD Ryzen 5 3600 6-Core Processor, with 32 GB of RAM; I assigned 6 CPUs over the 12 available to the VM).
However, when I check the size of the source directory, now containing the object files of everything built, the size of the drivers directory bothers me:
user#vm:~/src/linux/linux-5.4.91$ du -hd 1
1.3G ./fs
544K ./certs
34M ./block
128K ./usr
41M ./tools
208K ./LICENSES
58M ./security
48M ./Documentation
3.4M ./init
58M ./include
895M ./sound
73M ./lib
5.1M ./ipc
95M ./crypto
2.0G ./net
2.2M ./samples
446M ./arch
5.2M ./scripts
195M ./.git
4.8M ./virt
142M ./kernel
56M ./mm
13G ./drivers
20G .
13 GB looks like a lot.
When I look at the installed files, the modules also looks very big (5.6G):
root#vm:/# find -name '*5.4.91*' | xargs du -hs
20G ./home/user/src/linux/linux-5.4.91
105M ./home/user/src/linux/linux-5.4.91.tar.xz
5.6G ./usr/lib/modules/5.4.91-tony+
4.0K ./var/lib/initramfs-tools/5.4.91-tony+
912M ./boot/initrd.img-5.4.91-tony+
232K ./boot/config-5.4.91-tony+
12M ./boot/vmlinuz-5.4.91-tony+
4.5M ./boot/System.map-5.4.91-tony+
Especially when I compare with the vanilla kernel installed with the distribution:
root#vm:/# find -name '*5.4.0-62*' | xargs du -hs
...
262M ./usr/lib/modules/5.4.0-62-generic
4.0K ./usr/lib/modprobe.d/blacklist_linux_5.4.0-62-generic.conf
4.0K ./var/lib/initramfs-tools/5.4.0-62-generic
...
12M ./boot/vmlinuz-5.4.0-62-generic
79M ./boot/initrd.img-5.4.0-62-generic
236K ./boot/config-5.4.0-62-generic
4.6M ./boot/System.map-5.4.0-62-generic
262M vs 5.6G seems like a lot of difference, taken into account that I took the same config file (the cp -v /boot/config-$(uname -r) .config command).
I also reproduced the same results on Ubuntu Server 18.04.
Moreover, I tried on my host directly (no VM) with again the same results.
I am obviously missing something here, but I cannot find what:
should I strip the kernel / the modules from unused symbols?
is there a configuration that is missing somewhere ?
Thank you in advance for your help!
Disabling CONFIG_SLUB_DEBUG, CONFIG_DEBUG_INFO and CONFIG_DEBUG_MISC in the kernel configuration resulted in reasonable build performance:
real 22m19.559s
user 119m17.273s
sys 12m15.424s
And the following size for the modules:
root#vm:/usr/lib/modules# du -hs *
261M 5.10.10-stripped+
262M 5.4.0-64-generic
Which is even better than the shipped kernel :) (notice I updated the kernel source, but it doesn't change the result if using the same kernel).
Apparently, one can also use make modules_install INSTALL_MOD_STRIP=1 to strip the modules when they are built with debug symbols, reducing the size without having to change the build options.
Installing with that option on the already-stripped kernel & modules as described above resulted in the following size:
user#vm:/usr/lib/modules$ du -hs *
260M 5.10.10-stripped+
262M 5.4.0-64-generic
We effectively gain one more megabyte from this additionnal stripping.

Create FreeXL rpm for CentOS 7: spec file?

I'm trying to build a spec file to create rpm for FreeXL con CentOS 7.
If I try to execute these steps manually
tar xzf freexl-1.0.2.tar.gz
cd freexl-1.0.2
export MAKEFLAGS='-j2'
./configure --prefix=/usr/local && make && make install
all works fine I can see under /usr/local/..... the files aboout FreeXL.
I've tried to "translate" these steps in a spec file ... here you are it
#
# spec file for package freexl
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
%define libname lib%{name}1
Name: freexl
Version: 1.0.2
Release: 1.my
Summary: Library to extract valid data from within an Excel
License: MPL-1.1 or GPL-2.0+ or LGPL-2.1+
Group: Development/Libraries/C and C++
Url: https://www.gaia-gis.it/fossil/freexl/index
Source: http://www.gaia-gis.it/gaia-sins/%{name}-%{version}.tar.gz
BuildRequires: gcc-c++
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
FreeXL is an open source library to extract valid data from within an Excel (.xls) spreadsheet.
%package -n %{libname}
Summary: Shared library for FreeXL
Group: System/Libraries
%description -n %{libname}
FreeXL is an open source library to extract valid data from within an Excel (.xls) spreadsheet.
%package devel
Summary: Development files for %{name}
Group: Development/Libraries/C and C++
Requires: %{libname} = %{version}
Requires: glibc-devel
%description devel
This package contains all necessary include files and libraries needed
to compile and develop applications that use libspatialite.
#redefine path ...
%define _bindir /usr/local
%prep
%setup -q
%build
%configure
%install
./configure --prefix=%_bindir && make && make install
%changelog
I obtain my freexl-debuginfo-1.0.2-1.csi.x86_64.rpm file but when I try to install it nothing is installed (and no errors are shown during installation ....
I think that probably there are some errors in my spec file ...... any suggestions / examples?
I've solved: the problem was that my spec file was not complete ....
Here you're a correct spec file that works fine ....
https://build.opensuse.org/package/view_file/openSUSE:Factory/freexl/freexl.spec?expand=1
It works for CentOS 7 too!

How to parse multi line records (with awk?)

I'm trying to figure out how to extract particular fields from multi line records separated by \n\n.
In this instance, it happens to be output from apt-cache akin to DEBIAN control files. See output of apt-cache show "$package"
Package: caffeine
Priority: optional
Section: misc
Installed-Size: 641
Maintainer: Reuben Thomas <rrt#sc3d.org>
Architecture: all
Version: 2.8.3
Depends: python3:any (>= 3.3.2-2~), python3, gir1.2-gtk-3.0, gir1.2-appindicator3-0.1, python3-xlib, python3-pkg-resources, libnet-dbus-perl
Filename: pool/main/c/caffeine/caffeine_2.8.3_all.deb
Size: 58774
MD5sum: 4438db3f6d1cf43a4f4b49cc7f24cda0
SHA1: e748370ac5ccd7de6fc9466ce0451d2e90d179d4
SHA256: ae303b4e32949cc1e1af80df7217e3406291679e3f18fa8f78a5bbb97504c4f6
Description-en: Prevent the desktop becoming idle in full-screen mode
Caffeine stops the desktop becoming idle when an application
is running full-screen. A desktop indicator ‘caffeine-indicator’
supplies a manual toggle, and the command ‘caffeinate’ can be used
to prevent idleness for the duration of any command.
Description-md5: 7c14f8adc007b10f6ecafed36260bedb
Package: caffeine
Priority: optional
Section: misc
Installed-Size: 655
Maintainer: Reuben Thomas <rrt#sc3d.org>
Architecture: all
Version: 2.6+555~ubuntu14.04.1
Depends: python:any (<< 2.8), python:any (>= 2.7.5-5~), python, gir1.2-gtk-2.0, gir1.2-appindicator3-0.1, x11-utils, python-dbus
Filename: pool/main/c/caffeine/caffeine_2.6+555~ubuntu14.04.1_all.deb
Size: 58604
MD5sum: 1051c3f7d40d344f986bb632d7436849
SHA1: 5e5f622595e8cbba8fb7468b3cffe2914b0ba110
SHA256: 11c5bbf2d28dcda6a7b82872195f740f1f79521b60d3c9acea3037bf0ab3a60e
Description: Prevent the desktop becoming idle
Caffeine allows the user to prevent the desktop becoming idle,
either manually or when certain applications are run. This
prevents screen-blanking, locking, suspending, and so on.
Description-md5: 738866350e5086e77408d7a9c7ffa59b
Package: caffeine
Status: install ok installed
Priority: optional
Section: misc
Installed-Size: 794
Maintainer: Isaiah Heyer <freshapplepy#gmail.com>
Architecture: all
Version: 2.4.1+478~raring1
Depends: dconf-gsettings-backend | gsettings-backend, python (>= 2.6), python-central (>= 0.6.11), python-xlib, python-appindicator, python-xdg, python-notify, python-kaa-metadata
Description: Caffeine
A status bar application able to temporarily prevent the activation
of both the screensaver and the "sleep" powersaving mode.
Description-md5: 1c29acf1ab0f2e6636db29fbde1d14a3
Homepage: https://launchpad.net/caffeine
Python-Version: >= 2.6
My desired output is one line per record in the format apt-get download $pkg=$ver -a=$arch. Basically a list of the installation commands for available packages...
So far what I've got is apt-cache show "$package" | awk '/^Package: / { print $2 } /^Version: / { print $2 } /^Architecture: / { print $2 }' | xargs -n3 | awk '{printf "apt-get download %s=%s -a=%s\n", $1, $3, $2}'
This is the actual output:
apt-get download caffeine=2.8.3 -a=all
apt-get download caffeine=2.6+555~ubuntu14.04.1 -a=all
apt-get download caffeine=2.4.1+478~raring1 -a=all
The is as desired but it appears to be a fluke only because the order of the fields is consistent in this example. It would break if the order of fields was different.
I can do parsing like this using object orientation in Python but I'm having difficulty getting this done in one awk command. The only way I can see doing this correctly would be to split each record into individual tmp files (using split or something along those lines) and then parse each file individually (which is straightforward). Obviously I'd really like to avoid unnecessary I/O as this seems like something that awk is well equipped for. Any awk pro's know how to solve this? I'd even be open to a Perl one-liner or utilizing bash but I'm really interested in learning how to better leverage awk.
$ package=sed
$ apt-cache show "$package" | awk '/^Package: /{p=$2} /^Version: /{v=$2} /^Architecture: /{a=$2} /^$/{print "apt-get download "p"="v" -a="a}'
apt-get download sed=4.2.1-10 -a=amd64
How it works
/^Package: /{p=$2}
Save the package information in variable p.
/^Version: /{v=$2}
Save the version information in variable v.
/^Architecture: /{a=$2}
Save the architecture information in variable a.
/^$/{print "apt-get download "p"="v" -a="a}
When we reach a blank line, print out the information in the desired form.
My version of apt-cache always outputs a blank line after each package. Your sample output is missing the last blank line. If your apt-cache genuinely does not produce that last blank line, then we will need to add a little bit more code to compensate.
As a matter of style, some may prefer printf to print. In which case, replace the above with:
/^$/{printf "apt-get download %s=%s -a=%s\n",v,p,a}'
I find the best way to deal with data that contains name to value pairings is to create an array of those pairs and then just access the values by their names:
$ cat tst.awk
BEGIN { RS=""; FS="\n" }
{
delete n2v
for (i=1;i<=NF;i++) {
if ($i !~ /^ /) {
name = gensub(/:.*/,"","",$i)
value = gensub(/[^:]+:\s+/,"","",$i)
n2v[name] = value
}
}
printf "apt-get download %s=%s -a=%s\n",
n2v["Package"], n2v["Version"], n2v["Architecture"]
}
$ awk -f tst.awk file
apt-get download caffeine=2.8.3 -a=all
apt-get download caffeine=2.6+555~ubuntu14.04.1 -a=all
apt-get download caffeine=2.4.1+478~raring1 -a=all
The above uses a couple of gawk extensions but is easily adapted to any awk if necessary.