File boottest-ramdisk.spec of Package boottest-ramdisk
#
# spec file for package boottest-ramdisk
#
# Copyright (c) 2021 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/
#
%if 0%{?sles_version} == 9
%define os_ver 9
%endif
%if 0%{?sles_version} == 10
%define os_ver 10
%endif
%if 0%{?sles_version} == 11
%define os_ver 11
%endif
%if 0%{?sle_version} >= 120000 && 0%{?sle_version} < 150000
%define os_ver 12
%endif
%if 0%{?sle_version} >= 150000 && 0%{?sle_version} < 160000
%define os_ver 15
%endif
%if 0%{?suse_version} > 1500
%define os_ver 16
%endif
#!BuildIgnore: python3
Name: boottest-ramdisk
Version: 0
Release: 0
Summary: Ramdisk for kernel boot test
Group: Development/Tools
License: GPL-2.0
BuildRequires: kernel-source
BuildRequires: distribution-release
%ifarch x86_64
BuildRequires: xen
%endif
%description
%package %os_ver
Summary: Ramdisk for kernel boot test
Group: Development/Tools
%description %os_ver
%prep
%build
temp=$(mktemp -d)
trap 'rm -rf "$temp"' EXIT
mkdir "$temp/seen"
add_file()
{
local src=$1 dst=$2
if test -e "$temp/seen/$dst"; then
return 1
fi
dirs=($(echo "$dst" | sed -rn ':a; s:/[^/]+$::p; ta' | tac))
for dir in "${dirs[@]}"; do
if test -d "$temp/seen/$dir"; then
continue
fi
echo "dir $dir 0755 0 0" >>"$temp/list"
mkdir "$temp/seen/$dir"
done
echo "file $dst $src 0755 0 0" >>"$temp/list"
touch "$temp/seen/$dst"
return 0
}
add_files()
{
while test $# -gt 0; do
local file=$1
shift
if ! add_file "$file" "$file"; then
continue
fi
set -- "$@" $(ldd "$file" 2>/dev/null | \
sed -ne 's:\t\(.* => \)\?\(/.*\) (0x[0-9a-f]*):\2:p' | \
sort -u)
done
}
add_files /bin/bash
MARKER="It WoRkS"
cat >"$temp/init" <<-EOF
#!/bin/bash
echo
echo $MARKER
echo
poweroff
EOF
add_file "$temp/init" "/init" ||:
cat >"$temp/poweroff.c" <<-EOF
#include <unistd.h>
#include <sys/reboot.h>
int main(int argc, char **argv)
{
reboot(RB_POWER_OFF);
return 0;
}
EOF
gcc -Wall -o "$temp/poweroff" "$temp/poweroff.c"
add_file "$temp/poweroff" "/bin/poweroff" ||:
gcc -Wall -o gen_init_cpio /usr/src/linux/usr/gen_init_cpio.c
./gen_init_cpio "$temp/list" >"$temp/cpio"
cp $temp/cpio initramfs-%os_ver
%install
install -d %{buildroot}/usr/share/%name
install -D -m 644 -t %{buildroot}/usr/share/%name initramfs-%os_ver
%ifarch x86_64
install -D -m 644 /boot/xen.gz %{buildroot}/usr/share/%name/xen-%os_ver
%endif
%post
%postun
%files %os_ver
/usr/share/%name
%changelog