From 9ef6843d3bbbff5b196dbb3ecf5c3b00e7747d4e Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 14:45:07 +0800 Subject: [PATCH 01/12] update script (cherry picked from commit 19fb3c8d44bfe43c1b8871d7ff34e3b057be5de0) --- install_dependencies.sh | 470 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 440 insertions(+), 30 deletions(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 860e79440e..0669d3a386 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -5,19 +5,327 @@ set -e OS="$(uname -s)" ARCH="$(uname -m)" -echo ">>> Environment Detection" +echo "========================================" +echo " TRON Java Dependencies Installer" +echo "========================================" +echo "" +echo -e ">>> \033[1mEnvironment Detection\033[0m" if [[ "$OS" == "Darwin" ]]; then echo " OS: MacOS $OS" elif [[ "$OS" == "Linux" ]]; then echo " OS: $OS" fi echo " Architecture: $ARCH" -echo "----------------------------------------" -echo ">>> Note: This script has been tested on:" +echo "" +echo ">>> This script will install the following components if not already installed:" +echo " 1. Homebrew to download and install JDK (macOS only)" +echo " 2. Git for cloning the java-tron repository" +if [[ "$OS" == "Darwin" ]]; then + if [[ "$ARCH" == "x86_64" ]]; then + echo " 3. OpenJDK 8 (required for x86_64 architecture)" + elif [[ "$ARCH" == "arm64" ]]; then + echo " 3. OpenJDK 17 (required for arm64 architecture)" + fi +elif [[ "$OS" == "Linux" ]]; then + if [[ "$ARCH" == "x86_64" ]]; then + echo " 3. OpenJDK 8 (required for x86_64 architecture)" + elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then + echo " 3. OpenJDK 17 (required for arm64/aarch64 architecture)" + fi +fi +echo "" +echo ">>> Tested platforms:" echo " - macOS x86_64 (JDK 8)" echo " - macOS arm64 (JDK 17)" echo " - Linux x86_64 (generic, including Ubuntu) (JDK 8)" echo " - Linux arm64/aarch64 (generic, including Ubuntu) (JDK 17)" +echo "" +echo "⚠️ WARNING: By continuing, you agree to install the above components." +echo " This script may install new software and modify your system Java environment." +echo "" + +# Function to ask for user confirmation +ask_confirmation() { + while true; do + read -p "Do you want to continue? (y/N): " yn + case $yn in + [Yy]* ) return 0;; + [Nn]* | "" ) echo "Installation cancelled."; exit 0;; + * ) echo "Please answer yes (y) or no (n).";; + esac + done +} + +# Function to check Java version +check_java_version() { + if command -v java &> /dev/null; then + local java_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + echo " Current Java version: $java_version" + + # Check if it's JDK 8 (version starts with 1.8) + if [[ "$java_version" =~ ^1\.8\. ]]; then + echo " JDK 8 is already installed." + return 0 + # Check if it's JDK 17 (version starts with 17) + elif [[ "$java_version" =~ ^17\. ]]; then + echo " JDK 17 is already installed." + return 1 + else + echo " Different Java version detected: $java_version" + return 2 + fi + else + echo " No Java installation found." + return 3 + fi +} + +# Function to ask for JDK installation confirmation +ask_jdk_confirmation() { + local current_version="$1" + local required_version="$2" + local arch="$3" + + echo "" + echo "⚠️ JDK Version Mismatch Detected!" + echo " Current version: $current_version" + echo " Required version for $arch: $required_version" + echo " This script will install $required_version alongside your existing installation." + echo " Your current Java installation will not be removed." + echo "" + + while true; do + read -p "Do you want to install $required_version? (y/N): " yn + case $yn in + [Yy]* ) return 0;; + [Nn]* | "" ) echo "JDK installation cancelled. Exiting."; exit 0;; + * ) echo "Please answer yes (y) or no (n).";; + esac + done +} + +# First, check and install Git (needed for cloning repository) +echo -e ">>> \033[1mChecking Git installation...\033[0m" +if ! command -v git &> /dev/null; then + echo " Git is not installed." + while true; do + read -p "Do you want to install Git (required for cloning the java-tron repository)? (y/N): " yn + case $yn in + [Yy]* ) + echo ">>> Installing Git..." + INSTALL_GIT=true + break;; + [Nn]* | "" ) + echo "Git installation cancelled. You'll need Git to clone the java-tron repository." + echo "You can install Git manually later and then clone the repository." + INSTALL_GIT=false + break;; + * ) echo "Please answer yes (y) or no (n).";; + esac + done +else + echo " ✅ Git is already installed: $(git --version)" + INSTALL_GIT=false +fi + +echo "" +echo -e ">>> \033[1mChecking existing Java installation...\033[0m" +set +e # Temporarily disable exit on error +check_java_version +java_status=$? +set -e # Re-enable exit on error + +# Determine required JDK version based on architecture +if [[ "$OS" == "Darwin" ]]; then + if [[ "$ARCH" == "x86_64" ]]; then + required_jdk="JDK 8" + required_status=0 + elif [[ "$ARCH" == "arm64" ]]; then + required_jdk="JDK 17" + required_status=1 + else + echo "Error: Unsupported architecture for macOS: $ARCH" + exit 1 + fi +elif [[ "$OS" == "Linux" ]]; then + if [[ "$ARCH" == "x86_64" ]]; then + required_jdk="JDK 8" + required_status=0 + elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then + required_jdk="JDK 17" + required_status=1 + else + echo "Error: Unsupported architecture for Linux: $ARCH" + exit 1 + fi +else + echo "Error: Unsupported Operating System: $OS" + exit 1 +fi + +# Check if correct JDK version is already installed +if [[ $java_status -eq $required_status ]]; then + echo "✅ Correct Java version ($required_jdk) is already installed!" + echo " You can skip the Java installation part." + echo "" + if [[ "$INSTALL_GIT" == "false" ]]; then + echo "✅ Both Git and Java JDK are ready for TRON development!" + echo "" + exit 0 + else + echo ">>> Proceeding with Git installation only..." + SKIP_JAVA_INSTALL=true + fi +elif [[ $java_status -eq 0 ]] || [[ $java_status -eq 1 ]] || [[ $java_status -eq 2 ]]; then + # Different JDK version is installed, ask for confirmation + current_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + ask_jdk_confirmation "$current_version" "$required_jdk" "$ARCH" + SKIP_JAVA_INSTALL=false +else + # No Java installation found, ask for general confirmation + echo "" + echo "⚠️ No Java installation detected!" + echo " This script will install $required_jdk which is required for $ARCH architecture." + echo "" + ask_confirmation + SKIP_JAVA_INSTALL=false +fi + +# Unified Java environment configuration function +configure_java_environment() { + local jdk_version="$1" + local os_type="$2" + local arch="$3" + local java_home="" + local java_bin_path="" + + echo "" + echo -e "==> \033[1mConfiguring Java environment\033[0m for JDK $jdk_version..." + + # Determine Java paths based on OS and architecture + if [[ "$os_type" == "Darwin" ]]; then + # macOS paths + if [[ "$jdk_version" == "8" ]]; then + java_home="/usr/local/opt/openjdk@8" + java_bin_path="/usr/local/opt/openjdk@8/bin" + elif [[ "$jdk_version" == "17" ]]; then + if [[ "$arch" == "arm64" ]]; then + java_home="/opt/homebrew/opt/openjdk@17" + java_bin_path="/opt/homebrew/opt/openjdk@17/bin" + else + java_home="/usr/local/opt/openjdk@17" + java_bin_path="/usr/local/opt/openjdk@17/bin" + fi + fi + elif [[ "$os_type" == "Linux" ]]; then + # Linux paths + if [[ "$jdk_version" == "8" ]]; then + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "arm64" ]]; then + java_home="/usr/lib/jvm/java-8-openjdk-arm64" + else + java_home="/usr/lib/jvm/java-8-openjdk-amd64" + fi + else + # RHEL/CentOS/Amazon Linux - try multiple possible paths + for path in "/usr/lib/jvm/java-1.8.0-amazon-corretto" "/usr/lib/jvm/java-1.8.0-openjdk"; do + if [[ -d "$path" ]]; then + java_home="$path" + break + fi + done + fi + elif [[ "$jdk_version" == "17" ]]; then + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "arm64" ]]; then + java_home="/usr/lib/jvm/java-17-openjdk-arm64" + else + java_home="/usr/lib/jvm/java-17-openjdk-amd64" + fi + else + # RHEL/CentOS/Amazon Linux - try multiple possible paths + for path in "/usr/lib/jvm/java-17-amazon-corretto" "/usr/lib/jvm/java-17-openjdk"; do + if [[ -d "$path" ]]; then + java_home="$path" + break + fi + done + fi + fi + java_bin_path="$java_home/bin" + fi + + # Set environment variables for current session + if [[ -d "$java_home" ]]; then + export JAVA_HOME="$java_home" + export PATH="$java_bin_path:$PATH" + echo " ✅ JAVA_HOME set to: $JAVA_HOME" + echo " ✅ PATH updated to include: $java_bin_path" + echo " 🔄 Environment temporarily configured for JDK $jdk_version" + + # Create a source script for the user's current shell + local env_script="./tron_java_env.sh" + cat > "$env_script" << EOF + +#!/bin/bash +# TRON Java Environment Configuration +# Generated by install_dependencies.sh on $(date) + +export JAVA_HOME="$java_home" +export PATH="$java_bin_path:\$PATH" + +echo "✅ Java environment configured:" +echo " JAVA_HOME: \$JAVA_HOME" +echo " Java version: \$(java -version 2>&1 | head -n 1)" +EOF + chmod +x "$env_script" + + echo "" + echo " 🎯 To apply Java environment to your current shell session:" + echo " source ./tron_java_env.sh" + echo "" + echo " 💡 Or run this command directly:" + echo " export JAVA_HOME=\"$java_home\"" + echo " export PATH=\"$java_bin_path:\$PATH\"" + + else + echo " ⚠️ Could not find Java installation at expected path: $java_home" + echo " ⚠️ You may need to set JAVA_HOME manually" + return 1 + fi + + # Provide OS-specific permanent configuration instructions + echo "" + echo " ⚙️ To make JDK $jdk_version permanent:" + if [[ "$os_type" == "Darwin" ]]; then + echo " # Add to ~/.zshrc or ~/.bash_profile:" + echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.zshrc" + echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.zshrc" + echo " # Then run below command:" + echo " source ~/.zshrc" + echo "" + elif [[ "$os_type" == "Linux" ]]; then + echo " # Method 1: Add to ~/.bashrc:" + echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.bashrc" + echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.bashrc" + echo " source ~/.bashrc" + echo "" + echo " # Method 2: Use update-alternatives (recommended):" + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + echo " sudo update-alternatives --install /usr/bin/java java $java_bin_path/java 1" + echo " sudo update-alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" + echo " sudo update-alternatives --config java" + else + echo " sudo alternatives --install /usr/bin/java java $java_bin_path/java 1" + echo " sudo alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" + echo " sudo alternatives --config java" + fi + fi + echo "" + + return 0 +} + echo "----------------------------------------" install_macos() { @@ -31,29 +339,73 @@ install_macos() { else eval "$(/usr/local/bin/brew shellenv)" fi + else + echo ">>> Homebrew is already installed." fi echo ">>> Updating Homebrew..." brew update - echo ">>> Installing Git..." - brew install git + # Install Git if needed + if [[ "$INSTALL_GIT" == "true" ]]; then + echo ">>> Installing Git..." + brew install git + echo " ✅ Git installed successfully: $(git --version)" + fi + + # Skip Java installation if flag is set + if [[ "$SKIP_JAVA_INSTALL" == "true" ]]; then + echo ">>> Skipping Java installation (correct version already detected)." + return 0 + fi if [[ "$ARCH" == "x86_64" ]]; then - echo ">>> Architecture is x86_64. Installing JDK 8..." - brew install openjdk@8 + echo ">>> Architecture is x86_64. Checking for JDK 8..." + set +e # Temporarily disable exit on error + check_java_version + local java_status=$? + set -e # Re-enable exit on error - echo ">>> Configuring PATH for openjdk@8 in this script session..." - export PATH="/usr/local/opt/openjdk@8/bin:$PATH" - echo " PATH updated to include /usr/local/opt/openjdk@8/bin" + if [[ $java_status -eq 0 ]]; then + echo ">>> JDK 8 is already installed. Skipping installation." + else + if [[ $java_status -eq 1 ]]; then + echo ">>> Installing JDK 8 alongside existing JDK 17..." + elif [[ $java_status -eq 2 ]]; then + echo ">>> Installing JDK 8 alongside existing Java installation..." + else + echo ">>> Installing JDK 8..." + fi + brew install openjdk@8 + + # Use unified Java environment configuration + configure_java_environment "8" "Darwin" "$ARCH" + echo "🔄 Environment has been updated! Java 8(1.8.*) is now configured." + fi elif [[ "$ARCH" == "arm64" ]]; then - echo ">>> Architecture is arm64. Installing JDK 17..." - brew install openjdk@17 + echo ">>> Architecture is arm64. Checking for JDK 17..." + set +e # Temporarily disable exit on error + check_java_version + local java_status=$? + set -e # Re-enable exit on error + + if [[ $java_status -eq 1 ]]; then + echo ">>> JDK 17 is already installed. Skipping installation." + else + if [[ $java_status -eq 0 ]]; then + echo ">>> Installing JDK 17 alongside existing JDK 8..." + elif [[ $java_status -eq 2 ]]; then + echo ">>> Installing JDK 17 alongside existing Java installation..." + else + echo ">>> Installing JDK 17..." + fi + brew install openjdk@17 - echo ">>> Configuring PATH for openjdk@17 in this script session..." - export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" - echo " PATH updated to include /opt/homebrew/opt/openjdk@17/bin" + # Use unified Java environment configuration + configure_java_environment "17" "Darwin" "$ARCH" + echo "🔄 Environment has been updated! Java 17 is now configured." + fi else echo "Error: Unsupported architecture for macOS script: $ARCH" @@ -82,8 +434,18 @@ install_linux() { echo ">>> Updating package index ($PKG_MANAGER)..." $UPDATE_CMD || true - echo ">>> Installing Git..." - $INSTALL_CMD git + # Install Git if needed + if [[ "$INSTALL_GIT" == "true" ]]; then + echo ">>> Installing Git..." + $INSTALL_CMD git + echo " ✅ Git installed successfully: $(git --version)" + fi + + # Skip Java installation if flag is set + if [[ "$SKIP_JAVA_INSTALL" == "true" ]]; then + echo ">>> Skipping Java installation (correct version already detected)." + return 0 + fi install_first_available() { for pkg in "$@"; do @@ -95,19 +457,61 @@ install_linux() { } if [[ "$ARCH" == "x86_64" ]]; then - echo ">>> Architecture is x86_64. Installing JDK 8..." - if [[ "$PKG_MANAGER" == "apt-get" ]]; then - install_first_available openjdk-8-jdk + echo ">>> Architecture is x86_64. Checking for JDK 8..." + set +e # Temporarily disable exit on error + check_java_version + local java_status=$? + set -e # Re-enable exit on error + + if [[ $java_status -eq 0 ]]; then + echo ">>> JDK 8 is already installed. Skipping installation." else - install_first_available java-1.8.0-amazon-corretto-devel java-1.8.0-openjdk-devel - fi || { echo "Error: Unable to install JDK 8 on $PKG_MANAGER"; exit 1; } + if [[ $java_status -eq 1 ]]; then + echo ">>> Installing JDK 8 alongside existing JDK 17..." + elif [[ $java_status -eq 2 ]]; then + echo ">>> Installing JDK 8 alongside existing Java installation..." + else + echo ">>> Installing JDK 8..." + fi + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + install_first_available openjdk-8-jdk + else + install_first_available java-1.8.0-amazon-corretto-devel java-1.8.0-openjdk-devel + fi || { echo "Error: Unable to install JDK 8 on $PKG_MANAGER"; exit 1; } + + # Use unified Java environment configuration + configure_java_environment "8" "Linux" "$ARCH" + echo "🔄 Environment has been updated! Java 8(1.8.*) is now configured." + fi + elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then - echo ">>> Architecture is arm64/aarch64. Installing JDK 17..." - if [[ "$PKG_MANAGER" == "apt-get" ]]; then - install_first_available openjdk-17-jdk + echo ">>> Architecture is arm64/aarch64. Checking for JDK 17..." + set +e # Temporarily disable exit on error + check_java_version + local java_status=$? + set -e # Re-enable exit on error + + if [[ $java_status -eq 1 ]]; then + echo ">>> JDK 17 is already installed. Skipping installation." else - install_first_available java-17-amazon-corretto-devel java-17-openjdk-devel - fi || { echo "Error: Unable to install JDK 17 on $PKG_MANAGER"; exit 1; } + if [[ $java_status -eq 0 ]]; then + echo ">>> Installing JDK 17 alongside existing JDK 8..." + elif [[ $java_status -eq 2 ]]; then + echo ">>> Installing JDK 17 alongside existing Java installation..." + else + echo ">>> Installing JDK 17..." + fi + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + install_first_available openjdk-17-jdk + else + install_first_available java-17-amazon-corretto-devel java-17-openjdk-devel + fi || { echo "Error: Unable to install JDK 17 on $PKG_MANAGER"; exit 1; } + + # Use unified Java environment configuration + configure_java_environment "17" "Linux" "$ARCH" + echo "🔄 Environment has been updated! Java 17 is now configured." + fi + else echo "Error: Unsupported architecture for Linux script: $ARCH" exit 1 @@ -124,8 +528,14 @@ else fi echo "----------------------------------------" -echo ">>> Installation logic completed." -echo "Please verify installations manually if any errors occurred above." -echo "Check versions with:" +echo -e "✅ \033[1mInstallation completed successfully!\033[0m" +echo "" +echo ">>> Verification Commands:" echo " git --version" echo " java -version" +echo "" +echo ">>> Troubleshooting:" +echo -e " • If 'java -version' shows incorrect version, check \033[1mConfiguring Java environment\033[0m instructions shown above " +echo "" +echo "🎉 Your development environment is ready for TRON!" +echo "" \ No newline at end of file From 1b1d32734f04982524fe09e3e1ab9963af702752 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 14:52:09 +0800 Subject: [PATCH 02/12] fix minors --- install_dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 0669d3a386..cdb53c4cf5 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -535,7 +535,7 @@ echo " git --version" echo " java -version" echo "" echo ">>> Troubleshooting:" -echo -e " • If 'java -version' shows incorrect version, check \033[1mConfiguring Java environment\033[0m instructions shown above " +echo -e " • If 'java -version' shows incorrect version, check \033[1mConfiguring Java environment\033[0m instructions shown above." echo "" echo "🎉 Your development environment is ready for TRON!" echo "" \ No newline at end of file From 2dd181ff66a5609b10f2177e36d1558251464640 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 14:56:36 +0800 Subject: [PATCH 03/12] fix texts --- install_dependencies.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index cdb53c4cf5..7b3aaa1021 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -75,7 +75,6 @@ check_java_version() { return 2 fi else - echo " No Java installation found." return 3 fi } From c55deb9251e5d9c2802d04d91e73e284414041e2 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 15:27:50 +0800 Subject: [PATCH 04/12] update --- install_dependencies.sh | 247 +++++++++++++++++++++++++++------------- tron_java_env.sh | 11 ++ 2 files changed, 182 insertions(+), 76 deletions(-) create mode 100755 tron_java_env.sh diff --git a/install_dependencies.sh b/install_dependencies.sh index 7b3aaa1021..fa35421dbc 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -17,6 +17,12 @@ elif [[ "$OS" == "Linux" ]]; then fi echo " Architecture: $ARCH" echo "" +echo ">>> Tested platforms:" +echo " - macOS x86_64 (JDK 8)" +echo " - macOS arm64 (JDK 17)" +echo " - Linux x86_64 (generic, including Ubuntu) (JDK 8)" +echo " - Linux arm64/aarch64 (generic, including Ubuntu) (JDK 17)" +echo "" echo ">>> This script will install the following components if not already installed:" echo " 1. Homebrew to download and install JDK (macOS only)" echo " 2. Git for cloning the java-tron repository" @@ -34,14 +40,7 @@ elif [[ "$OS" == "Linux" ]]; then fi fi echo "" -echo ">>> Tested platforms:" -echo " - macOS x86_64 (JDK 8)" -echo " - macOS arm64 (JDK 17)" -echo " - Linux x86_64 (generic, including Ubuntu) (JDK 8)" -echo " - Linux arm64/aarch64 (generic, including Ubuntu) (JDK 17)" -echo "" -echo "⚠️ WARNING: By continuing, you agree to install the above components." -echo " This script may install new software and modify your system Java environment." +echo "WARNING: By continuing, you agree to install the above components." echo "" # Function to ask for user confirmation @@ -55,6 +54,7 @@ ask_confirmation() { esac done } +ask_confirmation # Function to check Java version check_java_version() { @@ -86,7 +86,7 @@ ask_jdk_confirmation() { local arch="$3" echo "" - echo "⚠️ JDK Version Mismatch Detected!" + echo "JDK Version Mismatch Detected!" echo " Current version: $current_version" echo " Required version for $arch: $required_version" echo " This script will install $required_version alongside your existing installation." @@ -123,7 +123,7 @@ if ! command -v git &> /dev/null; then esac done else - echo " ✅ Git is already installed: $(git --version)" + echo "Git is already installed: $(git --version)" INSTALL_GIT=false fi @@ -164,11 +164,11 @@ fi # Check if correct JDK version is already installed if [[ $java_status -eq $required_status ]]; then - echo "✅ Correct Java version ($required_jdk) is already installed!" + echo "Correct Java version ($required_jdk) is already installed!" echo " You can skip the Java installation part." echo "" if [[ "$INSTALL_GIT" == "false" ]]; then - echo "✅ Both Git and Java JDK are ready for TRON development!" + echo "Both Git and Java JDK are ready for TRON development!" echo "" exit 0 else @@ -183,41 +183,155 @@ elif [[ $java_status -eq 0 ]] || [[ $java_status -eq 1 ]] || [[ $java_status -eq else # No Java installation found, ask for general confirmation echo "" - echo "⚠️ No Java installation detected!" + echo "No Java installation detected!" echo " This script will install $required_jdk which is required for $ARCH architecture." echo "" - ask_confirmation SKIP_JAVA_INSTALL=false fi -# Unified Java environment configuration function -configure_java_environment() { +# Function to show permanent Java configuration instructions +show_permanent_java_config() { local jdk_version="$1" local os_type="$2" - local arch="$3" - local java_home="" - local java_bin_path="" + local java_home="$3" + local java_bin_path="$4" + + echo "" + echo " To make JDK $jdk_version permanent:" + if [[ "$os_type" == "Darwin" ]]; then + echo " # Add to ~/.zshrc or ~/.bash_profile:" + echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.zshrc" + echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.zshrc" + echo " # Then run below command:" + echo " source ~/.zshrc" + echo "" + echo " # Or use jenv for Java version management:" + echo " brew install jenv" + echo " jenv add $java_home" + elif [[ "$os_type" == "Linux" ]]; then + echo " # Method 1: Add to ~/.bashrc:" + echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.bashrc" + echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.bashrc" + echo " source ~/.bashrc" + echo "" + echo " # Method 2: Use update-alternatives (recommended):" + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + echo " sudo update-alternatives --install /usr/bin/java java $java_bin_path/java 1" + echo " sudo update-alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" + echo " sudo update-alternatives --config java" + else + echo " sudo alternatives --install /usr/bin/java java $java_bin_path/java 1" + echo " sudo alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" + echo " sudo alternatives --config java" + fi + fi + echo "" +} +# Function to show Java environment application instructions +show_java_env_instructions() { + local java_home="$1" + local java_bin_path="$2" + + echo "" + echo " To apply Java environment to your current shell session:" + echo " source ./tron_java_env.sh" echo "" - echo -e "==> \033[1mConfiguring Java environment\033[0m for JDK $jdk_version..." + echo " Or run this command directly:" + echo " export JAVA_HOME=\"$java_home\"" + echo " export PATH=\"$java_bin_path:\$PATH\"" +} + +# Function to get Java paths based on OS and architecture +get_java_paths() { + local jdk_version="$1" + local os_type="$2" + local arch="$3" + local java_home="" - # Determine Java paths based on OS and architecture if [[ "$os_type" == "Darwin" ]]; then # macOS paths if [[ "$jdk_version" == "8" ]]; then java_home="/usr/local/opt/openjdk@8" - java_bin_path="/usr/local/opt/openjdk@8/bin" elif [[ "$jdk_version" == "17" ]]; then if [[ "$arch" == "arm64" ]]; then java_home="/opt/homebrew/opt/openjdk@17" - java_bin_path="/opt/homebrew/opt/openjdk@17/bin" else java_home="/usr/local/opt/openjdk@17" - java_bin_path="/usr/local/opt/openjdk@17/bin" fi fi elif [[ "$os_type" == "Linux" ]]; then - # Linux paths + # Linux paths - provide generic path for manual configuration + java_home="/usr/lib/jvm/java-$jdk_version-openjdk" + fi + + echo "$java_home" +} + +# Unified Java environment configuration function +configure_java_environment() { + local jdk_version="$1" + local os_type="$2" + local arch="$3" + local java_home="" + local java_bin_path="" + + echo "" + echo -e ">>> \033[1mConfiguring Java environment\033[0m for JDK $jdk_version..." + + # Ask user for confirmation before changing environment + echo "" + echo "This will modify your Java environment settings:" + echo " • Set JAVA_HOME to the new JDK $jdk_version installation" + echo " • Update PATH to include the new Java binaries" + echo " • Create a script (tron_java_env.sh) for easy environment setup" + echo "" + + while true; do + read -p "Do you want to configure the Java environment for JDK $jdk_version? (y/N): " yn + case $yn in + [Yy]* ) + echo ">>> Proceeding with Java environment configuration..." + break;; + [Nn]* | "" ) + echo "Java environment configuration skipped." + echo "You may need to manually set JAVA_HOME and PATH for JDK $jdk_version" + echo "" + echo "Manual configuration commands:" + + # Get the expected Java path + local expected_java_home=$(get_java_paths "$jdk_version" "$os_type" "$arch") + local expected_java_bin_path="$expected_java_home/bin" + echo " export JAVA_HOME=\"$expected_java_home\"" + echo " export PATH=\"\$JAVA_HOME/bin:\$PATH\"" + + if [[ "$os_type" == "Linux" ]]; then + echo "" + echo "Note: Actual path may vary depending on your distribution." + echo "Common paths include:" + echo " /usr/lib/jvm/java-$jdk_version-openjdk-amd64 (Ubuntu/Debian)" + echo " /usr/lib/jvm/java-1.$jdk_version.0-openjdk (RHEL/CentOS)" + fi + + # Show the same application instructions as automatic configuration + show_java_env_instructions "$expected_java_home" "$expected_java_bin_path" + + # Show permanent configuration instructions + show_permanent_java_config "$jdk_version" "$os_type" "$expected_java_home" "$expected_java_bin_path" + + echo "" + return 1;; + * ) echo "Please answer yes (y) or no (n).";; + esac + done + + # Determine Java paths based on OS and architecture + if [[ "$os_type" == "Darwin" ]]; then + # Use the helper function for macOS + java_home=$(get_java_paths "$jdk_version" "$os_type" "$arch") + java_bin_path="$java_home/bin" + elif [[ "$os_type" == "Linux" ]]; then + # Linux paths - try to find the actual installation if [[ "$jdk_version" == "8" ]]; then if [[ "$PKG_MANAGER" == "apt-get" ]]; then if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "arm64" ]]; then @@ -258,9 +372,9 @@ configure_java_environment() { if [[ -d "$java_home" ]]; then export JAVA_HOME="$java_home" export PATH="$java_bin_path:$PATH" - echo " ✅ JAVA_HOME set to: $JAVA_HOME" - echo " ✅ PATH updated to include: $java_bin_path" - echo " 🔄 Environment temporarily configured for JDK $jdk_version" + echo " JAVA_HOME set to: $JAVA_HOME" + echo " PATH updated to include: $java_bin_path" + echo " Environment temporarily configured for JDK $jdk_version" # Create a source script for the user's current shell local env_script="./tron_java_env.sh" @@ -273,54 +387,23 @@ configure_java_environment() { export JAVA_HOME="$java_home" export PATH="$java_bin_path:\$PATH" -echo "✅ Java environment configured:" +echo "Java environment configured:" echo " JAVA_HOME: \$JAVA_HOME" echo " Java version: \$(java -version 2>&1 | head -n 1)" EOF chmod +x "$env_script" echo "" - echo " 🎯 To apply Java environment to your current shell session:" - echo " source ./tron_java_env.sh" - echo "" - echo " 💡 Or run this command directly:" - echo " export JAVA_HOME=\"$java_home\"" - echo " export PATH=\"$java_bin_path:\$PATH\"" + show_java_env_instructions "$java_home" "$java_bin_path" else - echo " ⚠️ Could not find Java installation at expected path: $java_home" - echo " ⚠️ You may need to set JAVA_HOME manually" + echo " Could not find Java installation at expected path: $java_home" + echo " You may need to set JAVA_HOME manually" return 1 fi # Provide OS-specific permanent configuration instructions - echo "" - echo " ⚙️ To make JDK $jdk_version permanent:" - if [[ "$os_type" == "Darwin" ]]; then - echo " # Add to ~/.zshrc or ~/.bash_profile:" - echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.zshrc" - echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.zshrc" - echo " # Then run below command:" - echo " source ~/.zshrc" - echo "" - elif [[ "$os_type" == "Linux" ]]; then - echo " # Method 1: Add to ~/.bashrc:" - echo " echo 'export JAVA_HOME=\"$java_home\"' >> ~/.bashrc" - echo " echo 'export PATH=\"\$JAVA_HOME/bin:\$PATH\"' >> ~/.bashrc" - echo " source ~/.bashrc" - echo "" - echo " # Method 2: Use update-alternatives (recommended):" - if [[ "$PKG_MANAGER" == "apt-get" ]]; then - echo " sudo update-alternatives --install /usr/bin/java java $java_bin_path/java 1" - echo " sudo update-alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" - echo " sudo update-alternatives --config java" - else - echo " sudo alternatives --install /usr/bin/java java $java_bin_path/java 1" - echo " sudo alternatives --install /usr/bin/javac javac $java_bin_path/javac 1" - echo " sudo alternatives --config java" - fi - fi - echo "" + show_permanent_java_config "$jdk_version" "$os_type" "$java_home" "$java_bin_path" return 0 } @@ -349,7 +432,7 @@ install_macos() { if [[ "$INSTALL_GIT" == "true" ]]; then echo ">>> Installing Git..." brew install git - echo " ✅ Git installed successfully: $(git --version)" + echo " Git installed successfully: $(git --version)" fi # Skip Java installation if flag is set @@ -378,8 +461,11 @@ install_macos() { brew install openjdk@8 # Use unified Java environment configuration - configure_java_environment "8" "Darwin" "$ARCH" - echo "🔄 Environment has been updated! Java 8(1.8.*) is now configured." + if configure_java_environment "8" "Darwin" "$ARCH"; then + echo "Environment has been updated! Java 8 is now configured." + else + echo "Java 8 installed but environment not configured. You may need to set JAVA_HOME manually." + fi fi elif [[ "$ARCH" == "arm64" ]]; then @@ -402,8 +488,11 @@ install_macos() { brew install openjdk@17 # Use unified Java environment configuration - configure_java_environment "17" "Darwin" "$ARCH" - echo "🔄 Environment has been updated! Java 17 is now configured." + if configure_java_environment "17" "Darwin" "$ARCH"; then + echo "Environment has been updated! Java 17 is now configured." + else + echo "Java 17 installed but environment not configured. You may need to set JAVA_HOME manually." + fi fi else @@ -437,7 +526,7 @@ install_linux() { if [[ "$INSTALL_GIT" == "true" ]]; then echo ">>> Installing Git..." $INSTALL_CMD git - echo " ✅ Git installed successfully: $(git --version)" + echo " Git installed successfully: $(git --version)" fi # Skip Java installation if flag is set @@ -479,8 +568,11 @@ install_linux() { fi || { echo "Error: Unable to install JDK 8 on $PKG_MANAGER"; exit 1; } # Use unified Java environment configuration - configure_java_environment "8" "Linux" "$ARCH" - echo "🔄 Environment has been updated! Java 8(1.8.*) is now configured." + if configure_java_environment "8" "Linux" "$ARCH"; then + echo "Environment has been updated! Java 8 is now configured." + else + echo "Java 8 installed but environment not configured. You may need to set JAVA_HOME manually." + fi fi elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then @@ -507,8 +599,11 @@ install_linux() { fi || { echo "Error: Unable to install JDK 17 on $PKG_MANAGER"; exit 1; } # Use unified Java environment configuration - configure_java_environment "17" "Linux" "$ARCH" - echo "🔄 Environment has been updated! Java 17 is now configured." + if configure_java_environment "17" "Linux" "$ARCH"; then + echo "Environment has been updated! Java 17 is now configured." + else + echo "Java 17 installed but environment not configured. You may need to set JAVA_HOME manually." + fi fi else @@ -527,7 +622,7 @@ else fi echo "----------------------------------------" -echo -e "✅ \033[1mInstallation completed successfully!\033[0m" +echo -e "\033[1mInstallation completed successfully!\033[0m" echo "" echo ">>> Verification Commands:" echo " git --version" @@ -536,5 +631,5 @@ echo "" echo ">>> Troubleshooting:" echo -e " • If 'java -version' shows incorrect version, check \033[1mConfiguring Java environment\033[0m instructions shown above." echo "" -echo "🎉 Your development environment is ready for TRON!" +echo "Your development environment is ready for TRON!" echo "" \ No newline at end of file diff --git a/tron_java_env.sh b/tron_java_env.sh new file mode 100755 index 0000000000..9a213d09ea --- /dev/null +++ b/tron_java_env.sh @@ -0,0 +1,11 @@ + +#!/bin/bash +# TRON Java Environment Configuration +# Generated by install_dependencies.sh on Thu Jan 22 15:27:00 +08 2026 + +export JAVA_HOME="/opt/homebrew/opt/openjdk@17" +export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" + +echo "Java environment configured:" +echo " JAVA_HOME: $JAVA_HOME" +echo " Java version: $(java -version 2>&1 | head -n 1)" From 0d1394f291c40afe94719642758c6137a7a9ab08 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 15:55:45 +0800 Subject: [PATCH 05/12] delete first confirm --- install_dependencies.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index fa35421dbc..2a58a68998 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -54,7 +54,6 @@ ask_confirmation() { esac done } -ask_confirmation # Function to check Java version check_java_version() { From af35af5565108dcfec3af1f5e30aa769eb89fe56 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 15:58:35 +0800 Subject: [PATCH 06/12] delete text --- install_dependencies.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 2a58a68998..0cc71bb402 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -40,8 +40,6 @@ elif [[ "$OS" == "Linux" ]]; then fi fi echo "" -echo "WARNING: By continuing, you agree to install the above components." -echo "" # Function to ask for user confirmation ask_confirmation() { @@ -185,6 +183,7 @@ else echo "No Java installation detected!" echo " This script will install $required_jdk which is required for $ARCH architecture." echo "" + ask_confirmation SKIP_JAVA_INSTALL=false fi From ae8cb7fbbe8ee3236cc4badd5f80c4f53197ff16 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 16:11:18 +0800 Subject: [PATCH 07/12] fix format --- install_dependencies.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 0cc71bb402..1f1d2268a5 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -9,7 +9,7 @@ echo "========================================" echo " TRON Java Dependencies Installer" echo "========================================" echo "" -echo -e ">>> \033[1mEnvironment Detection\033[0m" +echo ">>> Environment Detection" if [[ "$OS" == "Darwin" ]]; then echo " OS: MacOS $OS" elif [[ "$OS" == "Linux" ]]; then @@ -22,6 +22,7 @@ echo " - macOS x86_64 (JDK 8)" echo " - macOS arm64 (JDK 17)" echo " - Linux x86_64 (generic, including Ubuntu) (JDK 8)" echo " - Linux arm64/aarch64 (generic, including Ubuntu) (JDK 17)" +echo " Note: Other platforms may require manual installation if errors occur" echo "" echo ">>> This script will install the following components if not already installed:" echo " 1. Homebrew to download and install JDK (macOS only)" @@ -101,7 +102,7 @@ ask_jdk_confirmation() { } # First, check and install Git (needed for cloning repository) -echo -e ">>> \033[1mChecking Git installation...\033[0m" +echo ">>> Checking Git installation..." if ! command -v git &> /dev/null; then echo " Git is not installed." while true; do @@ -125,7 +126,7 @@ else fi echo "" -echo -e ">>> \033[1mChecking existing Java installation...\033[0m" +echo ">>> Checking existing Java installation..." set +e # Temporarily disable exit on error check_java_version java_status=$? @@ -161,7 +162,6 @@ fi # Check if correct JDK version is already installed if [[ $java_status -eq $required_status ]]; then - echo "Correct Java version ($required_jdk) is already installed!" echo " You can skip the Java installation part." echo "" if [[ "$INSTALL_GIT" == "false" ]]; then @@ -275,14 +275,14 @@ configure_java_environment() { local java_bin_path="" echo "" - echo -e ">>> \033[1mConfiguring Java environment\033[0m for JDK $jdk_version..." + echo ">>> Configuring Java environment for JDK $jdk_version..." # Ask user for confirmation before changing environment echo "" echo "This will modify your Java environment settings:" - echo " • Set JAVA_HOME to the new JDK $jdk_version installation" - echo " • Update PATH to include the new Java binaries" - echo " • Create a script (tron_java_env.sh) for easy environment setup" + echo " - Set JAVA_HOME to the new JDK $jdk_version installation" + echo " - Update PATH to include the new Java binaries" + echo " - Create a script (tron_java_env.sh) for easy environment setup" echo "" while true; do @@ -620,14 +620,14 @@ else fi echo "----------------------------------------" -echo -e "\033[1mInstallation completed successfully!\033[0m" +echo "Installation completed successfully!" echo "" echo ">>> Verification Commands:" echo " git --version" echo " java -version" echo "" echo ">>> Troubleshooting:" -echo -e " • If 'java -version' shows incorrect version, check \033[1mConfiguring Java environment\033[0m instructions shown above." +echo " - If 'java -version' shows incorrect version, check Configuring Java environment instructions shown above." echo "" echo "Your development environment is ready for TRON!" echo "" \ No newline at end of file From c8a439445c9428243784a96a6f392d3de9bb9cd7 Mon Sep 17 00:00:00 2001 From: Edward Date: Thu, 22 Jan 2026 16:14:17 +0800 Subject: [PATCH 08/12] Delete tron_java_env.sh --- tron_java_env.sh | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100755 tron_java_env.sh diff --git a/tron_java_env.sh b/tron_java_env.sh deleted file mode 100755 index 9a213d09ea..0000000000 --- a/tron_java_env.sh +++ /dev/null @@ -1,11 +0,0 @@ - -#!/bin/bash -# TRON Java Environment Configuration -# Generated by install_dependencies.sh on Thu Jan 22 15:27:00 +08 2026 - -export JAVA_HOME="/opt/homebrew/opt/openjdk@17" -export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" - -echo "Java environment configured:" -echo " JAVA_HOME: $JAVA_HOME" -echo " Java version: $(java -version 2>&1 | head -n 1)" From cee43ece1d17d7ae34a52aa903b64fc6ef362691 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 16:21:04 +0800 Subject: [PATCH 09/12] fix git comments --- install_dependencies.sh | 2 +- tron_java_env.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 1f1d2268a5..3c7292b302 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -26,7 +26,7 @@ echo " Note: Other platforms may require manual installation if errors occur" echo "" echo ">>> This script will install the following components if not already installed:" echo " 1. Homebrew to download and install JDK (macOS only)" -echo " 2. Git for cloning the java-tron repository" +echo " 2. Git for cloning github repository" if [[ "$OS" == "Darwin" ]]; then if [[ "$ARCH" == "x86_64" ]]; then echo " 3. OpenJDK 8 (required for x86_64 architecture)" diff --git a/tron_java_env.sh b/tron_java_env.sh index 9a213d09ea..32d8ad0ae8 100755 --- a/tron_java_env.sh +++ b/tron_java_env.sh @@ -1,7 +1,7 @@ #!/bin/bash # TRON Java Environment Configuration -# Generated by install_dependencies.sh on Thu Jan 22 15:27:00 +08 2026 +# Generated by install_dependencies.sh on Thu Jan 22 16:12:18 +08 2026 export JAVA_HOME="/opt/homebrew/opt/openjdk@17" export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" From 26c2c66a049f8679f2bcdd8d35c8085dbc2e3a53 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 16:22:48 +0800 Subject: [PATCH 10/12] merge --- tron_java_env.sh | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100755 tron_java_env.sh diff --git a/tron_java_env.sh b/tron_java_env.sh deleted file mode 100755 index 32d8ad0ae8..0000000000 --- a/tron_java_env.sh +++ /dev/null @@ -1,11 +0,0 @@ - -#!/bin/bash -# TRON Java Environment Configuration -# Generated by install_dependencies.sh on Thu Jan 22 16:12:18 +08 2026 - -export JAVA_HOME="/opt/homebrew/opt/openjdk@17" -export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" - -echo "Java environment configured:" -echo " JAVA_HOME: $JAVA_HOME" -echo " Java version: $(java -version 2>&1 | head -n 1)" From 42be19604ab542eeec0acfbb256da83c25c5e5a4 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 16:23:22 +0800 Subject: [PATCH 11/12] fix format --- install_dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 3c7292b302..84f58923f5 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -26,7 +26,7 @@ echo " Note: Other platforms may require manual installation if errors occur" echo "" echo ">>> This script will install the following components if not already installed:" echo " 1. Homebrew to download and install JDK (macOS only)" -echo " 2. Git for cloning github repository" +echo " 2. Git for cloning Github repository" if [[ "$OS" == "Darwin" ]]; then if [[ "$ARCH" == "x86_64" ]]; then echo " 3. OpenJDK 8 (required for x86_64 architecture)" From 9bfb5d9f91a0374676a60b7854cc0788ed324a24 Mon Sep 17 00:00:00 2001 From: GrapeS Date: Thu, 22 Jan 2026 18:51:36 +0800 Subject: [PATCH 12/12] update homebrew --- install_dependencies.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/install_dependencies.sh b/install_dependencies.sh index 84f58923f5..d45c8aa47c 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -11,7 +11,7 @@ echo "========================================" echo "" echo ">>> Environment Detection" if [[ "$OS" == "Darwin" ]]; then - echo " OS: MacOS $OS" + echo " OS: macOS $OS" elif [[ "$OS" == "Linux" ]]; then echo " OS: $OS" fi @@ -410,8 +410,24 @@ echo "----------------------------------------" install_macos() { if ! command -v brew &> /dev/null; then - echo ">>> Homebrew not found. Installing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo ">>> Homebrew not found." + echo " Homebrew is required to install Java on macOS." + echo "" + while true; do + read -p "Do you want to install Homebrew? (y/N): " yn + case $yn in + [Yy]* ) + echo ">>> Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + break;; + [Nn]* | "" ) + echo "Homebrew installation cancelled." + echo "Cannot proceed with Java installation without Homebrew on macOS." + echo "Please install Homebrew manually or use alternative Java installation methods." + exit 1;; + * ) echo "Please answer yes (y) or no (n).";; + esac + done # Add Homebrew to PATH for the current session (Apple Silicon vs Intel) if [[ "$ARCH" == "arm64" ]]; then