Skip to content

Commit

Permalink
Merge pull request #4 from missingcharacter/ISSUE-3
Browse files Browse the repository at this point in the history
check if native version is available first then try to download it
  • Loading branch information
missingcharacter authored Jan 31, 2019
2 parents aebb2db + 2539e81 commit df34b27
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ install () {
local platform=""
local tempdir=""
local native_filename=""
local github_prefix="https://github.com/JetBrains/kotlin/releases"

[ "Linux" = "$(uname)" ] && platform="linux" || platform="darwin"
[ "linux" = "${platform}" ] && tempdir=$(mktemp -d asdf-kotlin.XXXX) || tempdir=$(mktemp -dt asdf-kotlin)

curl -L "https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-compiler-${version}.zip" -o "${tempdir}/kotlin-compiler.zip"
curl -L "${github_prefix}/download/v${version}/kotlin-compiler-${version}.zip" -o "${tempdir}/kotlin-compiler.zip"
unzip -qq "${tempdir}/kotlin-compiler.zip" -d "${install_path}"

if [[ $platform == "linux-gnu" ]]; then
native_filename="kotlin-native-linux-${version}.tar.gz"
if [[ $platform == "linux" ]]; then
native_filename="kotlin-native-linux-\d\.\d\.\d.tar.gz"
elif [[ $platform == "darwin" ]]; then
native_filename="kotlin-native-macos-${version}.tar.gz"
native_filename="kotlin-native-macos-\d\.\d\.\d.tar.gz"
fi

if [[ ! -z $native_filename ]]; then
local native_url="https://github.com/JetBrains/kotlin/releases/download/v${version}/${native_filename}"
local check_url="${github_prefix}/tag/v${version}"
local check_regex="/JetBrains/kotlin/releases/download/v${version}/${native_filename}"
local check_native=$(curl "${check_url}" | grep -P "${check_regex}" | cut -f2 -d '"')
if [[ ! -z $check_native ]]; then
local native_install_path="${install_path}/kotlin-native"

curl -fL "${native_url}" -o "${tempdir}/kotlin-native.tar.gz" && \
curl -fL "https://github.com${check_native}" -o "${tempdir}/kotlin-native.tar.gz" && \
mkdir -p "${native_install_path}" && \
(cd "${native_install_path}" && tar -xf "${tempdir}/kotlin-native.tar.gz" --strip-components=1)
tar -xf "${tempdir}/kotlin-native.tar.gz" --strip-components=1 --directory "${native_install_path}"
fi

rm -rf "${tempdir}"
Expand Down

0 comments on commit df34b27

Please sign in to comment.