#!/bin/ksh

# **************************** LICENSE START ***********************************
#
# Copyright 2012 ECMWF and INPE. This software is distributed under the terms
# of the Apache License version 2.0. In applying this license, ECMWF does not
# waive the privileges and immunities granted to it by virtue of its status as
# an Intergovernmental Organization or submit itself to any jurisdiction.
#
# ***************************** LICENSE END ************************************

#
# Create basic user directories by untar'ing
# the prepared tar file containing the needed
# directories and files.
#
# Called by the main Metview script.
#
# Parameter:
#       User Metview directory (full path)
#


TAR_FILE=$METVIEW_DIR/share/metview/app-defaults/User_Dir_Frame.tar.gz
DRAWERS_TAR_FILE=$METVIEW_DIR/share/metview/app-defaults/Sample_Drawers.tar.gz


if [ x$1 = x ]
then
   USER_DIR=$HOME/metview
else
   USER_DIR=$1
fi

echo " creating Metview user directories in $USER_DIR..."
mkdir $USER_DIR

if [ -f $TAR_FILE ]
then
   cd $USER_DIR
   gunzip -c $TAR_FILE | tar xf -

   if [ x$MV_DESKTOP_NAME = xDesktop ]
   then
      echo " creating sample drawers"
      cd System
      gunzip -c $DRAWERS_TAR_FILE | tar xf -
   fi

   echo " created !"
else
   echo " UNABLE TO CREATE: missing file $TAR_FILE"
   rmdir $USER_DIR
   exit 1
fi
