File opsi-linux-bootimage.spec of Package opsi-linux-bootimage

# spec file for package opsi-linux-bootimage
#
# Copyright (c) 2010-2019 uib GmbH.
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#

Name:           opsi-linux-bootimage
Requires:       opsiconfd >= 4.1
Requires:       opsi-utils >= 4.1
Url:            http://www.opsi.org
License:        AGPL-3.0-only
Group:          Productivity/Networking/Opsi
AutoReqProv:    on
Version:        20200910
Release:        1
Summary:        The opsi linux bootimage
%define tarname opsi-linux-bootimage
%define kernelversion 5.8.5
Source:         opsi-linux-bootimage_20200910-1.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%define _binaries_in_noarch_packages_terminate_build   0

%if 0%{?suse_version} || 0%{?is_opensuse} 
%define tftpboot /var/lib/tftpboot
%define opsitftpboot /var/lib/tftpboot/opsi
%else
%define tftpboot /tftpboot
%define opsitftpboot /tftpboot/linux
%endif

%define toplevel_dir %{name}-%{version}

# ===[ description ]================================
%description
The opsi linux bootimage is used to run os independent tasks in the opsi context.

# ===[ debug_package ]==============================
%debug_package

# ===[ prep ]=======================================
%prep

# ===[ setup ]======================================
%setup -n %{tarname}-%{version}

# ===[ build ]======================================
%build

# ===[ install ]====================================
%install
mkdir -p                       $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg
mkdir -p                       $RPM_BUILD_ROOT/%{tftpboot}/grub/x86_64-efi

cp grub/grub.cfg               $RPM_BUILD_ROOT/%{tftpboot}/grub/grub.cfg
cp grub/unicode.pf2            $RPM_BUILD_ROOT/%{tftpboot}/grub/unicode.pf2
cp grub/x86_64-efi/regexp.mod  $RPM_BUILD_ROOT/%{tftpboot}/grub/x86_64-efi/regexp.mod
cp syslinux/chain.c32          $RPM_BUILD_ROOT/%{opsitftpboot}/chain.c32
cp syslinux/menu.c32           $RPM_BUILD_ROOT/%{opsitftpboot}/menu.c32
cp syslinux/pxelinux.0         $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.0
cp default.menu                $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/default.menu
cp default.nomenu              $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/default.nomenu
cp install-elilo-x86           $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install-elilo-x86
cp install-elilo-x64           $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install-elilo-x64
cp install-grub-x64            $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install-grub-x64
cp elilo.conf                  $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/elilo.conf
cp miniroot.bz2                $RPM_BUILD_ROOT/%{opsitftpboot}/miniroot-%{version}.bz2
cp miniroot-x64.bz2            $RPM_BUILD_ROOT/%{opsitftpboot}/miniroot-x64-%{version}.bz2
cp vmlinuz                     $RPM_BUILD_ROOT/%{opsitftpboot}/vmlinuz-%{kernelversion}
cp vmlinuz-x64                 $RPM_BUILD_ROOT/%{opsitftpboot}/vmlinuz-x64-%{kernelversion}
cp vmlinuz-x64.signed          $RPM_BUILD_ROOT/%{opsitftpboot}/vmlinuz-x64-%{kernelversion}.signed
cp perl_x86_64.tgz             $RPM_BUILD_ROOT/%{opsitftpboot}/perl_x86_64.tgz
cp perl_x86.tgz                $RPM_BUILD_ROOT/%{opsitftpboot}/perl_x86.tgz
cp shimx64.efi.signed          $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/shimx64.efi.signed
cp grubx64.efi                 $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/grubx64.efi
cp elilo.efi                   $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/elilo.efi
cp elilo.conf                  $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/elilo.conf
cp elilo-x86.efi               $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/elilo-x86.efi
cp install                     $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install
cp install-x64                 $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install-x64
cp install3264                 $RPM_BUILD_ROOT/%{opsitftpboot}/pxelinux.cfg/install3264

# Creating some necessary links
cd $RPM_BUILD_ROOT/%{opsitftpboot}
ln -sf vmlinuz-%{kernelversion} install
ln -sf vmlinuz-x64-%{kernelversion}.signed install-x64
ln -sf install-x64 install64
ln -sf miniroot-%{version}.bz2 miniroot.bz2
ln -sf miniroot-x64-%{version}.bz2 miniroot-x64.bz2
cd -


