Skip to content

Instantly share code, notes, and snippets.

@jen20
Created September 16, 2019 16:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jen20/218642f3c2cd0e2ce8b6b95ca59e0538 to your computer and use it in GitHub Desktop.
Save jen20/218642f3c2cd0e2ce8b6b95ca59e0538 to your computer and use it in GitHub Desktop.
Script for installing JetBrains Toolbox on Linux
#!/bin/bash
[ $(id -u) != "0" ] && exec sudo "$0" "$@"
echo -e " \e[94mInstalling Jetbrains Toolbox\e[39m"
echo ""
function getLatestUrl() {
USER_AGENT=('User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36')
URL=$(curl 'https://data.services.jetbrains.com//products/releases?code=TBA&latest=true&type=release' -H 'Origin: https://www.jetbrains.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8' -H "${USER_AGENT[@]}" -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: https://www.jetbrains.com/toolbox/download/' -H 'Connection: keep-alive' -H 'DNT: 1' --compressed | grep -Po '"linux":.*?[^\\]",' | awk -F ':' '{print $3,":"$4}'| sed 's/[", ]//g')
echo $URL
}
getLatestUrl
FILE=$(basename ${URL})
DEST=$PWD/$FILE
echo ""
echo -e "\e[94mDownloading Toolbox files \e[39m"
echo ""
wget -cO ${DEST} ${URL} --read-timeout=5 --tries=0
echo ""
echo -e "\e[32mDownload complete!\e[39m"
echo ""
DIR="/opt/jetbrains-toolbox"
echo ""
echo -e "\e[94mInstalling to $DIR\e[39m"
echo ""
if mkdir ${DIR}; then
tar -xzf ${DEST} -C ${DIR} --strip-components=1
fi
chmod -R +rwx ${DIR}
touch ${DIR}/jetbrains-toolbox.sh
echo "#!/bin/bash" >> $DIR/jetbrains-toolbox.sh
echo "$DIR/jetbrains-toolbox" >> $DIR/jetbrains-toolbox.sh
ln -s ${DIR}/jetbrains-toolbox.sh /usr/local/bin/jetbrains-toolbox
chmod -R +rwx /usr/local/bin/jetbrains-toolbox
echo ""
rm ${DEST}
echo -e "\e[32mDone.\e[39m"
@jankatins
Copy link

jankatins commented Mar 19, 2021

Apparently, this now works to get the toolox download URL without spoofing the user agent and so on:

URL=$(curl -s 'https://data.services.jetbrains.com//products/releases?code=TBA&latest=true&type=release' |jq -r '.TBA[0].downloads.linux.link')
# -L = follow redirects
curl -L "${URL}" --output "${DEST}/toolbox.tar.gz"

If you extract and run the toolbox command inside, it will also install itself into your home dir, so you can imit the extra script

Full script:

#!/usr/bin/env bash

set -e

if [[ ! -f ~/.local/share/JetBrains/Toolbox/bin/jetbrains-toolbox ]]; then
  msg_start "Installing jetbrains Toolbox"
  URL=$(curl -s 'https://data.services.jetbrains.com//products/releases?code=TBA&latest=true&type=release' | jq -r '.TBA[0].downloads.linux.link')

  DOWNLOAD_TEMP_DIR=$(mktemp -d)

  mkdir -p "${DOWNLOAD_TEMP_DIR}"

  curl -L "${URL}" --output "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"

  TOOLBOX_TEMP_DIR=$(mktemp -d)

  tar -C "$TOOLBOX_TEMP_DIR" -xf "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"
  rm "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"

  # for whatever stupid reasons bash doesn't expand the star here...
  # it automatically installs itself into ~/.local/share/JetBrains/Toolbox/
  bash -c "${TOOLBOX_TEMP_DIR}/*/jetbrains-toolbox"
  rm -rf "${TOOLBOX_TEMP_DIR}"
  msg_success "Installing jetbrains Toolbox: done."
fi

@juliangaal
Copy link

juliangaal commented Nov 12, 2021

works as of 11/2021

Some modifications: install jq, use echo

#!/usr/bin/env bash

set -e

sudo apt install -y jg

if [[ ! -f ~/.local/share/JetBrains/Toolbox/bin/jetbrains-toolbox ]]; then
  echo "Installing jetbrains Toolbox"
  URL=$(curl -s 'https://data.services.jetbrains.com//products/releases?code=TBA&latest=true&type=release' | jq -r '.TBA[0].downloads.linux.link')

  DOWNLOAD_TEMP_DIR=$(mktemp -d)

  mkdir -p "${DOWNLOAD_TEMP_DIR}"

  curl -L "${URL}" --output "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"

  TOOLBOX_TEMP_DIR=$(mktemp -d)

  tar -C "$TOOLBOX_TEMP_DIR" -xf "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"
  rm "${DOWNLOAD_TEMP_DIR}/toolbox.tar.gz"

  # for whatever stupid reasons bash doesn't expand the star here...
  # it automatically installs itself into ~/.local/share/JetBrains/Toolbox/
  bash -c "${TOOLBOX_TEMP_DIR}/*/jetbrains-toolbox"
  rm -rf "${TOOLBOX_TEMP_DIR}"
  echo "Installing jetbrains Toolbox: done."
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment