|
#!/usr/bin/env bash |
|
set -euo pipefail |
|
IFS=$'\n\t' |
|
|
|
# --- 0) Check/install dependencies --- |
|
deps=(curl jq tar libfuse2) |
|
for pkg in "${deps[@]}"; do |
|
if [[ "$pkg" == "libfuse2" ]]; then |
|
if ! dpkg -s libfuse2 &> /dev/null; then |
|
read -rp "Package libfuse2 is missing. Install? [y/N] " ans |
|
if [[ "$ans" =~ ^[Yy] ]]; then |
|
sudo apt update |
|
sudo apt install -y libfuse2 |
|
else |
|
echo "libfuse2 is required. Exiting." |
|
exit 1 |
|
fi |
|
fi |
|
else |
|
if ! command -v "$pkg" &> /dev/null; then |
|
read -rp "Command '$pkg' is missing. Install? [y/N] " ans |
|
if [[ "$ans" =~ ^[Yy] ]]; then |
|
sudo apt update |
|
sudo apt install -y "$pkg" |
|
else |
|
echo "'$pkg' is required. Exiting." |
|
exit 1 |
|
fi |
|
fi |
|
fi |
|
done |
|
|
|
# --- 1) Fetch the latest Toolbox URL for Linux --- |
|
TOOLBOX_URL=$( |
|
curl -fsSL 'https://data.services.jetbrains.com/products/releases?code=TBA&latest=true&type=release' \ |
|
-H 'Origin: https://www.jetbrains.com' \ |
|
-H 'Referer: https://www.jetbrains.com/toolbox/download/' \ |
|
| jq -r '.TBA[0].downloads.linux.link' |
|
) |
|
|
|
# --- 2) Define install directory --- |
|
INSTALL_DIR="$HOME/.local/share/JetBrains/Toolbox" |
|
|
|
# --- 3) Create the directory --- |
|
mkdir -p "$INSTALL_DIR" |
|
|
|
# --- 4) Download & extract in one go --- |
|
curl -fsSL "$TOOLBOX_URL" \ |
|
| tar xz --strip-components=1 -C "$INSTALL_DIR" |
|
|
|
BIN_DIR="$INSTALL_DIR/bin" |
|
BIN_PATH="$BIN_DIR/jetbrains-toolbox" |
|
DESKTOP_SRC="$BIN_DIR/jetbrains-toolbox.desktop" |
|
|
|
# --- 5) (Optional) Symlink into ~/bin if it exists --- |
|
if [[ -d "$HOME/bin" ]]; then |
|
ln -sf "$BIN_PATH" "$HOME/bin/jetbrains-toolbox" |
|
fi |
|
|
|
# --- 6) Install .desktop launcher for current user --- |
|
if [[ -f "$DESKTOP_SRC" ]]; then |
|
APPS_DIR="$HOME/.local/share/applications" |
|
mkdir -p "$APPS_DIR" |
|
|
|
DESKTOP_DST="$APPS_DIR/jetbrains-toolbox.desktop" |
|
cp "$DESKTOP_SRC" "$DESKTOP_DST" |
|
|
|
# Fix Exec line to point to the real binary |
|
sed -i "s|^Exec=.*|Exec=$BIN_PATH %u|" "$DESKTOP_DST" |
|
|
|
# If we have an icon, fix Icon line too |
|
ICON_PATH="$BIN_DIR/toolbox-tray-color.png" |
|
if [[ -f "$ICON_PATH" ]]; then |
|
sed -i "s|^Icon=.*|Icon=$ICON_PATH|" "$DESKTOP_DST" || true |
|
fi |
|
|
|
chmod +x "$DESKTOP_DST" |
|
|
|
echo "Desktop entry installed to: $DESKTOP_DST" |
|
echo "You should now see 'JetBrains Toolbox' in your application menu." |
|
else |
|
echo "Warning: $DESKTOP_SRC not found; no .desktop file was installed." |
|
fi |
|
|
|
echo "JetBrains Toolbox installed to $INSTALL_DIR" |