#!/bin/sh
# Copyright (C) 2001 NEC Corporation
# All Rights Reserved.
#
#    /etc/rc0.d/K00a - Express5800/CacheServer Online Update Package Install Script
#
#    1. run all exectable files in $dir and logging /var/log/wbmc_olud/<logfile>.
#    2. remove the files.
#    3. install all rpm packages in $dir and logging /var/log/wbmc_olud/<logfile>.
#    4. remove the rpm files.
#
# chkconfig: - 99 00
# description: Express5800/CacheServer Online Update Package Install Script
#

dir="/var/opt/nec/wbmc/olud/onshutdown"
logdir="/var/log/wbmc_olud"

if cd $dir ; then
  for f in * ; do
    if [ $f != "*" ]; then
      if [ -x "$f" -a ! -d "$f" ]; then
        logf="$logdir/$f.$$"
        mkdir -p $logdir
        
        echo "["`(export LANG=C; export LC_ALL=C; date)`"]: execute $f" >> $logf

        ./$f >> $logf 2>&1
        /bin/rm -f $f
      fi
    fi
  done
  for f in *.rpm ; do
    if [ $f != "*.rpm" ]; then
      logf="$logdir/$f.$$"
      mkdir -p $logdir

      echo "["`(export LANG=C; export LC_ALL=C; date)`"]: install $f" >> $logf

      md5=`md5sum $f`
      echo "["`(export LANG=C; export LC_ALL=C; date)`"]: md5sum $md5" >> $logf

      echo "["`(export LNAG=C; export LC_ALL=C; date)`"]: exec /bin/rpm -U $f" >> $logf
      /bin/rpm -U $f >> $logf 2>&1
      /bin/rm -f $f
    fi
  done
fi

exit 0;
