Last active
October 28, 2024 04:04
-
-
Save fmmendes/fbc0f339a8d2b15ef3532d7dbebd4db2 to your computer and use it in GitHub Desktop.
Custom script to download and install Oracle JDK from archive file
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
#!/bin/bash | |
# This is a custom script to download and install Oracle JDK from archive file | |
# Please note that this script was only tested only on: | |
# Raspberry Pi 5 running Raspberry Pi OS (64-bit) (Debian Bookworm port) | |
# This script is provided as is and you are free to use it at your own risk | |
# The author is not responsible for any damage caused by this script | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "Please run as root with sudo -i command" | |
exit 1 | |
fi | |
hw_arch=$(uname -m) | |
if [ "$hw_arch" = "aarch64" ]; then | |
hw_arch="aarch64" | |
elif [ "$hw_arch" = "x86_64" ]; then | |
hw_arch="x64" | |
else | |
echo "Unsupported hardware architecture" | |
exit 1 | |
fi | |
echo "Enter the Oracle JDK version to be installed" | |
read version | |
if [ -z "$version" ]; then | |
echo "Version cannot be empty" | |
exit 1 | |
fi | |
filename="jdk-$(echo $version)_linux-$(echo $hw_arch)_bin.tar.gz" | |
url="https://download.oracle.com/java/$version/latest/$filename" | |
sha256_url="https://download.oracle.com/java/$version/latest/$filename.sha256" | |
echo "Downloading the jdk tar.gz file" | |
wget -nc $url | |
echo "Downloading the sha256 file" | |
wget -nc $sha256_url | |
echo "Verifying the sha256 checksum" | |
if ! [ "$(sha256sum $filename | cut -d' ' -f1)" = "$(cat $filename.sha256)" ]; then | |
echo "Checksum verification failed" | |
exit 1 | |
fi | |
folder=$(tar -tf $filename | head -n 1 | cut -f1 -d"/") | |
priority=$(echo $folder | cut -d'-' -f2 | awk -F. '{printf "%d%02d\n", $1, $3}') | |
echo "Extracting the jdk tar.gz file" | |
tar -xzf $filename -C /opt | |
echo "Setting up the alternatives" | |
for binary in /opt/$folder/bin/*; do | |
if [ -x "$binary" ]; then | |
echo "Processing $binary" | |
update-alternatives --install /usr/bin/$(basename "$binary") $(basename "$binary") "$binary" $priority | |
update-alternatives --display $(basename "$binary") | |
echo "" | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment