#!/bin/bash

# **************************** 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 copying
# the prepared directories and files.
#
# Called by the main Metview script.
#
# Parameter:
#       User Metview directory (full path)
#


USER_SOURCE_DIR=$METVIEW_DIR/share/metview/app-defaults/UserDir


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

if [ -d $USER_DIR ]
then
    echo "NOTE: directory $USER_DIR already exists. Metview will write new files into this directory."
fi


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

if [ -d $USER_SOURCE_DIR ]
then
   cp -r $USER_SOURCE_DIR/* $USER_DIR
   cp $USER_SOURCE_DIR/._mv* $USER_DIR

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

# for neatness, unset these env vars
unset USER_SOURCE_DIR
unset USER_DIR
