#!/bin/bash

# posix-compliant way to source script
. ./jdkversion-settings.sh
# By sourcing jdkversion-settings, the following variables now exist
# - majorversion (JDK major version, likely 11 for GS and 17 for Expeditee)
# - fullversion (full version string of JDK)
# - bitness (32 or 64)

selfcon_ext=selfcontained-jdk
filesuffix=_x64

# lowercase OS name
thisOS=`uname -s`
thisOS=$(echo "$thisOS" | tr '[:upper:]' '[:lower:]')

#Bitness is always 64 on mac (darwin)
#bitness=`getconf LONG_BIT` # returns 32 or 64
if [ "$bitness" = "32" ]; then
    filesuffix=_i686
    #selfcon_ext=$selfcon_ext${bitness}
    echo "@@@ Need to get the 32 bit JDK"
fi

osfname=$thisOS
if [ "$thisOS" = "darwin" ] ; then
    osfname=macosx
fi
filename=zulu${fullversion}-${osfname}${filesuffix}

if [ ! -f ${filename}.tar.gz ] ; then
    echo "Downloading $osfname jdk binary"
    svn export ^/main/trunk/cli-extensions/$selfcon_ext/downloads/${filename}.tar.gz

else
    echo "Detected ${osfname} JDK binary - no need to download"
fi

tar xvzf ${filename}.tar.gz \
    && mv ${filename} zulu-jdk${majorversion}-${bitness}bit

if [ $? = 0 ] ; then
    echo "Untarred JDK${majorversion} and renamed the directory to:"
    echo "  zulu-jdk${majorversion}-${bitness}bit"
fi



