#!/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

if [ "$bitness" = "32" ]; then
    filesuffix=_i686
    # REMOVE THIS NEXT LINE AFTER MERGING JDK ZIP DOWNLOADS INTO SINGLE selfcontained-jdk TRAC URL
    # It's needed for now as the zip file it wants to download is still in selfcontained-jdk32
    #selfcon_ext=selfcontained-jdk${bitness}
    echo "@@@ Need to get the 32 bit JDK"
fi

filename=zulu${fullversion}-win${filesuffix}

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

else
    echo "Detected windows JDK binary - no need to download"
fi

unzip ${filename}.zip \
    && mv ${filename} zulu-jdk${majorversion}-${bitness}bit

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


