File SLED-images.spec of Package SLED-images

#
# spec file for package SLED-images
#
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#
# needsrootforbuild
# needsbinariesforbuild


Name:           SLED-images
BuildRequires:  createrepo
BuildRequires:  dummy-release
BuildRequires:  ghostscript-fonts-std
BuildRequires:  ghostscript-library
BuildRequires:  kernel-default
BuildRequires:  package-lists-SLED-images
BuildRequires:  plymouth-branding-SLE
BuildRequires:  python-libxml2
BuildRequires:  suse-build-key
BuildRequires:  systemd
BuildRequires:  udev
BuildRequires:  xz
#!BuildIgnore: sled-release
#!BuildIgnore: post-build-checks
#!BuildIgnore: rpmlint-mini
#!BuildIgnore: rpmlint-Factory
#!BuildIgnore: build-compare
Summary:        Creates preinstalled images of patterns
License:        BSD-3-Clause
Group:          Metapackages
Version:        13.1
Release:        0
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Source:         common_tree
Source1:        images.xml.in
ExcludeArch:    ia64 ppc ppc64 s390x s390 ppc64le %{ix86} aarch64
# do not compress the ISO - takes ages 
%define _binary_payload w.ufdio

%description
This will install most default packages and create tar images for
faster installation

%prep
%setup -T -c

