File initrd.spec of Package initrd

#
# spec file for package initrd
#
# Copyright (c) 2023 SUSE LLC
#
# 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.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# needsbinariesforbuild

%bcond debug 0

Name:           initrd
Version:        0
Release:        0
Summary:        initrd based on systemd
License:        MIT
Source0:        mkmoduleinitrd
# XXX: black OBS magic
#!BuildIgnore:  krb5-mini
#!BuildIgnore:  libsystemd0-mini
#!BuildIgnore:  libudev-mini1
#!BuildIgnore:  udev-mini
#!BuildIgnore:  systemd-mini
BuildRequires:  --ignoreignore--
###
BuildRequires:  systemd
BuildRequires:  udev
BuildRequires:  libudev1
BuildRequires:  libsystemd0
BuildRequires:  zstd
BuildRequires:  libsolv-tools
BuildRequires:  openSUSE-release
BuildRequires:  openSUSE-release
BuildRequires:  openSUSE-release-appliance-custom
BuildRequires:  dbus-broker
BuildRequires:  systemd-presets-branding-openSUSE
BuildRequires:  device-mapper
# XXX: for extra udev rules
BuildRequires:  dracut
%if %{with debug}
BuildRequires:  lsof krb5 strace procps xterm-resize
BuildRequires:  busybox-static
%endif

%description

%prep
for pkg in /.build.binaries/*.rpm; do
	ln -s "$pkg" "$(rpm -qp --qf '%{nevra}.rpm\n' $pkg)"
done

rpms2solv /.build.binaries/*.rpm > packages.solv

cat > packages.t <<EOF
system %_build_arch rpm
repo repo 50 solv packages.solv
solverflags ignorerecommended
solverflags addalreadyrecommended
job favor name openSUSE-release
job install name systemd
job install name udev
job install name openSUSE-release
job install name dbus-broker
job install name systemd-presets-branding-openSUSE
job install name device-mapper
%if %{with debug}
job install name lsof
job install name strace
job install name procps
job install name xterm-resize
job install name busybox-static
%endif
EOF
cat packages.t

%build
testsolv packages.t > result
cat result
if grep -q "Found.*problems" result; then
	exit 1
fi

extract() {
  rpm2cpio "$1" | cpio -id
  find -type d -not -perm '/0200' | xargs --no-run-if-empty chmod u+w
  mkdir -p usr/lib/sysimage/rpm-headers
  dd if="$1" of="usr/lib/sysimage/rpm-headers/${1##*/}" bs=96 count=1
}
mkdir -p initrd
cd initrd
extract /.build.binaries/filesystem.rpm
while read -r dash nevra; do
	[ "$dash" = '-' ] || continue
	extract "../$nevra.rpm"
done < ../result
# remove unneded stuff
rm -rf usr/share/doc usr/share/man usr/share/info
#
ln -s os-release etc/initrd-release
ln -s usr/lib/systemd/systemd init
> usr/.updated
mkdir sysroot
mkdir -p etc/systemd/system/basic.target.wants
ln -s /usr/lib/systemd/system/debug-shell.service etc/systemd/system/basic.target.wants/debug-shell.service
# need to be able to resolve root
#sed -e '/^#\|^$/d;s/^\(group:\s*compat\)$/\1 [SUCCESS=merge] systemd/;s/^\(\(passwd\|shadow\):\s*compat\)/\1  systemd/' usr/etc/nsswitch.conf > etc/nsswitch.conf
#echo 'root:x:0:0:root:/root:/bin/bash' > etc/passwd
#echo 'root::17275::::::' > etc/shadow
SYSTEMD_LOG_LEVEL=info systemd-sysusers --root="$PWD"
SYSTEMD_LOG_LEVEL=info systemctl --root="$PWD" preset-all
# XXX wtf. without this crypt devices won't be recognized
mkdir -p etc/udev/rules.d
cp /usr/lib/dracut/modules.d/90dm/*.rules etc/udev/rules.d
#

%install
install -D -m 755 "%SOURCE0" $RPM_BUILD_ROOT/usr/bin/mkmoduleinitrd
mkdir -p $RPM_BUILD_ROOT/usr/lib/initrd
cd initrd
find -print0 | cpio --format newc --null -R root:root -o --quiet | zstd -3 -T0 -q > $RPM_BUILD_ROOT/usr/lib/initrd/30-systemd

%files
/usr/bin/mkmoduleinitrd
/usr/lib/initrd

%changelog

openSUSE Build Service is sponsored by