#!/bin/bash

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

#======================================
# Greeting...
#--------------------------------------
echo "Configure image: [$kiwi_iname]..."

#==========================================
# setup build day
#------------------------------------------
baseSetupBuildDay

#======================================
# Mount system filesystems
#--------------------------------------
baseMount

#==========================================
# remove unneded kernel files
#------------------------------------------
suseStripKernel
baseStripLocales en_US.utf-8 C.utf8

#======================================
# Setup baseproduct link
#--------------------------------------
suseSetupProduct

#======================================
# Add missing gpg keys to rpm
#--------------------------------------
suseImportBuildKey

#======================================
# Activate services
#--------------------------------------
suseInsertService sshd
suseInsertService openstack-ironic-python-agent
suseInsertService suse-ironic-image-setup

echo 'DEFAULT_TIMEZONE="UTC"' >> /etc/sysconfig/clock
baseUpdateSysConfig /etc/sysconfig/clock HWCLOCK "-u"
baseUpdateSysConfig /etc/sysconfig/clock TIMEZONE UTC
baseUpdateSysConfig /etc/sysconfig/network/dhcp DHCLIENT_SET_HOSTNAME no
baseUpdateSysConfig /etc/sysconfig/network/dhcp WRITE_HOSTNAME_TO_HOSTS no

#==========================================
# generate autologin@ service
# based on getty@ service
#------------------------------------------
sed 's/^ExecStart=.*/\0 --autologin root/' /usr/lib/systemd/system/getty@.service > /etc/systemd/system/autologin\@.service

#==========================================
# add fstab entry for tmpfs based /tmp
#------------------------------------------
echo 'tmpfs /tmp tmpfs size=1G 0 0' >> /etc/fstab

#==========================================
# remove package docs and manuals
#------------------------------------------
baseStripDocs
baseStripMans
baseStripInfos

#======================================
# only basic version of vim is
# installed; no syntax highlighting
#--------------------------------------
sed -i -e's/^syntax on/" syntax on/' /etc/vimrc

#======================================
# Remove yast if not in use
#--------------------------------------
suseRemoveYaST

#======================================
# Remove package manager
#--------------------------------------
suseStripPackager

#rm -f usr/lib/perl5/*/*/auto/Encode/??/??.so # 9MB

#======================================
# Umount kernel filesystems
#--------------------------------------
baseCleanMount

ln -s /sbin/init /init

#==========================================
# umount
#------------------------------------------
umount /proc >/dev/null 2>&1

exit 0
