#
# spec file for package openSUSE
#
# Copyright (c) 2017 SUSE LINUX 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/
#


Name:           ___PACKAGE_NAME___
%define product ___PRODUCT_NAME___
Version:        ___VERSION___
Release:        0
# ___RELEASE___ is the product release, not the build release of this package 
Conflicts:      otherproviders(distribution-release)
# Give zypp a hint that this product must be kept up-to-date using zypper dup, not up (boo#1061384)
Provides:       aaa_version
Provides:       distribution-release
Provides:       suse-release = %{version}-%{release}
Provides:       suse-release-oss = %{version}-%{release}
Provides:       product-update() = dup
Obsoletes:      aaa_version
Obsoletes:      openSUSE-Promo-release <= 11.1
Obsoletes:      openSUSE-release-live <= 11.0
Obsoletes:      product_flavor(%{product}) < ___VERSION___
Conflicts:      sles-release <= 10 sled-release <= 10 core-release <= 10
# bnc#826592
Provides:       weakremover(kernel-default) < 3.11
Provides:       weakremover(kernel-desktop) < 4.2
Provides:       weakremover(kernel-ec2) < 3.11
Provides:       weakremover(kernel-pae) < 3.11
Provides:       weakremover(kernel-vanilla) < 3.11
Provides:       weakremover(kernel-xen) < 3.11

Suggests:       java-1_8_0-openjdk
Suggests:       mariadb
Suggests:       mariadb-client
Recommends:     branding-openSUSE
BuildRequires:  skelcd-control-openSUSE
BuildRequires:  skelcd-openSUSE
___PRODUCT_PROVIDES___
___OBSOLETE_PACKAGES___

Summary:        ___SUMMARY___
License:        BSD-3-Clause
Group:          System/Fhs
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# /etc/issue is no longer a default file, but is auto-generated at bootup
Requires:       issue-generator
Requires(post): issue-generator
#PreReq:         coreutils
# the post scriptlets uses awk, boo#976913
Requires(post):  awk
%define betaversion ___BETA_VERSION___
%define codename Tumbleweed

%description
___DESCRIPTION___

___FLAVOR_PACKAGES___

%prep
%setup -qcT
mkdir license
if [ -f /CD1/license.tar.gz ]; then
  tar -C license -xzf /CD1/license.tar.gz
elif [ -f /usr/lib/skelcd/CD1/license.tar.gz ]; then
  tar -C license -xzf /usr/lib/skelcd/CD1/license.tar.gz
fi

%build

%install
mkdir -p $RPM_BUILD_ROOT/etc $RPM_BUILD_ROOT/usr/lib/issue.d $RPM_BUILD_ROOT/run

echo -e 'Welcome to %{product} %{codename} %{version}%{?betaversion: %{betaversion}} - Kernel \\r (\\l).\n' > $RPM_BUILD_ROOT/usr/lib/issue.d/10-openSUSE.conf
echo -e "\n" > $RPM_BUILD_ROOT/usr/lib/issue.d/90-openSUSE.conf
echo    'Welcome to %{product} %{codename} %{version}%{?betaversion: %{betaversion}} - Kernel %%r (%%t).' > $RPM_BUILD_ROOT/etc/issue.net

VERSION_ID=`echo %{version}|tr '[:upper:]' '[:lower:]'|sed -e 's/ //g;'`
# note: VERSION is an optional field and has no meaning other than informative on a rolling distro
# We do thus not add it to the os-release file
cat > $RPM_BUILD_ROOT/usr/lib/os-release <<EOF
NAME="openSUSE Tumbleweed"
# VERSION="%{version}%{?betaversion: %{betaversion}}"
ID=opensuse
ID_LIKE="suse"
VERSION_ID="$VERSION_ID"
PRETTY_NAME="openSUSE Tumbleweed"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:tumbleweed:%{version}"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
EOF
ln -s ../usr/lib/os-release $RPM_BUILD_ROOT/etc/os-release

echo "Have a lot of fun..." > $RPM_BUILD_ROOT/etc/motd
# Bug 404141 - /etc/YaST/control.xml should be owned by some package
mkdir -p $RPM_BUILD_ROOT/etc/YaST2/
echo $RPM_BUILD_ROOT
if [ -f /CD1/control.xml ]; then
  install -m 644 /CD1/control.xml $RPM_BUILD_ROOT/etc/YaST2/
elif [ -f /usr/lib/skelcd/CD1/control.xml ]; then
  install -m 644 /usr/lib/skelcd/CD1/control.xml $RPM_BUILD_ROOT/etc/YaST2/
fi

# fate#319341, make openSUSE-release own YaST license files. TODO:
# get rid of /etc/YaST2/licenses
install -D -d -m 755 "$RPM_BUILD_ROOT/etc/YaST2/licenses/base"
install -D -d -m 755 "$RPM_BUILD_ROOT%_defaultlicensedir"
cp -a license "$RPM_BUILD_ROOT%_defaultlicensedir/%name"
pushd license
for i in *; do
	ln -s "%_defaultlicensedir/%name/$i" $RPM_BUILD_ROOT/etc/YaST2/licenses/base/$i
done

___CREATE_PRODUCT_FILES___
# this is a base product, create symlink
ln -s openSUSE.prod $RPM_BUILD_ROOT/etc/products.d/baseproduct

%post
# Upgrade path - if /etc/default/grub contains any of the DISTRIBUTOR= tags
# we ever put, replace it with "", which means grub will use /etc/os-release to make something up
if [ -f /etc/default/grub ]; then
  DISTRIBUTOR=$(awk -F= '/^GRUB_DISTRIBUTOR/ {print $2}' /etc/default/grub | tr -d '"')
  case "$DISTRIBUTOR" in
        "openSUSE" | \
        "openSUSE 13.1" | \
        "openSUSE 13.2")
                # replace GRUB_DISTRIBUTOR in /etc/default/grub with ""
                sed -i "s/^GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=/" /etc/default/grub
                ;;
  esac
fi

%posttrans
# Launch the issue-generator: we have a new config file in /usr/lib/issue.d that needs to be represented
if [ -x /usr/sbin/issue-generator ]; then
    /usr/bin/systemd-tmpfiles --create issue-generator.conf || :
    /usr/sbin/issue-generator || :
fi

%files
%defattr(644,root,root,755)
%dir /etc/YaST2/licenses
/etc/YaST2/licenses/base
%license license/*
/etc/os-release
/usr/lib/os-release
# Bug 404141 - /etc/YaST/control.xml should be owned by some package
%dir /etc/YaST2/
%config /etc/YaST2/control.xml
%config(noreplace) /etc/motd
%dir /usr/lib/issue.d/
/usr/lib/issue.d/10-openSUSE.conf
/usr/lib/issue.d/90-openSUSE.conf
%config(noreplace) /etc/issue.net
/etc/products.d

%changelog