#
# spec file for package openstack-ironic-image
#
# 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/
#
# needsrootforbuild
# needsbinariesforbuild


Name:           ironic-ipa-ramdisk
Version:        3.0.8
Release:        0
Summary:        Kernel and ramdisk image for OpenStack Ironic
License:        SUSE-EULA
Group:          System/Management
URL:            https://github.com/SUSE-Cloud/
Source0:        config.sh
Source10:       ironic-ipa-ramdisk.kiwi
Source20:       root

BuildRequires:  -post-build-checks
BuildRequires:  bash
BuildRequires:  kiwi
BuildRequires:  kiwi-tools
BuildRequires:  zypper
BuildArch:      noarch

BuildRequires:  checkmedia
BuildRequires:  acl
BuildRequires:  ca-certificates-mozilla-prebuilt
BuildRequires:  cracklib-dict-full
BuildRequires:  cron
BuildRequires:  dbus-1
BuildRequires:  elfutils
BuildRequires:  filesystem
BuildRequires:  fipscheck
BuildRequires:  fontconfig
BuildRequires:  fonts-config
BuildRequires:  gptfdisk
BuildRequires:  grub2
%ifarch x86_64
BuildRequires:  grub2-x86_64-efi
%endif
%ifarch aarch64
BuildRequires:  grub2-arm64-efi
%endif
BuildRequires:  haveged
BuildRequires:  hdparm
BuildRequires:  hwinfo
BuildRequires:  ipmitool
BuildRequires:  iproute2
BuildRequires:  iputils
BuildRequires:  kernel-default
BuildRequires:  kernel-firmware-all
BuildRequires:  lvm2
BuildRequires:  net-tools
BuildRequires:  ntp
BuildRequires:  open-iscsi
BuildRequires:  openssh
BuildRequires:  openstack-ironic-python-agent
BuildRequires:  pam-config
BuildRequires:  parted
BuildRequires:  patterns-base-minimal_base
BuildRequires:  pinentry
BuildRequires:  pkgconfig
BuildRequires:  Mesa-gallium
BuildRequires:  plymouth
BuildRequires:  plymouth-scripts
BuildRequires:  python311-proliantutils
BuildRequires:  psmisc
BuildRequires:  qemu-tools
BuildRequires:  sg3_utils
BuildRequires:  sles-release
BuildRequires:  sudo
BuildRequires:  suse-build-key
BuildRequires:  systemd-presets-branding-SLE
BuildRequires:  timezone
BuildRequires:  udev
BuildRequires:  vim
BuildRequires:  wpa_supplicant
BuildRequires:  dhcp-client
BuildRequires:  which
BuildRequires:  NetworkManager
BuildRequires:  nm-configurator
BuildRequires:  logrotate
BuildRequires:  plymouth-dracut
BuildRequires:  plymouth-theme-bgrt
BuildRequires:  dracut-kiwi-oem-dump
BuildRequires:  dracut-kiwi-oem-repart
BuildRequires:  grub2-branding-SLE
BuildRequires:  open-iscsi
BuildRequires:  plymouth-branding-SLE
BuildRequires:  lshw
BuildRequires:  kbd
BuildRequires:  dmidecode
BuildRequires:  efibootmgr
%ifarch x86_64
BuildRequires:  syslinux
%endif

%description
Kernel and ramdisk image for use with Metal3

%package %{_arch}
Summary:        Kernel and ramdisk image for Metal3
Group:          System/Management
Provides:       openstack-ironic-python-agent = %{version}
Obsoletes:      openstack-ironic-python-agent < %{version}

%description %{_arch}
Kernel and ramdisk image for use with Metal3
For %{_arch}

%prep
mkdir -p /tmp/openstack-ironic-image/build /tmp/openstack-ironic-image/img

cp -a %{SOURCE0} /tmp/openstack-ironic-image/config.sh

cp -a %{SOURCE10} /tmp/openstack-ironic-image/config.kiwi

cp -ar %{SOURCE20} /tmp/openstack-ironic-image/root

%build
if ! which kiwi; then
    cat <<EOF >&2
kiwi not found in \$PATH; most likely this build was missing
the --userootforbuild option.  If you are invoking osc build
manually, please use 'make buildlocal' instead.
EOF
    exit 1
fi

kiwi-ng --debug --profile default system build --description /tmp/openstack-ironic-image --target-dir /tmp/openstack-ironic-image/img

%install
TDIR=`mktemp -d /tmp/openstack-ironic-image.XXXXX`
cd /tmp/openstack-ironic-image/img/build/image-root 
find . | cpio --create --format=newc --quiet > $TDIR/initrdtmp
cd $TDIR
zstd initrdtmp -o initrd-%{_arch}.zst
INITRD=`ls *.zst | head -1`

ls /tmp/openstack-ironic-image/img/openstack-ironic-image*
KERNEL=`ls /tmp/openstack-ironic-image/img/openstack-ironic-image*default*kernel | head -1`

mkdir -p %{buildroot}/srv/tftpboot/openstack-ironic-image
install -p -m 644 $KERNEL $INITRD %{buildroot}/srv/tftpboot/openstack-ironic-image/

%files %{_arch}
%defattr(644,root,root)
%dir %attr(755, root, root) /srv/tftpboot/openstack-ironic-image
%attr(644, root, root) /srv/tftpboot/openstack-ironic-image/*

%changelog
