#!/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 X-Server with PID: $SPID"
	kill -KILL $SPID >/dev/null 2>&1
fi
# 13.2) kill VNC server and remove VNC passwd
if [ ! -z "$VNC" ] ; then
	log "\tkill all VNC sessions..."
	killall Xvnc >/dev/null 2>&1
	rm -fv /root/.vnc/passwd
fi
# 13.3) stop network and sshd
if test ! -z "$Y2_NETWORK_ACTIVE" ; then
	log "\tShutdown SSH daemon and network interfaces..."
	test -z "$Y2_SSH_ACTIVE" && rcsshd stop
	rcnetwork stop
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) remove network config for pcmcia and usb
if [ -f "$IFCFG_PCMCIA_SAVE" ] ; then
	mv $IFCFG_PCMCIA_SAVE $IFCFG_PCMCIA
else
	rm -f $IFCFG_PCMCIA
fi
if [ -f "$IFCFG_USB_SAVE" ] ; then
	mv $IFCFG_USB_SAVE $IFCFG_PCMCIA
else
	rm -f $IFCFG_USB
fi

stop_unicode

if [ -e "/var/lib/YaST2/firstboot_reboot_after_finish" ] ; then
    log "\tRebooting system as requested by firstboot..."
    rm /var/lib/YaST2/firstboot_reboot_after_finish
    /sbin/reboot
fi
