Created
January 11, 2024 04:42
-
-
Save sebhoss/5ce8d0858ff0d3f1a439d05368eca09c to your computer and use it in GitHub Desktop.
shell script to download latest JetBrains IntelliJ Ultimate
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 characters
#!/usr/bin/env sh | |
############################################################################### | |
# This shell script downloads the latest IntelliJ Ultimate (IU) version | |
############################################################################### | |
# modify these at will | |
install_folder="${XDG_DATA_HOME:-$HOME/.local/share}/installations/software" | |
binary_folder=$(systemd-path user-binaries) | |
operating_system='linux' | |
binary_name='jetbrains-idea' | |
binary_target="${binary_folder}/${binary_name}" | |
# keep these as-is | |
download_folder=$(mktemp --directory) | |
echo "[OK] working in ${download_folder}" | |
release_info_file="${download_folder}/latest-release-info" | |
latest_release_file="${download_folder}/latest-release" | |
# 'IU' is the code for Ultimate | |
release_url='https://data.services.jetbrains.com/products/releases?code=IU&latest=true&type=release' | |
# 'IIU' is the response for Ultimate | |
release_query='.IIU[0] | del(.whatsnew) | del(.notesLink) | del(.licenseRequired) | del(.uninstallFeedbackLinks) | del(.printableReleaseType)' | |
# download latest release infos | |
if curl --silent --fail --location --header 'Accept: application/json' "${release_url}" --output "${release_info_file}"; then | |
echo "[OK] latest release info downloaded from ${release_url}" | |
else | |
echo "[ERROR] failed to download ${release_url}" 1>&2 | |
exit 1 | |
fi | |
if ! jq --exit-status "${release_query}" < "${release_info_file}" > "${latest_release_file}"; then | |
echo '[ERROR] failed to fetch latest release' 1>&2 | |
exit 1 | |
fi | |
# extract various required infos | |
latest_release=$(cat "${latest_release_file}") | |
latest_version=$(echo "${latest_release}" \ | |
| jq -r '.version') | |
echo "[OK] latest version is ${latest_version}" | |
latest_bin_link=$(echo "${latest_release}" \ | |
| jq -r ".downloads.${operating_system}.link") | |
latest_sha_link=$(echo "${latest_release}" \ | |
| jq -r ".downloads.${operating_system}.checksumLink") | |
latest_archive="ideaIU-${latest_version}.tar.gz" | |
latest_checksum="${latest_archive}.sha256" | |
latest_install_folder="${install_folder}/${binary_name}/${latest_version}" | |
latest_binary="${latest_install_folder}/bin/idea.sh" | |
latest_icon="${latest_install_folder}/bin/idea.svg" | |
echo "[OK] installing into ${latest_install_folder}" | |
# short circuit in case version is already installed | |
if [ -d "${latest_install_folder}" ]; then | |
echo '[OK] latest version already installed' | |
exit 0 | |
fi | |
# download binary | |
echo "[OK] downloading binary from ${latest_bin_link}" | |
echo "[OK] downloading checksum from ${latest_sha_link}" | |
download_bin="${download_folder}/${latest_archive}" | |
download_sha="${download_folder}/${latest_checksum}" | |
if curl --silent --fail --location "${latest_bin_link}" --output "${download_bin}"; then | |
echo "[OK] latest binary downloaded from ${latest_bin_link}" | |
else | |
echo "[ERROR] failed to download ${latest_bin_link}" 1>&2 | |
exit 1 | |
fi | |
if curl --silent --fail --location "${latest_sha_link}" --output "${download_sha}"; then | |
echo "[OK] latest checksum downloaded from ${latest_sha_link}" | |
else | |
echo "[ERROR] failed to download ${latest_sha_link}" 1>&2 | |
exit 1 | |
fi | |
# verify checksum | |
if ! cd "${download_folder}" > /dev/null; then | |
echo "[ERROR] cannot change to ${download_folder}" 1>&2 | |
exit 1 | |
fi | |
if sha256sum --status --check "${latest_checksum}"; then | |
echo '[OK] checksum matches' | |
else | |
echo '[ERROR] checksum mismatch' 1>&2 | |
exit 1 | |
fi | |
if ! cd - > /dev/null; then | |
echo '[ERROR] cannot change to previous folder' 1>&2 | |
exit 1 | |
fi | |
# prepare installation folder | |
if mkdir --parents "${latest_install_folder}"; then | |
echo "[OK] install folder ${latest_install_folder} created" | |
else | |
echo "[ERROR] failed to create folder ${latest_install_folder}" 1>&2 | |
exit 1 | |
fi | |
# untar into installation folder | |
if tar --extract --gzip \ | |
--file="${download_bin}" \ | |
--directory="${latest_install_folder}" \ | |
--strip-components=1; then | |
echo "[OK] extracted ${download_bin} into ${latest_install_folder}" | |
else | |
echo "[ERROR] could not extract ${download_bin} into ${latest_install_folder}" 1>&2 | |
exit 1 | |
fi | |
# link to local bin folder | |
if [ -x "${latest_binary}" ]; then | |
echo "[OK] ${latest_binary} is an executable file" | |
else | |
echo "[ERROR] ${latest_binary} is not an executable file" 1>&2 | |
exit 1 | |
fi | |
if ln --symbolic --force "${latest_binary}" "${binary_target}"; then | |
echo "[OK] linked ${latest_binary} to ${binary_target}" | |
else | |
echo "[ERROR] could not link ${latest_binary} to ${binary_target}" 1>&2 | |
exit 1 | |
fi | |
if [ -f "${latest_icon}" ]; then | |
echo "[OK] ${latest_icon} is a file" | |
else | |
echo "[ERROR] ${latest_icon} is not a file" 1>&2 | |
exit 1 | |
fi | |
if ln --symbolic --force "${latest_icon}" "${icon_target}"; then | |
echo "[OK] linked ${latest_icon} to ${icon_target}" | |
else | |
echo "[ERROR] could not link ${latest_icon} to ${icon_target}" 1>&2 | |
exit 1 | |
fi | |
# cleanup | |
if rm --recursive --force "${download_folder}"; then | |
echo "[OK] deleted ${download_folder}" | |
else | |
echo "[ERROR] could not delete ${download_folder}" 1>&2 | |
exit 1 | |
fi | |
# announce | |
notify-send --app-name "install-latest-${binary_name}" \ | |
--urgency low \ | |
"${binary_name} ${latest_version} installed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment