#!/bin/bash
### BEGIN INIT INFO
# Provides: hmcpostcfg
# Required-Start: hmcConfig
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Description: Provide configuration after hmcConfig or hmcRestore
### END INIT INFO

# Source function library.
. /etc/rc.status

rc_reset

case "$1" in
  start)
    # For RMC data restore. 'restoreRMC' indicator set in 'restore' script
    if [ -f /var/hsc/log/restoreRMC ]; then
        if [ -f /usr/sbin/rsct/bin/ctrestore ]; then
            /usr/sbin/rsct/bin/ctrestore >> /var/hsc/log/restore.log 2>&1
        fi
        rm -f /var/hsc/log/restoreRMC
    fi
    
    # Also for MegaMouth restore upgrade data processing...
    if [ -f /var/hsc/log/restoreMM ]; then
        if [ -f /usr/sbin/rsct/bin/ctrestore ]; then
            /usr/sbin/rsct/bin/ctrestore >> /var/hsc/log/restore.log 2>&1
        fi
        rm -f /var/hsc/log/restoreMM
    fi
    
    # Closing down HMC
    /opt/hsc/sbin/closeDownHMC 2>/dev/null
    mount /media/cdrom 2>/dev/null
    if [ $? -eq 0 ]; then
      if [ -f /media/cdrom/images/.AutoUpdate ]; then
	/opt/hsc/bin/applyUpdates cdrom 2>/dev/null
      fi
    fi
    rc=`umount /media/cdrom 2>/dev/null`
    echo $rc >/dev/null
    rc_status -v
    ;;
  stop)
    rc_status -v
    ;;
  *)
    echo "Usage: hmcpostcfg {start|stop}"
    exit 1
    ;;
esac
rc_exit

