#!/bin/bash
# Elevate script
if [ ! "$UID" -eq 0 ]
then
    sudo bash "$BASH_SOURCE";
    curl -s "https://get.sdkman.io" | bash;
    source "~/.sdkman/bin/sdkman-init.sh";
    sdk install gradle 7.5.1;
else
    apt install -y wget apt-transport-https;
    mkdir -p /etc/apt/keyrings;

    wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public \
        | tee /etc/apt/keyrings/adoptium.asc;

    echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" \
        | tee /etc/apt/sources.list.d/adoptium.list;

    apt update;
    apt install -y temurin-17-jdk;
fi