# ===[ clean ]======================================
%clean
rm -rf $RPM_BUILD_ROOT

# ===[ post ]=======================================
%post
fileadmingroup=$(grep "^fileadmingroup" /etc/opsi/opsi.conf | cut -d "=" -f 2 | sed 's/ //g')

chown -R opsiconfd:$fileadmingroup %{opsitftpboot} || true
chmod 2775 %{opsitftpboot}
chmod 2775 %{opsitftpboot}/pxelinux.cfg
find %{opsitftpboot} -type f -exec chmod 664 {} \;
if [ ! -e %{opsitftpboot}/pxelinux.cfg/default ]; then
	ln -s default.menu %{opsitftpboot}/pxelinux.cfg/default
fi
%if 0%{?suse_version} == 1110 || 0%{?suse_version} == 1315 || 0%{?is_opensuse}
    sed -i "s/linux/opsi/g" %{opsitftpboot}/pxelinux.cfg/install-elilo-x64
    sed -i "s/linux/opsi/g" %{opsitftpboot}/pxelinux.cfg/install-elilo-x86
    sed -i "s_/linux/_/opsi/_g" %{tftpboot}/grub/grub.cfg
    sed -i "s_/linux/_/opsi/_g" %{opsitftpboot}/pxelinux.cfg/install-grub-x64
%endif


# ===[ postun ]=====================================
%postun

# ===[ files ]======================================
%files
# default attributes
%defattr(-,opsiconfd,root)

# configfiles
%config %{tftpboot}/grub/grub.cfg
%config %{opsitftpboot}/install
%config %{opsitftpboot}/install64
%config %{opsitftpboot}/install-x64
%config %{opsitftpboot}/pxelinux.cfg/default.menu
%config %{opsitftpboot}/pxelinux.cfg/default.nomenu
%config %{opsitftpboot}/pxelinux.cfg/install-elilo-x64
%config %{opsitftpboot}/pxelinux.cfg/install-elilo-x86
%config %{opsitftpboot}/pxelinux.cfg/elilo.conf

# other files
%{tftpboot}/grub/unicode.pf2
%{tftpboot}/grub/x86_64-efi/regexp.mod
%{opsitftpboot}/chain.c32
%{opsitftpboot}/pxelinux.0
%{opsitftpboot}/menu.c32
%{opsitftpboot}/install
%{opsitftpboot}/install-x64
%{opsitftpboot}/miniroot-%{version}.bz2
%{opsitftpboot}/miniroot-x64-%{version}.bz2
%{opsitftpboot}/miniroot.bz2
%{opsitftpboot}/miniroot-x64.bz2
%{opsitftpboot}/vmlinuz-%{kernelversion}
%{opsitftpboot}/vmlinuz-x64-%{kernelversion}
%{opsitftpboot}/vmlinuz-x64-%{kernelversion}.signed
%{opsitftpboot}/perl_x86_64.tgz
%{opsitftpboot}/perl_x86.tgz
%{opsitftpboot}/pxelinux.cfg/elilo.efi
%{opsitftpboot}/pxelinux.cfg/shimx64.efi.signed
%{opsitftpboot}/pxelinux.cfg/grubx64.efi
%{opsitftpboot}/pxelinux.cfg/elilo-x86.efi
%{opsitftpboot}/pxelinux.cfg/install
%{opsitftpboot}/pxelinux.cfg/install3264
%{opsitftpboot}/pxelinux.cfg/install-x64
%{opsitftpboot}/pxelinux.cfg/install-elilo-x86
%{opsitftpboot}/pxelinux.cfg/install-elilo-x64
%{opsitftpboot}/pxelinux.cfg/install-grub-x64

# directories
%attr(-,root,root) %dir %{tftpboot}
%attr(2775,opsiconfd,root) %dir %{tftpboot}/grub
%attr(2775,opsiconfd,root) %dir %{tftpboot}/grub/x86_64-efi
%attr(2775,opsiconfd,root) %dir %{opsitftpboot}
%attr(2775,opsiconfd,root) %dir %{opsitftpboot}/pxelinux.cfg

# ===[ changelog ]==================================
%changelog