#!/bin/sh
# =============================================================================
# Unitex/GramLab Unix-like Environments Setup Script
# https://github.com/UnitexGramLab/unitex-packaging-unix
# =============================================================================
# Copyright (C) 2015 Université Paris-Est Marne-la-Vallée <unitex@univ-mlv.fr>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
#
# cristian.martinez@univ-paris-est.fr (martinec)
# 
# =============================================================================
# This shell script must work in any POSIX-like system, including systems without 
# bash. See this helpful document on writing portable shell scripts:
# @see http://www.gnu.org/s/hello/manual/autoconf/Portable-Shell.html
# =============================================================================
# Script code must be ShellCheck-compliant for information about how to run 
# ShellCheck locally @see http://www.shellcheck.net/about.html
# e.g shellcheck -s sh setup
# =============================================================================
# Constants
# =============================================================================
UNITEX_SETUP_JAVA_SCRIPT_NAME=$(basename -- "$0")                 # This script name
# =============================================================================
# Script working directory
# =============================================================================
# Working directory snippet from @source http://stackoverflow.com/a/17744637/2042871
UNITEX_SETUP_JAVA_SCRIPT_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P) &&\
UNITEX_SETUP_JAVA_SCRIPT_FILE="$UNITEX_SETUP_JAVA_SCRIPT_FILE/$UNITEX_SETUP_JAVA_SCRIPT_NAME"

# Resolve symlinks snippet from @source http://stackoverflow.com/a/697552/2042871
while [ -h "$UNITEX_SETUP_JAVA_SCRIPT_FILE" ]; do
    UNITEX_SETUP_JAVA_SCRIPT_DIR=$(dirname -- "$UNITEX_SETUP_JAVA_SCRIPT_FILE")
    UNITEX_SETUP_JAVA_SCRIPT_SYM=$(readlink   "$UNITEX_SETUP_JAVA_SCRIPT_FILE")
    UNITEX_SETUP_JAVA_SCRIPT_FILE="$(cd "$UNITEX_SETUP_JAVA_SCRIPT_DIR"  &&\
                     cd "$(dirname  -- "$UNITEX_SETUP_JAVA_SCRIPT_SYM")" &&\
                    pwd)/$(basename -- "$UNITEX_SETUP_JAVA_SCRIPT_SYM")"
done  # [ -h "$UNITEX_SETUP_JAVA_SCRIPT_FILE" ]

# Set-up working directory 
UNITEX_SETUP_JAVA_SCRIPT_BASEDIR="$(dirname  -- "$UNITEX_SETUP_JAVA_SCRIPT_FILE")"

# =============================================================================
# Load dependencies
# =============================================================================
. "$UNITEX_SETUP_JAVA_SCRIPT_BASEDIR/common"

# =============================================================================
# Main Setup
# =============================================================================
unitex_setup_detect_java
unitex_setup_print_java_not_found_message
unitex_setup_print_java_installation_message
# =============================================================================
