Last active
November 26, 2023 17:38
-
-
Save robfrawley/5258f4c2e183582a0c632244db0b89a3 to your computer and use it in GitHub Desktop.
Global Installation of Jetbrains Toolbox
This file contains 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
{ | |
"jba": { | |
"email": "rmf@src.run", | |
"fullName": "Rob Frawley 2nd", | |
"login": "robfrawley" | |
}, | |
"privacy_policy": { | |
"eua_accepted_version": "1.2" | |
}, | |
"install_location": "/opt/jetbrains/lib", | |
"shell_scripts": { | |
"enabled": true, | |
"location": "/opt/jetbrains/bin" | |
}, | |
"statistics": { | |
"allow": true | |
}, | |
"update": { | |
"filter": { | |
"quality_filter": { | |
"order_value": 10000 | |
} | |
} | |
} | |
} |
This file contains 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
#!/bin/bash | |
# configure behavior of installation and final toolbox placement | |
INSTALL_USE_TEMP_PATH="/tmp/jetbrains-toolbox-installation" | |
TOOLBOX_DOWNLOAD_LINK="https://src.run/get/jetbrains/toolkit/jetbrains-toolbox-1.14.5179.tar.gz" | |
TOOLBOX_USE_ROOT_PATH="/opt/jetbrains" | |
TOOLBOX_USE_TOOL_PATH="${TOOLBOX_USE_ROOT_PATH}/toolbox" | |
TOOLBOX_USE_IDES_PATH="${TOOLBOX_USE_ROOT_PATH}/lib" | |
TOOLBOX_USE_BINS_PATH="${TOOLBOX_USE_ROOT_PATH}/bin" | |
TOOLBOX_USE_USER_PATH="${HOME}/.local/share/JetBrains/Toolbox/" | |
TOOLBOX_USE_CONF_PATH="${TOOLBOX_USE_TOOL_PATH}/.settings.json" | |
TOOLBOX_TMP_CONF_PATH="${INSTALL_USE_TEMP_PATH}/settings.json" | |
# stop on non-zero exit automatically | |
set -e | |
# define functions | |
function std_out() { | |
printf "${1}" "${@:2}" | |
} | |
function std_err() { | |
std_out "${1}" "${@:2}" 2>&1 | |
} | |
function opt_user_input_prompt() { | |
local prompt="${1}" | |
local valids=("${@:2}") | |
local return | |
typeset -g PROMPT_RETURN | |
while true; do | |
std_out '(PROMPT) %s' "${prompt}" | |
if [[ ${#valids[@]} -gt 0 ]]; then | |
std_out ' [' | |
for i in "${!valids[@]}"; do | |
std_out '"%s"' "${valids[$i]}" | |
if [[ ${i} -lt $((${#valids[@]} - 1)) ]]; then std_out ', '; fi | |
done | |
std_out ']' | |
fi | |
std_out ': ' | |
read return | |
if [[ -n ${return} ]] && [[ ${#valids[@]} -gt 0 ]]; then | |
for i in "${!valids[@]}"; do | |
if [[ ${return} == ${valids[$i]} ]]; then break 2; fi | |
done | |
std_err '(FAILED) Invalid input value provided; you can use any of the enumerated values or no value. Please try again...\n' | |
continue | |
fi | |
break | |
done | |
PROMPT_RETURN="${return}" | |
} | |
function req_user_input_prompt() { | |
local prompt="${1}" | |
local valids=("${@:2}") | |
local return | |
typeset -g PROMPT_RETURN | |
while true; do | |
opt_user_input_prompt "${@}" | |
return="${PROMPT_RETURN}" | |
PROMPT_RETURN="" | |
if [[ ${#valids[@]} -gt 0 ]]; then | |
if [[ -n ${return} ]]; then | |
for i in "${!valids[@]}"; do | |
if [[ ${return} == ${valids[$i]} ]]; then break 2; fi | |
done | |
fi | |
std_err '(FAILED) Invalid input value provided; you can use any of the enumerated values. Please try again...\n' | |
continue | |
fi | |
if [[ -z ${return} ]]; then | |
std_err '(FAILED) Invalid input value provided; you can use any non-empty string value. Please try again...\n' | |
continue | |
fi | |
break | |
done | |
PROMPT_RETURN="${return}" | |
} | |
# create and use temporary work directory | |
mkdir -p "${INSTALL_USE_TEMP_PATH}" \ | |
&& std_out 'Creating temporary work directory "%s"\n' "${INSTALL_USE_TEMP_PATH}" | |
cd "${INSTALL_USE_TEMP_PATH}" \ | |
&& std_out 'Entering temporary work directory "%s"\n' "${INSTALL_USE_TEMP_PATH}" | |
# download/untar toolbox and catch installer file | |
std_out 'Fetching and extracting toolbox from "%s" ... ' "${TOOLBOX_DOWNLOAD_LINK}" | |
TOOLBOX_INSTALLER_PATH="$( | |
curl -s ${TOOLBOX_DOWNLOAD_LINK} \ | |
| tar -xvz \ | |
| tail -n1 | |
)" | |
std_out 'DONE\n' | |
# run installer | |
std_out 'Invoking toolbox installer executable at "%s" ... ' "${TOOLBOX_INSTALLER_PATH}" | |
${TOOLBOX_INSTALLER_PATH} | |
std_out 'DONE\n' | |
# inform user that toolbox has started and wait for it to perform any required setup | |
std_out 'Starting toolbox executable instance! Waiting a few seconds for it to complete its own initial setup operations.\n' | |
sleep 5 | |
# check for running instances and require user quits toolbox to continue | |
while ps aux | grep '[t]oolbox' &> /dev/null; do | |
opt_user_input_prompt 'Detected toolbox running: use the Toolbox GUI interface to quit and then press enter to continue...' | |
done | |
# create new system-wide installation directories | |
sudo mkdir -p "${TOOLBOX_USE_TOOL_PATH}" \ | |
&& std_out 'Creating toolbox self system directory "%s"\n' "${TOOLBOX_USE_TOOL_PATH}" | |
sudo mkdir -p "${TOOLBOX_USE_IDES_PATH}" \ | |
&& std_out 'Creating toolbox ides system directory "%s"\n' "${TOOLBOX_USE_IDES_PATH}" | |
sudo mkdir -p "${TOOLBOX_USE_BINS_PATH}" \ | |
&& std_out 'Creating toolbox bins system directory "%s"\n' "${TOOLBOX_USE_BINS_PATH}" | |
# make new path globally writable and owned by current user | |
sudo chown -R ${USER}:${USER} "${TOOLBOX_USE_ROOT_PATH}" \ | |
&& std_out 'Assigned recurrsive user/group permissions of "%s":"%s" to "%s"\n' ${USER} ${USER} "${TOOLBOX_USE_ROOT_PATH}" | |
sudo chmod -R 0777 "${TOOLBOX_USE_ROOT_PATH}" \ | |
&& std_out 'Assigned recurrsive r/w/x permissions of "0777" to "%s"\n' "${TOOLBOX_USE_ROOT_PATH}" | |
# copy files from user-specific toolbox install location to system-wide directory | |
std_out 'Rsyncing user-specific toolbox files "%s" to system-wide location "%s" ... ' "${TOOLBOX_USE_USER_PATH}" "${TOOLBOX_USE_TOOL_PATH}" | |
sudo rsync -avp "${TOOLBOX_USE_USER_PATH}/" "${TOOLBOX_USE_TOOL_PATH}" &> /dev/null | |
std_out 'DONE\n' | |
sudo chmod -R 0777 "${TOOLBOX_USE_ROOT_PATH}" \ | |
&& std_out 'Assigned recurrsive r/w/x permissions of "0777" to "%s"\n' "${TOOLBOX_USE_ROOT_PATH}" | |
# remove user-specific toolbox install location and then create symbolic link from user-specific toolbox install location to system-wide directory | |
rm -fr "${TOOLBOX_USE_USER_PATH}" \ | |
&& std_out 'Removing user-specific toolbox directory "%s"\n' "${TOOLBOX_USE_USER_PATH}" | |
cd "$(dirname "${TOOLBOX_USE_USER_PATH}")" | |
ln -s "${TOOLBOX_USE_TOOL_PATH}" "$(basename "${TOOLBOX_USE_USER_PATH}")" \ | |
&& std_out 'Creating symbolic link from user-specific toolbox directory "%s" to system-wide directory "%s"\n' "${TOOLBOX_USE_USER_PATH}" "${TOOLBOX_USE_TOOL_PATH}" | |
cd "${INSTALL_USE_TEMP_PATH}" | |
# figure out how to handle the settings file | |
std_out 'Settings file "%s/.settings.json" must be edited such that the "install_location" and "shell_scripts.location" JSON keys reflect the new directory locations.\n' "${TOOLBOX_USE_TOOL_PATH}" | |
req_user_input_prompt 'The settings file can be setup using "auto" mode to handle configuration automatically or manually yourself NOW (after which you can enter "done" to skip auto-config)' | |
# handle auto settings setup | |
if [[ ${PROMPT_RETURN} == "auto" ]]; then | |
while true; do | |
while true; do | |
JQ_BIN=$(which jq 2> /dev/null) | |
if [[ $? -eq 0 ]]; then break; fi | |
out_err 'Locating required dependency "jq" failed! Please install using "sudo apt install jq"...' | |
opt_user_input_prompt 'Press enter when ready to continue...' | |
done | |
${JQ_BIN} -e ".install_location = \"${TOOLBOX_USE_IDES_PATH}\"" "${TOOLBOX_USE_CONF_PATH}" > "${TOOLBOX_TMP_CONF_PATH}.1" | |
${JQ_BIN} -e ".shell_scripts.location = \"${TOOLBOX_USE_BINS_PATH}\"" "${TOOLBOX_TMP_CONF_PATH}.1" > "${TOOLBOX_TMP_CONF_PATH}.2" | |
cat "${TOOLBOX_TMP_CONF_PATH}.2" | sed -e 's/^/CONFFILE > /' | |
req_user_input_prompt 'Verify the above configuration settings file contents appears correct; continue and overwrite settings with contents?' yes no | |
if [[ ${PROMPT_RETURN} == "no" ]]; then | |
continue | |
fi | |
sudo cp "${TOOLBOX_TMP_CONF_PATH}.2" "${TOOLBOX_USE_CONF_PATH}" \ | |
&& std_out 'Creating final settings configuration file at at "%s"\n' "${TOOLBOX_USE_CONF_PATH}" | |
break | |
done | |
fi | |
# make new path globally writable and owned by current user | |
sudo chown -R ${USER}:${USER} "${TOOLBOX_USE_ROOT_PATH}" \ | |
&& std_out 'Assigned recurrsive user/group permissions of "%s":"%s" to "%s"\n' ${USER} ${USER} "${TOOLBOX_USE_ROOT_PATH}" | |
sudo chmod -R 0777 "${TOOLBOX_USE_ROOT_PATH}" \ | |
&& std_out 'Assigned recurrsive r/w/x permissions of "0777" to "%s"\n' "${TOOLBOX_USE_ROOT_PATH}" | |
# inform user of script completion | |
std_out 'Completed all operations; try starting JetBrains toolbox!\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tnx