#! /bin/bash

set -x

# KIWI functions
test -f /.kconfig && . /.kconfig
test -f /.profile && . /.profile

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

# setup baseproduct link
suseSetupProduct

# activate services
systemctl enable sshd.service
systemctl enable NetworkManager.service
systemctl enable agama.service
systemctl enable agama-auto.service
systemctl enable x11-autologin.service
systemctl enable spice-vdagent.service

# default target
systemctl set-default graphical.target

filter_config=$(find /usr/lib64/ruby/gems/3.2.0/gems -name filter-config.rb)
products=""
case $kiwi_profiles in
"ALP" | "ALP-Playwright")
	products="ALP-Dolomite"
	;;
"openSUSE" | "openSUSE-Playwright")
	products="Tumbleweed Leap16"
	;;
esac

if [[ -n "$products" ]]; then
	ruby "$filter_config" /etc/agama.yaml $products >/etc/agama.yaml.new
	mv /etc/agama.yaml.new /etc/agama.yaml
fi

# adjust owner of extracted files
chown -R root:root /root
find /etc -user 1000 | xargs chown root:root
