File baseiso.spec.in of Package baseiso-containment

# needsrootforbuild

# Keep this as a bcond for the future, but always
# enable it by default as baseiso-containment only
# works for agama-installer ISOs currently
%bcond pxeboot 1

# Patterns file name can be specified by defining %{tftpbootpatterns_name},
# or it defaults to "agama-installer".
%define tftpbootpatterns_path /usr/lib/build/%{?tftpbootpatterns_name}%{!?tftpbootpatterns_name:agama-installer}.tftpbootpatterns.txt
%define tftpbootlinks_path /usr/lib/build/%{?tftpbootpatterns_name}%{!?tftpbootpatterns_name:agama-installer}.tftpbootlinks.txt

Url:            http://www.suse.com/
Name:           baseiso-__NAME____FLAVOR__
Summary:        Product Composer Base Images
Version:        __VERSION__
Release:        __RELEASE__
Group:          System/Management
License:        SUSE-EULA
Provides:       baseiso(__NAME____FLAVOR__)

%define install_dir    %{_libexecdir}/base-isos
%define tftpboot_dir   /usr/share/tftpboot-installation
%define product_dir    %{tftpboot_dir}/__NAME____FLAVOR__
%define pxeboot_dir    %{product_dir}/%{_arch}
%define skelcd_dir     /usr/lib/skelcd
%define skelcd_cd1_dir %{skelcd_dir}/CD1

%description
Images to be used by product composer as a base. It is designed
for Agama Installer in first place.

%package -n tftpboot-__NAME____FLAVOR__-%{_arch}
Summary:        Product Composer Base Images (extracted PXE images)
Group:          System/Management
BuildArch:      noarch

%description -n tftpboot-__NAME____FLAVOR__-%{_arch}
Loaders that can be used for PXE boot, extracted from the installer
content.

%package -n skelcd-__NAME____FLAVOR__
Summary:        Product Composer Base Images (skeleton data)
Group:          System/Management

%description -n skelcd-__NAME____FLAVOR__
Loaders that can be extracted in ftp-trees.

%install
mkdir -p %buildroot%{install_dir}
cp -a /usr/src/packages/KIWI/* %buildroot%install_dir


%if %{with pxeboot}
mkdir -p %{buildroot}%{pxeboot_dir}
mkdir -p %{buildroot}%{skelcd_cd1_dir}
for file in $(isoinfo -R -i %{buildroot}%{install_dir}/*.iso -find -type f -print | grep -Ef %{tftpbootpatterns_path}); do
  mkdir -p %{buildroot}%{pxeboot_dir}/$(dirname ${file}) %{buildroot}%{skelcd_cd1_dir}/$(dirname ${file})
  isoinfo -R -i %{buildroot}%{install_dir}/*.iso -x ${file} > %{buildroot}%{pxeboot_dir}/${file}
  cp %{buildroot}%{pxeboot_dir}/${file} %{buildroot}%{skelcd_cd1_dir}/${file}
done

# Create compatibility symlinks with the directory structure used by older
# baseiso-containment releases.
# They will go in %{pxeboot_dir}/loader. This is only needed only for
# the tftpboot- packages.
if [ -e %{tftpbootlinks_path} ]; then
  mkdir -p %{buildroot}%{pxeboot_dir}/loader
  cat %{tftpbootlinks_path} | while read file; do
    [ ! -e %{buildroot}%{pxeboot_dir}/${file} ] || ln -s %{pxeboot_dir}/${file} %{buildroot}%{pxeboot_dir}/loader/$(basename ${file})
  done
fi
%endif

if [ -n "__FLAVOR__" ]; then
  # Rename the files so that they match what product-composer
  # expect
  for path in %{buildroot}%{install_dir}/__NAME__*; do
    filename="$(basename $path)"
    target_filename="${filename//__NAME__//__NAME____FLAVOR__}"
    mv -v ${path} %{buildroot}%{install_dir}/${target_filename}
    
    if [[ ${filename} == *.sha256 ]]; then
      sed -i "s|__NAME__|__NAME____FLAVOR__|g" %{buildroot}%{install_dir}/${target_filename}
    fi
  done
fi

%files
%install_dir

%if %{with pxeboot}
%files -n tftpboot-__NAME____FLAVOR__-%{_arch}
%defattr(-,root,root)
%dir %attr(0755,tftp,tftp) %tftpboot_dir
%tftpboot_dir

%files -n skelcd-__NAME____FLAVOR__
%defattr(-,root,root)
%dir %skelcd_dir
%skelcd_cd1_dir
%endif

%changelog
openSUSE Build Service is sponsored by