#!/bin/sh
#C#
#
# Vaisala software source code file
#
# Copyright (c) Vaisala Oyj 1997, 1999, 2000, 2003, 2004, 2005, 2007, 2008,
# 2011, 2012, 2013.
# All rights reserved.
#
#C#

# @file
#
# Prepare for Making IRIS Release DVD
#
# $URL: https://subversion.vaisala.com/svn/repos/sigmet/wr_iris_rda/tags/release8.13.6/base/install_tools/prepare $
#
# $Id: prepare 29329 2013-04-23 18:23:13Z jho $
#

EXIT_STATUS=1
TMP=/tmp/$$_tmp
trap 'rm -f ${TMP} "${TMP}2" ; exit ${EXIT_STATUS}' INT EXIT

# ==============================
# Check IRIS_ROOT environment variable
#
if [ ! -r ${IRIS_ROOT}/install/prepare ] ; then
  echo "The 'IRIS_ROOT' env variable is not set properly" 1>&2 ; exit 1
fi

# ==============================
# Set specific values for the run from this machine
#
MACHINE="`uname -s`"
HOSTNAME=`hostname` ; HOSTNAME="${HOSTNAME%%.*}"

if [ "$MACHINE" = 'HP-UX' ] ; then
  alias REMSH="remsh"
  GROUP="users"
elif [ "$MACHINE" = 'Linux' ] ; then
  alias REMSH="rsh"
  GROUP="users"
else
  echo "Unknown Machine: '${MACHINE}'" 1>&2 ; exit 1
fi

PREPARE=${IRIS_ROOT}/install/prepare

IRISAPPDIR=${IRIS_ROOT}/bin/app-defaults

STYLE=$1

# ========================================================================
# Check style for valid options
# ========================================================================

case ${STYLE} in
    -iris|-rda) ;;
    *)
    echo "Unknown argument '$1', try:"
    echo "  prepare -iris"
    echo "  prepare -rda"
    exit 1
	;;
esac

IRISDIRS="./config ./include ./install ./lib"


  # ========================================
  # Make sure that the "C" version of the message catalogs exists
  #
echo "Checking Russian nls directory..."
if [ ! -r "${IRIS_ROOT}/bin/nls/ru/LC_MESSAGES" ] ; then
    echo "  Missing nls directory '${IRIS_ROOT}/bin/nls/ru/LC_MESSAGES'"
fi

  # ========================================
  # Remove any junk
  #
  echo "Removing spurious files..."
  cd ${IRIS_ROOT}
  find ./bin ${IRISDIRS} -type f \
    \( \
       -name '.*'     -o \
       -name '*~'     -o \
       -name '*.bak'  -o \
       -name '*.tmp'  -o \
       -name 'core'   -o \
       -name '#*#'       \
    \) -print -exec rm -f {} \;

  # ========================================
  # Check that the -setown option to INSTALL_IRIS leaves the files in the
  # same state that the makefiles initially create them.  This assures that
  # the customer's directory state will be the same as the development state
  # that has been tested at SIGMET.
  #
#  if [ ! -w / ] ; then
#    echo "Skipping '-setown' checks (must be run as 'root')"
#  else
    cd ${IRIS_ROOT} ; rm -rf ${TMP} "${TMP}2"
    echo ""
    echo "Checking consistency of '-setown' installation option..."
    echo "Scanning directories in present form..."
    find bin config_template -print | sort | xargs ls -ld > ${TMP}

    cd ${IRIS_ROOT}/install
    sudo ./instiris -root ${IRIS_ROOT} -setown -v

    echo "Comparing initial and final directories..."
    cd ${IRIS_ROOT}
    find bin config_template -print | sort | xargs ls -ld |
      sdiff -s -w 192 ${TMP} - | egrep -v '^[0-9c,]*$' |
      sed 's/ *\| */\|/' | tr '|' '\012'

    echo ""
#  fi

  # ========================================
  # Check to make sure we still have a symbolic link to the manuals.
  #
    if [ -h ${IRIS_ROOT}/manuals ] ; then
      echo "Viewable manuals are symbolicly linked, OK."
    else
      echo "Manuals directory is not a link, please repair" 1>&2 ; exit 1
    fi

  # Now make sure that each manual actually exists.  Do this
  # regardless of which machine we are on.
  #
    for ITEM in \
	${IRIS_ROOT}/manuals/IRIS_and_RDA_Dual_Polarization_Users_Manual.pdf \
        ${IRIS_ROOT}/manuals/IRIS_and_RDA_Utilities_Manual.pdf     \
        ${IRIS_ROOT}/manuals/IRIS_Product_and_Display_Manuals.pdf  \
        ${IRIS_ROOT}/manuals/IRIS_Programmers_Manual.pdf           \
        ${IRIS_ROOT}/manuals/IRIS_Radar_Manual.pdf                 \
        ${IRIS_ROOT}/manuals/RCP8_Users_Manual.pdf                 \
        ${IRIS_ROOT}/manuals/RVP8_Users_Manual.pdf                 \
        ${IRIS_ROOT}/manuals/RVP900_Users_Manual.pdf               \
        ${IRIS_ROOT}/manuals/Software_Installation_Manual.pdf  ; do
	if [ ! -r ${ITEM} ] ; then
	    echo "Manuals file '${ITEM}' is not readable'" 1>&2 ; exit 1
	fi
    done

    for ITEM in \
	${IRIS_ROOT}/manuals/extraspdf \
	${IRIS_ROOT}/manuals/release_notes ; do
	if [ ! -d ${ITEM} ] ; then
	    echo "Manuals directory '${ITEM}' is not readable'" 1>&2 ; exit 1
	fi
    done


EXIT_STATUS=0
