#!/bin/bash
#================
# FILE          : config.sh
#----------------
# PROJECT       : OpenSuSE KIWI Image System
# COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH. All rights reserved
#               :
# AUTHOR        : Marcus Schaefer <ms@suse.de>
#               :
# BELONGS TO    : Operating System images
#               :
# DESCRIPTION   : configuration script for SUSE based
#               : operating systems
#               :
#               :
# STATUS        : BETA
#----------------
#======================================
# Functions...
#--------------------------------------
test -f /.kconfig && . /.kconfig
test -f /.profile && . /.profile

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

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

#======================================
# Activate services
#--------------------------------------
suseInsertService sshd
suseInsertService boot.device-mapper
suseRemoveService avahi-dnsconfd
suseRemoveService avahi-daemon

#==========================================
# remove unneeded packages
#------------------------------------------
suseRemovePackagesMarkedForDeletion

#==========================================
# remove package docs
#------------------------------------------
rm -rf /usr/share/doc/packages/*
rm -rf /usr/share/doc/manual/*
rm -rf /opt/kde*

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

#======================================
# SuSEconfig
#--------------------------------------
suseConfig

insserv sleshammerstartup

#======================================
# Fix DHCP config
#--------------------------------------
function setsc()
{
# $1 = file, $2 = varname, $3 = value   
	# regex for zero or more spaces
	local S='[[:space:]]*'
	sed -i -r -e "s%^($S$2$S=$S).*%\1\"$3\"%" "$1"
}
setsc /etc/sysconfig/network/dhcp DHCLIENT_SET_HOSTNAME yes

#======================================
# Remove unneeded packages
#--------------------------------------
rpm -qa | grep yast | xargs rpm -e --nodeps
rpm -e --nodeps ruby
ln -sf /usr/bin/ruby.ruby2.1 /usr/bin/ruby

# dhcpcd required for mkinitrd - now removing
rpm -e dhcpcd mkinitrd cron logrotate --nodeps
rpm -e postfix openldap2-client glibc-locale xz bzip2 satsolver-tools openssl \
       dirmngr gpg2 libzypp suse-build-key gpg2-lang zypper perl-Bootloader \
       gfxboot gfxboot-branding-SLES perl-HTML-Parser perl-HTML-Tagset
rpm -e rpm --nodeps
# rempve rpm Database(s)
rm -rf /var/lib/rpm
# drop more unneeded code/data
rm -rf usr/{share,lib}/locale/{[^e],e[^n]}*
rm -rf lib/modules/*/kernel/{sound,drivers/{bluetooth,pcmcia,isdn,media,net/wireless,net/irda,parport,platform/x86/{*wmi.ko,*laptop.ko}}} # 22MB
rm -f usr/lib/perl5/*/*/auto/Encode/??/??.so # 9MB
 
#======================================
# Umount kernel filesystems
#--------------------------------------
baseCleanMount


# Create the init file
#cat >> /init << EOF
##!/bin/sh
#echo
#echo "Simple initrd is active"
#echo
#mount -t proc /proc /proc
#mount -t sysfs none /sys
#/bin/sh --login
#EOF
#
#chmod +x /init

ln -s /sbin/init /init

exit 0
