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_with debug

Name:           initrd
Version:        0
Release:        0
Summary:        initrd based on systemd
License:        MIT
Source0:        mkmoduleinitrd
Source1:        solve_and_install
# 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
%if 0%{?suse_version}
BuildRequires:  openSUSE-release
BuildRequires:  openSUSE-release
BuildRequires:  openSUSE-release-appliance-custom
BuildRequires:  systemd-presets-branding-openSUSE
BuildRequires:  device-mapper
%endif
%if 0%{?debian}
BuildRequires:  dash
BuildRequires:  base-files
%endif
BuildRequires:  dbus-broker
# XXX: for extra udev rules
BuildRequires:  dracut
%if %{with debug}
BuildRequires:  lsof krb5 strace procps xterm-resize
%endif
BuildRequires:  busybox-static

%description

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

%build
chmod 755 %{SOURCE1}
%{SOURCE1} "packages" initrd

cd initrd
# remove unneded stuff
rm -rf usr/share/doc usr/share/man usr/share/info
#
sed -i -e '/^NAME=/s/"$/ initrd"/' etc/os-release
echo 'ANSI_COLOR="0;36"' >> etc/os-release
ln -s os-release etc/initrd-release
#ln -s usr/lib/systemd/systemd init
cat > init <<'EOF'
#!/bin/sh
echo "executed initrd $0"
if grep -q rd.break /proc/cmdline; then
	echo "Initrd shell due to rd.break. press ^D to continue"
	/bin/sh -i < /dev/console > /dev/console 2>&1
fi
exec /usr/lib/systemd/systemd
EOF
chmod 755 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
ln -s ../bin/busybox sbin/sulogin
ln -s ../bin/busybox bin/grep
# 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