Last active
          September 7, 2020 10:48 
        
      - 
      
 - 
        
Save Frederick888/40f4ee2545e13b22ae91e801d257812c to your computer and use it in GitHub Desktop.  
Revisions
- 
        
Frederick888 revised this gist
Sep 7, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,10 +27,10 @@ function compare_sdk_versions() { readarray -d $'\t' L <<< "$(sed "s/^0*\([0-9]\+\)u0*\([0-9]\+\)b0*\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1")" readarray -d $'\t' R <<< "$(sed "s/^0*\([0-9]\+\)u0*\([0-9]\+\)b0*\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2")" for i in "${!L[@]}"; do if [[ "${L[$i]}" -lt "${R[$i]}" ]]; then printf -- '-1' return 0 elif [[ "${L[$i]}" -gt "${R[$i]}" ]]; then printf '1' return 0 fi  - 
        
Frederick888 revised this gist
Aug 4, 2020 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,11 +24,9 @@ function get_sdk_version() { } function compare_sdk_versions() { readarray -d $'\t' L <<< "$(sed "s/^0*\([0-9]\+\)u0*\([0-9]\+\)b0*\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1")" readarray -d $'\t' R <<< "$(sed "s/^0*\([0-9]\+\)u0*\([0-9]\+\)b0*\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2")" for i in "${!L[@]}"; do if [[ "$LO" -lt "$RO" ]]; then printf -- '-1' return 0 @@ -51,7 +49,7 @@ printf 'Fetching file list...\n\n' for sdk_edition in '8' '11'; do DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_$sdk_edition" BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk$sdk_edition-$OS-x64/files" readarray -d $'\n' -t "$DOWNLOADABLE_FILES_VAR_NAME" <<< "$(curl $BINTRAY_API 2>/dev/null | jq -r '[.[] | select(.path | contains("sdk") and (contains("checksum") | not))] | sort_by(.created) | reverse | .[].path')" done declare -a TO_DOWNLOAD=()  - 
        
Frederick888 revised this gist
Jul 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ printf 'Fetching file list...\n\n' for sdk_edition in '8' '11'; do DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_$sdk_edition" BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk$sdk_edition-$OS-x64/files" readarray -d $'\n' -t "$DOWNLOADABLE_FILES_VAR_NAME" <<< "$(curl $BINTRAY_API 2>/dev/null | jq -r '[.[] | select(.path | contains("sdk"))] | sort_by(.created) | reverse | .[].path' | rg -v checksum)" done declare -a TO_DOWNLOAD=()  - 
        
Frederick888 revised this gist
Jul 28, 2020 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,10 +27,12 @@ function compare_sdk_versions() { readarray -d $'\t' L <<< "$(sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1")" readarray -d $'\t' R <<< "$(sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2")" for i in "${!L[@]}"; do LO="$(sed -e 's/^0.*//' -e 's/\n//' <<< "${L[$i]}")" RO="$(sed -e 's/^0.*//' -e 's/\n//' <<< "${R[$i]}")" if [[ "$LO" -lt "$RO" ]]; then printf -- '-1' return 0 elif [[ "$LO" -gt "$RO" ]]; then printf '1' return 0 fi  - 
        
Frederick888 revised this gist
Mar 6, 2020 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,7 @@ case "$OS" in ;; esac # get SDK version in the format of EDITIONuVERSIONbBUILD e.g. 11u06b722 function get_sdk_version() { sed 's/jbr\?sdk-\?\([[:digit:]]\+\)[u_]\([[:digit:]]\+\)[_-]\?\([[:digit:]]\+\)\(-[[:alpha:]]\+-[xi][[:digit:]]\+-\)\?\(b[[:digit:]]\+\)\..*/\1u\2\3\5/' <<< "$1" } @@ -41,8 +42,10 @@ function get_download_link() { printf 'https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=%s' "$1" } # list local SDKs readarray -d $'\n' -t SDK_LIST <<< "$(find "$DIR" -maxdepth 1 -type f \( -name "jbrsdk-11*.tar.gz" -or -name "jbrsdk-8*.tar.gz" \) -exec basename '{}' \; | sort)" printf 'Fetching file list...\n\n' # list remote SDKs via Bintray API for sdk_edition in '8' '11'; do DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_$sdk_edition" BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk$sdk_edition-$OS-x64/files" @@ -52,6 +55,7 @@ done declare -a TO_DOWNLOAD=() declare -a TO_REMOVE=() # find latest builds for local SDKs printf "INSTALLED\t\t\t\tLATEST\n" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=$(get_sdk_version "$sdk") @@ -61,6 +65,7 @@ for sdk in "${SDK_LIST[@]}"; do for sdk_remote in "${!DOWNLOADABLE_FILES_VAR_NAME}"; do SDK_REMOTE_VERSION=$(get_sdk_version "$sdk_remote") if [[ "$SDK_VERSION" == "$SDK_REMOTE_VERSION" ]]; then # find out the filename of the latest build in DOWNLOADABLE_FILES_x, which was sorted by creation date descendingly FILE_NAME="$sdk_remote" break fi @@ -75,6 +80,7 @@ for sdk in "${SDK_LIST[@]}"; do fi done # find the latest remote SDK declare -A LATEST_INSTALLED declare -A LATEST_AVAILABLE declare -A LATEST_LINK @@ -86,6 +92,7 @@ for sdk_edition in '8' '11'; do fi done DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_${sdk_edition}[@]" # we have to traverse through the whole list as new builds of old versions can be released after new versions for sdk in "${!DOWNLOADABLE_FILES_VAR_NAME}"; do SDK_VERSION=$(get_sdk_version "$sdk") if [[ "$SDK_VERSION" == "$sdk_edition""u"* && ( -z "${LATEST_AVAILABLE[$sdk_edition]}" || $(compare_sdk_versions "$SDK_VERSION" "${LATEST_AVAILABLE[$sdk_edition]}") -gt 0 ) ]]; then @@ -124,6 +131,7 @@ for i in "${!TO_DOWNLOAD[@]}"; do aria2c -d "$DIR" -s4 -x4 "${TO_DOWNLOAD[$i]}" # shellcheck disable=SC2181 if [[ $? -eq 0 && -n "${TO_REMOVE[$i]}" ]]; then # delete old build if download was successful rm "$DIR/${TO_REMOVE[$i]}" fi done  - 
        
Frederick888 revised this gist
Mar 6, 2020 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,11 +43,10 @@ function get_download_link() { readarray -d $'\n' -t SDK_LIST <<< "$(find "$DIR" -maxdepth 1 -type f \( -name "jbrsdk-11*.tar.gz" -or -name "jbrsdk-8*.tar.gz" \) -exec basename '{}' \; | sort)" printf 'Fetching file list...\n\n' for sdk_edition in '8' '11'; do DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_$sdk_edition" BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk$sdk_edition-$OS-x64/files" readarray -d $'\n' -t "$DOWNLOADABLE_FILES_VAR_NAME" <<< "$(curl $BINTRAY_API 2>/dev/null | jq -r '[.[] | select(.path | contains("sdk"))] | sort_by(.created) | reverse | .[].path')" done declare -a TO_DOWNLOAD=() @@ -57,10 +56,13 @@ printf "INSTALLED\t\t\t\tLATEST\n" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=$(get_sdk_version "$sdk") FILE_NAME="" sdk_edition="$(cut -d 'u' -f 1 <<< "$SDK_VERSION")" DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_${sdk_edition}[@]" for sdk_remote in "${!DOWNLOADABLE_FILES_VAR_NAME}"; do SDK_REMOTE_VERSION=$(get_sdk_version "$sdk_remote") if [[ "$SDK_VERSION" == "$SDK_REMOTE_VERSION" ]]; then FILE_NAME="$sdk_remote" break fi done if [[ "$sdk" == "$FILE_NAME" ]]; then @@ -83,7 +85,8 @@ for sdk_edition in '8' '11'; do LATEST_INSTALLED[$sdk_edition]="$SDK_VERSION" fi done DOWNLOADABLE_FILES_VAR_NAME="DOWNLOADABLE_FILES_${sdk_edition}[@]" for sdk in "${!DOWNLOADABLE_FILES_VAR_NAME}"; do SDK_VERSION=$(get_sdk_version "$sdk") if [[ "$SDK_VERSION" == "$sdk_edition""u"* && ( -z "${LATEST_AVAILABLE[$sdk_edition]}" || $(compare_sdk_versions "$SDK_VERSION" "${LATEST_AVAILABLE[$sdk_edition]}") -gt 0 ) ]]; then LATEST_AVAILABLE[$sdk_edition]="$SDK_VERSION"  - 
        
Frederick888 revised this gist
Mar 4, 2020 . 3 changed files with 126 additions and 236 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,126 @@ #!/usr/bin/env bash # shellcheck disable=SC2001 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" OS=$(uname) case "$OS" in Linux) OS="${OS,,}" ;; Darwin) OS="osx" ;; *) printf 'Unsupported system\n' exit 1 ;; esac function get_sdk_version() { sed 's/jbr\?sdk-\?\([[:digit:]]\+\)[u_]\([[:digit:]]\+\)[_-]\?\([[:digit:]]\+\)\(-[[:alpha:]]\+-[xi][[:digit:]]\+-\)\?\(b[[:digit:]]\+\)\..*/\1u\2\3\5/' <<< "$1" } function compare_sdk_versions() { readarray -d $'\t' L <<< "$(sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1")" readarray -d $'\t' R <<< "$(sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2")" for i in "${!L[@]}"; do if [[ "${L[$i]}" -lt "${R[$i]}" ]]; then printf -- '-1' return 0 elif [[ "${L[$i]}" -gt "${R[$i]}" ]]; then printf '1' return 0 fi done printf '0' } function get_download_link() { printf 'https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=%s' "$1" } readarray -d $'\n' -t SDK_LIST <<< "$(find "$DIR" -maxdepth 1 -type f \( -name "jbrsdk-11*.tar.gz" -or -name "jbrsdk-8*.tar.gz" \) -exec basename '{}' \; | sort)" printf 'Fetching file list...\n\n' declare -a DOWNLOADABLE_FILES=() for sdk_edition in '8' '11'; do BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk$sdk_edition-$OS-x64/files" readarray -d $'\n' -t SDK_DOWNLOADABLE_FILES <<< "$(curl $BINTRAY_API 2>/dev/null | jq -r '[.[] | select(.path | contains("sdk"))] | sort_by(.created) | .[].path')" DOWNLOADABLE_FILES+=( "${SDK_DOWNLOADABLE_FILES[@]}" ) done declare -a TO_DOWNLOAD=() declare -a TO_REMOVE=() printf "INSTALLED\t\t\t\tLATEST\n" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=$(get_sdk_version "$sdk") FILE_NAME="" for sdk_remote in "${DOWNLOADABLE_FILES[@]}"; do SDK_REMOTE_VERSION=$(get_sdk_version "$sdk_remote") if [[ "$SDK_VERSION" == "$SDK_REMOTE_VERSION" ]]; then FILE_NAME="$sdk_remote" fi done if [[ "$sdk" == "$FILE_NAME" ]]; then printf '%s\t(UP-TO-DATE)\n' "$sdk" else printf '%s\t%s\n' "$sdk" "$FILE_NAME" DOWNLOAD_LINK=$(get_download_link "$FILE_NAME") TO_DOWNLOAD+=( "$DOWNLOAD_LINK" ) TO_REMOVE+=( "$sdk" ) fi done declare -A LATEST_INSTALLED declare -A LATEST_AVAILABLE declare -A LATEST_LINK for sdk_edition in '8' '11'; do for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=$(get_sdk_version "$sdk") if [[ "$SDK_VERSION" == "$sdk_edition""u"* && ( -z "${LATEST_INSTALLED[$sdk_edition]}" || $(compare_sdk_versions "$SDK_VERSION" "${LATEST_INSTALLED[$sdk_edition]}") -gt 0 ) ]]; then LATEST_INSTALLED[$sdk_edition]="$SDK_VERSION" fi done for sdk in "${DOWNLOADABLE_FILES[@]}"; do SDK_VERSION=$(get_sdk_version "$sdk") if [[ "$SDK_VERSION" == "$sdk_edition""u"* && ( -z "${LATEST_AVAILABLE[$sdk_edition]}" || $(compare_sdk_versions "$SDK_VERSION" "${LATEST_AVAILABLE[$sdk_edition]}") -gt 0 ) ]]; then LATEST_AVAILABLE[$sdk_edition]="$SDK_VERSION" LATEST_LINK[$sdk_edition]=$(get_download_link "$sdk") fi done done if [[ "${#TO_DOWNLOAD[@]}" -gt 0 ]]; then printf '\n' read -p "Upgrade all? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" != "y" ]]; then TO_DOWNLOAD=() TO_REMOVE=() fi fi for sdk_edition in '8' '11'; do if [[ -z "${LATEST_INSTALLED[$sdk_edition]}" || $(compare_sdk_versions "${LATEST_INSTALLED[$sdk_edition]}" "${LATEST_AVAILABLE[$sdk_edition]}") -lt 0 ]]; then printf '\n' read -p "Latest SDK $sdk_edition version ${LATEST_AVAILABLE[$sdk_edition]} is not installed yet. Download? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" == "y" ]]; then TO_DOWNLOAD+=( "${LATEST_LINK[$sdk_edition]}" ) TO_REMOVE+=( "" ) fi fi done if [[ "${#TO_DOWNLOAD[@]}" -eq 0 ]]; then exit 0 fi for i in "${!TO_DOWNLOAD[@]}"; do aria2c -d "$DIR" -s4 -x4 "${TO_DOWNLOAD[$i]}" # shellcheck disable=SC2181 if [[ $? -eq 0 && -n "${TO_REMOVE[$i]}" ]]; then rm "$DIR/${TO_REMOVE[$i]}" fi done This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,118 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,118 +0,0 @@  - 
        
Frederick888 created this gist
Nov 7, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,118 @@ #!/usr/bin/env bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" OS=`uname` case "$OS" in Linux) OS="${OS,,}" ;; Darwin) OS="osx" ;; *) printf 'Unsupported system\n' exit 1 ;; esac function get_sdk_version() { sed 's/jbr\?sdk-\?\([[:digit:]]\+\)[u_]\([[:digit:]]\+\)[_-]\?\([[:digit:]]\+\)\(-[[:alpha:]]\+-[xi][[:digit:]]\+-\)\?\(b[[:digit:]]\+\)\..*/\1u\2\3\5/' <<< "$1" } function compare_sdk_versions() { declare -a L; IFS=$'\t' read -r -a L <<< `sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1"` declare -a R; IFS=$'\t' read -r -a R <<< `sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2"` for i in "${!L[@]}"; do if [[ "${L[$i]}" -lt "${R[$i]}" ]]; then printf -- '-1' return 0 elif [[ "${L[$i]}" -gt "${R[$i]}" ]]; then printf '1' return 0 fi done printf '0' } function get_download_link() { printf 'https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=%s' "$1" } BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk11-$OS-x64/files" declare -a SDK_LIST IFS=$'\n' SDK_LIST=( `find "$DIR" -maxdepth 1 -type f -name "jbrsdk-11*.tar.gz" -exec basename '{}' \; | sort` ) printf 'Fetching file list...\n\n' declare -a DOWNLOADABLE_FILES IFS=$'\n' DOWNLOADABLE_FILES=( `curl $BINTRAY_API 2>/dev/null | jq 'sort_by(.created) | .[].path' | grep sdk | sed -e 's/^"//' -e 's/"$//'` ) declare -a TO_DOWNLOAD=() declare -a TO_REMOVE=() printf "INSTALLED\t\t\t\tLATEST\n" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=`get_sdk_version "$sdk"` FILE_NAME="" for sdk_remote in "${DOWNLOADABLE_FILES[@]}"; do SDK_REMOTE_VERSION=`get_sdk_version "$sdk_remote"` if [[ "$SDK_VERSION" == "$SDK_REMOTE_VERSION" ]]; then FILE_NAME+=`printf '\n%s' "$sdk_remote"` fi done FILE_NAME=`printf '%s' "$FILE_NAME" | tail -n 1` if [[ "$sdk" == "$FILE_NAME" ]]; then printf "$sdk\t(UP-TO-DATE)\n" else printf "$sdk\t$FILE_NAME\n" DOWNLOAD_LINK=`get_download_link "$FILE_NAME"` TO_DOWNLOAD+=( "$DOWNLOAD_LINK" ) TO_REMOVE+=( "$sdk" ) fi done LATEST_INSTALLED="" LATEST_AVAILABLE="" LATEST_LINK="" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=`get_sdk_version "$sdk"` if [[ -z "$LATEST_INSTALLED" ]] || [[ `compare_sdk_versions "$SDK_VERSION" "$LATEST_INSTALLED"` -gt 0 ]]; then LATEST_INSTALLED="$SDK_VERSION" fi done for sdk in "${DOWNLOADABLE_FILES[@]: -15}"; do SDK_VERSION=`get_sdk_version "$sdk"` if [[ -z "$LATEST_AVAILABLE" ]] || [[ `compare_sdk_versions "$SDK_VERSION" "$LATEST_AVAILABLE"` -gt 0 ]]; then LATEST_AVAILABLE="$SDK_VERSION" LATEST_LINK=`get_download_link "$sdk"` fi done if [[ "${#TO_DOWNLOAD[@]}" -gt 0 ]]; then printf '\n' read -p "Upgrade all? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" != "y" ]]; then TO_DOWNLOAD=() TO_REMOVE=() fi fi if [[ -z "$LATEST_INSTALLED" ]] || [[ `compare_sdk_versions "$LATEST_INSTALLED" "$LATEST_AVAILABLE"` -lt 0 ]]; then printf '\n' read -p "Latest version $LATEST_AVAILABLE is not installed yet. Download? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" == "y" ]]; then TO_DOWNLOAD+=( "$LATEST_LINK" ) TO_REMOVE+=( "" ) fi fi if [[ "${#TO_DOWNLOAD[@]}" -eq 0 ]]; then exit 0 fi for i in "${!TO_DOWNLOAD[@]}"; do aria2c -d "$DIR" -s4 -x4 "${TO_DOWNLOAD[$i]}" if [[ "$?" -eq 0 ]] && [[ -n "${TO_REMOVE[$i]}" ]]; then rm "$DIR/${TO_REMOVE[$i]}" fi done This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,118 @@ #!/usr/bin/env bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" OS=`uname` case "$OS" in Linux) OS="${OS,,}" ;; Darwin) OS="osx" ;; *) printf 'Unsupported system\n' exit 1 ;; esac function get_sdk_version() { sed 's/jbr\?sdk-\?\([[:digit:]]\+\)[u_]\([[:digit:]]\+\)[_-]\?\([[:digit:]]\+\)\(-[[:alpha:]]\+-[xi][[:digit:]]\+-\)\?\(b[[:digit:]]\+\)\..*/\1u\2\3\5/' <<< "$1" } function compare_sdk_versions() { declare -a L; IFS=$'\t' read -r -a L <<< `sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$1"` declare -a R; IFS=$'\t' read -r -a R <<< `sed "s/^\([0-9]\+\)u\([0-9]\+\)b\([0-9]\+\)$/\1\t\2\t\3/" <<< "$2"` for i in "${!L[@]}"; do if [[ "${L[$i]}" -lt "${R[$i]}" ]]; then printf -- '-1' return 0 elif [[ "${L[$i]}" -gt "${R[$i]}" ]]; then printf '1' return 0 fi done printf '0' } function get_download_link() { printf 'https://bintray.com/jetbrains/intellij-jbr/download_file?file_path=%s' "$1" } BINTRAY_API="https://api.bintray.com/packages/jetbrains/intellij-jbr/jbrsdk8-$OS-x64/files" declare -a SDK_LIST IFS=$'\n' SDK_LIST=( `find "$DIR" -maxdepth 1 -type f -name "jbrsdk-8*.tar.gz" -exec basename '{}' \; | sort` ) printf 'Fetching file list...\n\n' declare -a DOWNLOADABLE_FILES IFS=$'\n' DOWNLOADABLE_FILES=( `curl $BINTRAY_API 2>/dev/null | jq 'sort_by(.created) | .[].path' | grep sdk | sed -e 's/^"//' -e 's/"$//'` ) declare -a TO_DOWNLOAD=() declare -a TO_REMOVE=() printf "INSTALLED\t\t\t\tLATEST\n" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=`get_sdk_version "$sdk"` FILE_NAME="" for sdk_remote in "${DOWNLOADABLE_FILES[@]}"; do SDK_REMOTE_VERSION=`get_sdk_version "$sdk_remote"` if [[ "$SDK_VERSION" == "$SDK_REMOTE_VERSION" ]]; then FILE_NAME+=`printf '\n%s' "$sdk_remote"` fi done FILE_NAME=`printf '%s' "$FILE_NAME" | tail -n 1` if [[ "$sdk" == "$FILE_NAME" ]]; then printf "$sdk\t(UP-TO-DATE)\n" else printf "$sdk\t$FILE_NAME\n" DOWNLOAD_LINK=`get_download_link "$FILE_NAME"` TO_DOWNLOAD+=( "$DOWNLOAD_LINK" ) TO_REMOVE+=( "$sdk" ) fi done LATEST_INSTALLED="" LATEST_AVAILABLE="" LATEST_LINK="" for sdk in "${SDK_LIST[@]}"; do SDK_VERSION=`get_sdk_version "$sdk"` if [[ -z "$LATEST_INSTALLED" ]] || [[ `compare_sdk_versions "$SDK_VERSION" "$LATEST_INSTALLED"` -gt 0 ]]; then LATEST_INSTALLED="$SDK_VERSION" fi done for sdk in "${DOWNLOADABLE_FILES[@]: -15}"; do SDK_VERSION=`get_sdk_version "$sdk"` if [[ -z "$LATEST_AVAILABLE" ]] || [[ `compare_sdk_versions "$SDK_VERSION" "$LATEST_AVAILABLE"` -gt 0 ]]; then LATEST_AVAILABLE="$SDK_VERSION" LATEST_LINK=`get_download_link "$sdk"` fi done if [[ "${#TO_DOWNLOAD[@]}" -gt 0 ]]; then printf '\n' read -p "Upgrade all? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" != "y" ]]; then TO_DOWNLOAD=() TO_REMOVE=() fi fi if [[ -z "$LATEST_INSTALLED" ]] || [[ `compare_sdk_versions "$LATEST_INSTALLED" "$LATEST_AVAILABLE"` -lt 0 ]]; then printf '\n' read -p "Latest version $LATEST_AVAILABLE is not installed yet. Download? [y/n] " -n 1 -r printf '\n' if [[ "$REPLY" == "y" ]]; then TO_DOWNLOAD+=( "$LATEST_LINK" ) TO_REMOVE+=( "" ) fi fi if [[ "${#TO_DOWNLOAD[@]}" -eq 0 ]]; then exit 0 fi for i in "${!TO_DOWNLOAD[@]}"; do aria2c -d "$DIR" -s4 -x4 "${TO_DOWNLOAD[$i]}" if [[ "$?" -eq 0 ]] && [[ -n "${TO_REMOVE[$i]}" ]]; then rm "$DIR/${TO_REMOVE[$i]}" fi done