#!/bin/bash
# Elevate script
if [ ! "$UID" -eq 0 ]
then
    sudo bash "$BASH_SOURCE";
else
    contextRoot="$(mktemp -d)";
    pushd "$contextRoot" > /dev/null;

    curl -fsSL https://raw.githubusercontent.com/nagygergo/jetbrains-toolbox-install/1.1/jetbrains-toolbox.sh \
        | bash;

    popd > /dev/null;
    rm -rf "$contextRoot";

    {
        echo "[Desktop Entry]";
        echo "Encoding=UTF-8";
        echo "Type=Application";
        echo "Terminal=false";
        echo "Exec=/opt/jetbrains-toolbox/jetbrains-toolbox";
        echo "Name=JetBrains Toolbox";
    } > /usr/share/applications/jetbrains-toolbox.desktop;
fi