%build
createrepo /.build.binaries
install_repo()
{
  set +e
  root=$1
  file=$2
  export YAST_IS_RUNNING=1
  export ZYPP_MODALIAS_SYSFS=/tmp
  mkdir -p $root/home/rpmdir $root/proc $root/sys
  mkdir -p $root/dev
  mkdir -m 755 -p $root/dev/pts
  mknod -m 666 $root/dev/null c 1 3
  mknod -m 666 $root/dev/zero c 1 5
  mknod -m 622 $root/dev/full c 1 7
  mknod -m 666 $root/dev/random c 1 8
  mknod -m 644 $root/dev/urandom c 1 9
  mknod -m 666 $root/dev/tty c 5 0
  mknod -m 666 $root/dev/ptmx c 5 2
  ln -s /proc/self/fd $root/dev/fd
  ln -s fd/2 $root/dev/stderr
  ln -s fd/0 $root/dev/stdin
  ln -s fd/1 $root/dev/stdout
  mknod -m 640 $root/dev/loop0 b 7 0
  mknod -m 640 $root/dev/loop1 b 7 1
  mknod -m 640 $root/dev/loop2 b 7 2
  mknod -m 640 $root/dev/loop3 b 7 3
  mkdir -p $root/etc
  touch $root/etc/mtab
  cp /var/adm/fillup-templates/passwd.aaa_base $root/etc/passwd
  cp /var/adm/fillup-templates/group.aaa_base $root/etc/group
  ret=0
  ZYPPER="zypper --root $root --non-interactive --no-gpg-checks"
  mount -o bind,ro /.build.binaries $root/home/rpmdir
  mount -o bind /dev $root/dev
  mount -o bind /proc $root/proc
  mount -o bind /sys $root/sys
  cp /.buildenv $root
  for key in /usr/lib/rpm/gnupg/keys/gpg-pubkey-*.asc; do
    rpm -r $root --import $key
  done
#  mount -t sysfs none $root/sys
  $ZYPPER addrepo file:$root/home/rpmdir InstallationImage || ret=1
  $ZYPPER ref
  $ZYPPER in --auto-agree-with-licenses `cat /usr/share/suse/packages/$file` || ret=1
  rpm -r $root -qa --qf "[%{NAME}\n]" | LC_ALL=C sort -u > $file
  diff -U 0 /usr/share/suse/packages/$file $file
  list=`diff -u /usr/share/suse/packages/$file $file | grep -v +++ | grep ^+ | grep -v gpg-pubkey | cut -b2-`
  if test -n "$list"; then
    for pkg in $list; do
       # can't use percent-S in spec files...
       date=`date +"%Y-%m-%d %H:%M:59"`
       vers=`rpm -r $root -q --qf '%{VERSION}-%{RELEASE}' $pkg` 
       arch=`rpm -r $root -q --qf '%{ARCH}' $pkg`
       echo "$date|remove |$pkg|$vers|$arch|root@sled" >> $root/var/log/zypp/history
       rpm -v --nodeps -r $root -e $pkg || ret=1
    done
  fi
  sed -i -e 's,|root@build[0-9]*,|root@sled,' $root/var/log/zypp/history
  # update System.solv
  $ZYPPER ref
  $ZYPPER rr InstallationImage
  umount -f $root/home/rpmdir
  rmdir $root/home/rpmdir
  rm $root/.buildenv
  umount -f $root/proc
  umount $root/sys
  umount -f $root/dev
  set -e
  if test "$ret" = 1; then
    exit 1
  fi
}
for i in gnome_cd-x11 gnome_cd gnome_cd-base ; do 
  file=$i-default.%{_target_cpu}.list
  install_repo $PWD/$i $file
  mkdir -p $i-meta/var/lib/rpm $i-meta/var/cache/zypp
  rm -rf $i/var/cache/zypp/raw/
  rm -rf $i/var/cache/zypp/repo.* $i/etc/zypp/repos.d/repo.repo $i/var/cache/zypp/solv/repo
  rm -f $i/var/lib/zypp/AnonymousUniqueId
  mv $i/var/lib/rpm/* $i-meta/var/lib/rpm
  mv $i/var/cache/zypp/* $i-meta/var/cache/zypp
  mv $file $i.rpms
done
perl %SOURCE0 --dst common-xorg --prim gnome_cd-x11 --sec gnome_cd
perl %SOURCE0 --dst common-base --prim gnome_cd-base --sec common-xorg
# non-confusing names
mv gnome_cd-meta gnome-meta
mv gnome_cd gnome
mv gnome_cd.rpms gnome.rpms
mv gnome_cd-x11-meta x11-meta
mv gnome_cd-x11 x11
mv gnome_cd-x11.rpms x11.rpms
mv gnome_cd-base-meta base-meta
mv gnome_cd-base base
mv gnome_cd-base.rpms base.rpms

%install
mkdir -p $RPM_BUILD_ROOT/CD1/images
COMP="xz -5 -c -v"
EXT=xz
cpu=%_target_cpu
case $cpu in
   i*86)
      cpu=i386
      ;;
esac
cat > $RPM_BUILD_ROOT/CD1/images/details-$cpu.xml <<EOF
<?xml version="1.0"?>
<!DOCTYPE details>
<image_installation_details xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<details config:type="list" >
EOF
for i in *; do 
  test -d $i || continue
  cd $i
  tar cf ../$i.tar *
  cd ..
  $COMP $i.tar > $RPM_BUILD_ROOT/CD1/images/$i-$cpu.tar.$EXT
  usize=$(stat --terse --format=%s $i.tar)
  rm $i.tar
  (
    echo "<image>"
    echo "  <file>$i-$cpu.tar.$EXT</file>"
    case $i in
      *-meta)
        echo "  <rpms config:type=\"list\">"
        for r in `cat ${i/-meta/}.rpms`; do
          echo "    <rpm>$r</rpm>"
        done
        echo "  </rpms>"
        ;;
    esac
    echo "  <size>$usize</size>"
    echo "</image>"
   ) >> $RPM_BUILD_ROOT/CD1/images/details-$cpu.xml
done
cat >> $RPM_BUILD_ROOT/CD1/images/details-$cpu.xml <<EOF
</details>
</image_installation_details>
EOF
cat > $RPM_BUILD_ROOT/CD1/images/images.xml <<EOF
<?xml version="1.0"?>
<!DOCTYPE images>
<image_installation xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<image_sets config:type="list" >
EOF
for arch in x86_64; do
  sed -e "s,@ARCH@,$arch,g" %SOURCE1 >> $RPM_BUILD_ROOT/CD1/images/images.xml
done
cat >> $RPM_BUILD_ROOT/CD1/images/images.xml <<EOF
</image_sets>
</image_installation>
EOF
size=`du -s $RPM_BUILD_ROOT/CD1/images/ | cut -f1`
if test $size -gt 800000; then
  echo "this looks unreasonable"
  exit 1
fi

%files
%defattr(-, root, root)
/CD1

%changelog
openSUSE Build Service is sponsored by