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

# spec file for package opsi-linux-bootimage
#
# Copyright (c) 2010 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:       python-opsi >= 4.0.6.13 opsi-utils >= 4.0
Url:            http://www.opsi.org
License:        AGPLv3+
Group:          Productivity/Networking/Opsi
AutoReqProv:    on
Version:        20161108
Release:        1
Summary:        opsi linux bootimage
%define tarname opsi-linux-bootimage
%define kernelversion messages
Source:         opsi-linux-bootimage_20161108-1.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%if 0%{?suse_version} == 1110 || 0%{?suse_version} == 1315
%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

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 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 perl_x86_64.tgz      $RPM_BUILD_ROOT/%{opsitftpboot}/perl_x86_64.tgz
cp perl_x86.tgz         $RPM_BUILD_ROOT/%{opsitftpboot}/perl_x86.tgz
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} 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
	cd %{opsitftpboot}/pxelinux.cfg
	ln -s default.menu default
	cd - >/dev/null
fi
serviceentry=$(opsi-admin --no-depot -Sd method config_getObjects '[]' '{"id":"clientconfig.configserver.url"}' | grep defaultValues | cut -d "'" -f2)
if [ "$serviceentry" != "" ]; then
	sed -i "s,append.*$,& service=$serviceentry,g" %{opsitftpboot}/pxelinux.cfg/default.menu
fi

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

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

# documentation
#%doc LICENSE README RELNOTES doc

# configfiles
%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
%{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}/perl_x86_64.tgz
%{opsitftpboot}/perl_x86.tgz
%{opsitftpboot}/pxelinux.cfg/elilo.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

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

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