#!/bin/sh
log "Starting S09-cleanup..."
log "======================="

#=============================================
# 13) second stage done, cleanup level
#---------------------------------------------
# 13.1) kill shell on second virtual console
if test ! -z "$SPID" ; then
	log "\tkill console with PID: $SPID"
	kill -KILL $SPID &>/dev/null
fi
# 13.2) kill VNC server and remove VNC passwd
if [ ! -z "$VNC" ] && [ "$VNC" -eq 1 ] ; then
	log "\tkill all VNC sessions..."
	killall Xvnc &>/dev/null
	rm -fv /root/.vnc/passwd.yast
fi
# 13.3) stop network and sshd
if [ "$Y2_NETWORK_ACTIVE" -ne 0 ] ; then
	log "\tShutdown SSH daemon and network interfaces..."
	test -z "$Y2_SSH_ACTIVE" && rcsshd stop

#
#	network mustn't be stopped when using systemd - systemd ignores
#	network service startup in such case.
#	restart is used to force reconfiguration of network - first stage
#	config is used up to now.
#
	rcnetwork restart
fi
# 13.4) stop pcmcia service
if [ -x /sbin/rcpcmcia ] ; then
if rcpcmcia status ; then
	log "\tShutdown PCMCIA services..."
	/sbin/cardctl eject
	/etc/init.d/pcmcia stop
fi
fi

# 13.5) restart other services if necessary (bnc#395402)
if [ -f /var/lib/YaST2/restart_services ] ; then
    cat /var/lib/YaST2/restart_services | while read service; do
	log "\tRestart $service service..."
	test -f /etc/init.d/$service  && /etc/init.d/$service restart
    done
    rm -f /var/lib/YaST2/restart_services
fi
stop_unicode
