#!/bin/bash

# Copyright (c) 2018 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.

test -f /.kconfig && . /.kconfig
test -f /.profile && . /.profile

echo "Configure image: [$kiwi_iname]..."

#======================================
# Setup baseproduct link
#--------------------------------------
if [ ! -e /etc/products.d/baseproduct ]; then
    suseSetupProduct
fi

#======================================
# Import repositories' keys
#--------------------------------------
suseImportBuildKey

#======================================
# Create container exit
#--------------------------------------
mkdir -p /etc/warewulf
cat > /etc/warewulf/container_exit.sh <<EOF
#!/bin/sh
LANG=C
LC_CTYPE=C
export LANG LC_CTYPE
set -x
zypper clean --all
EOF
chmod 755 /etc/warewulf/container_exit.sh

#======================================
# Create exclude
#--------------------------------------
cat > /etc/warewulf/excludes <<EOF
/boot/
/usr/share/doc
/usr/share/man
EOF
chmod 644 /etc/warewulf/excludes
#======================================
# Create systemd/system-preset/85-ww4-node-default.preset
#--------------------------------------
cat > /usr/lib/systemd/system-preset/85-ww4-node-default.preset <<EOF
enable sshd.service
EOF
chmod 644 /usr/lib/systemd/system-preset/85-ww4-node-default.preset
systemctl preset sshd.service

#======================================
# create an empty resolv.conf
#--------------------------------------
test -e /etc/resolv.conf || touch /etc/resolv.conf

#===========================================
# create empty SCC files if they don't exist
#-------------------------------------------
test -e /etc/SUSEConnect || touch /etc/SUSEConnect
test -e /etc/zypp/credentials.d/SCCcredentials || touch /etc/zypp/credentials.d/SCCcredentials

#===========================================
# We only want one kernel
#------------------------------------------
sed -i -e "/^multiversion = .*(kernel)/s@\(.*\)@# \1@g" /etc/zypp/zypp.conf

exit 0
