diff --git a/README.md b/README.md index 4864dbef4f..0f8b30704b 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,8 @@ Network selection is performed by specifying the appropriate configuration file ### 1. Join the TRON main network Launch a main-network full node with the built-in default configuration: ```bash -nohup java -jar ./build/libs/FullNode.jar & +java -jar ./build/libs/FullNode.jar ``` -* `nohup ... &`: Runs the command in the background and ignores the hangup signal. > For production deployments or long-running Mainnet nodes, please refer to the [JVM Parameter Optimization for FullNode](https://tronprotocol.github.io/documentation-en/using_javatron/installing_javatron/#jvm-parameter-optimization-for-mainnet-fullnode-deployment) guide for the recommended Java command configuration. @@ -132,7 +131,7 @@ Use [TronScan](https://tronscan.org/#/), TRON's official block explorer, to view Utilize the `-c` flag to direct the node to the configuration file corresponding to the desired network. Since Nile TestNet may incorporate features not yet available on the MainNet, it is **strongly advised** to compile the source code following the [Building the Source Code](https://github.com/tron-nile-testnet/nile-testnet/blob/master/README.md#building-the-source-code) instructions for the Nile TestNet. ```bash -nohup java -jar ./build/libs/FullNode.jar -c config-nile.conf & +java -jar ./build/libs/FullNode.jar -c config-nile.conf ``` Nile resources: explorer, faucet, wallet, developer docs, and network statistics at [nileex.io](https://nileex.io/). diff --git a/install_dependencies.sh b/install_dependencies.sh index d45c8aa47c..f72ecf2e19 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -12,10 +12,27 @@ echo "" echo ">>> Environment Detection" if [[ "$OS" == "Darwin" ]]; then echo " OS: macOS $OS" -elif [[ "$OS" == "Linux" ]]; then +else echo " OS: $OS" fi echo " Architecture: $ARCH" + +# Validate OS and architecture support first +if [[ "$OS" != "Darwin" && "$OS" != "Linux" ]]; then + echo "Error: Unsupported OS $OS" + exit 1 +elif [[ "$OS" == "Darwin" ]]; then + if [[ "$ARCH" != "x86_64" && "$ARCH" != "arm64" ]]; then + echo "Error: Unsupported architecture for macOS: $ARCH" + exit 1 + fi +else + if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" && "$ARCH" != "arm64" ]]; then + echo "Error: Unsupported architecture for Linux: $ARCH" + exit 1 + fi +fi + echo "" echo ">>> Tested platforms:" echo " - macOS x86_64 (JDK 8)" @@ -25,19 +42,23 @@ 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)" -echo " 2. Git for cloning Github repository" +if [[ "$OS" == "Darwin" ]]; then + echo " 1. Homebrew to download and install JDK (macOS only)" + echo " 2. Git for cloning Github repository" +else + echo " 1. Git for cloning Github repository" +fi if [[ "$OS" == "Darwin" ]]; then if [[ "$ARCH" == "x86_64" ]]; then echo " 3. OpenJDK 8 (required for x86_64 architecture)" - elif [[ "$ARCH" == "arm64" ]]; then + else echo " 3. OpenJDK 17 (required for arm64 architecture)" fi -elif [[ "$OS" == "Linux" ]]; then +else 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)" + echo " 2. OpenJDK 8 (required for x86_64 architecture)" + else + echo " 2. OpenJDK 17 (required for arm64/aarch64 architecture)" fi fi echo "" @@ -62,11 +83,11 @@ check_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." + echo " JDK 8 is installed." return 0 # Check if it's JDK 17 (version starts with 17) elif [[ "$java_version" =~ ^17\. ]]; then - echo " JDK 17 is already installed." + echo " JDK 17 is installed." return 1 else echo " Different Java version detected: $java_version" @@ -86,6 +107,10 @@ ask_jdk_confirmation() { echo "" echo "JDK Version Mismatch Detected!" echo " Current version: $current_version" + echo " Current installation path: $(which java 2>/dev/null || echo 'Not found')" + if command -v java &> /dev/null && [[ -n "$JAVA_HOME" ]]; then + echo " Current JAVA_HOME: $JAVA_HOME" + fi 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." @@ -140,9 +165,6 @@ if [[ "$OS" == "Darwin" ]]; then 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 @@ -151,13 +173,7 @@ elif [[ "$OS" == "Linux" ]]; then 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 @@ -232,12 +248,16 @@ show_java_env_instructions() { local java_bin_path="$2" echo "" - echo " To apply Java environment to your current shell session:" + echo " ✓ Java environment has been applied to this script session." + echo " To apply Java environment to your current terminal session:" echo " source ./tron_java_env.sh" echo "" - echo " Or run this command directly:" + echo " Or run these commands directly:" echo " export JAVA_HOME=\"$java_home\"" echo " export PATH=\"$java_bin_path:\$PATH\"" + echo "" + echo " Note: You may need to open a new terminal or run 'source ./tron_java_env.sh'" + echo " if 'java -version' doesn't work immediately after this script completes." } # Function to get Java paths based on OS and architecture @@ -248,14 +268,36 @@ get_java_paths() { local java_home="" if [[ "$os_type" == "Darwin" ]]; then - # macOS paths + # macOS paths - try to detect actual Homebrew installation if [[ "$jdk_version" == "8" ]]; then - java_home="/usr/local/opt/openjdk@8" + # Try multiple possible paths for JDK 8 + for path in "/usr/local/opt/openjdk@8" "/opt/homebrew/opt/openjdk@8"; do + if [[ -d "$path" ]]; then + java_home="$path" + break + fi + done + # If not found, use brew --prefix to get the correct path + if [[ -z "$java_home" ]] && command -v brew &> /dev/null; then + local brew_prefix=$(brew --prefix openjdk@8 2>/dev/null || echo "") + if [[ -n "$brew_prefix" && -d "$brew_prefix" ]]; then + java_home="$brew_prefix" + fi + fi elif [[ "$jdk_version" == "17" ]]; then - if [[ "$arch" == "arm64" ]]; then - java_home="/opt/homebrew/opt/openjdk@17" - else - java_home="/usr/local/opt/openjdk@17" + # Try multiple possible paths for JDK 17 + for path in "/opt/homebrew/opt/openjdk@17" "/usr/local/opt/openjdk@17"; do + if [[ -d "$path" ]]; then + java_home="$path" + break + fi + done + # If not found, use brew --prefix to get the correct path + if [[ -z "$java_home" ]] && command -v brew &> /dev/null; then + local brew_prefix=$(brew --prefix openjdk@17 2>/dev/null || echo "") + if [[ -n "$brew_prefix" && -d "$brew_prefix" ]]; then + java_home="$brew_prefix" + fi fi fi elif [[ "$os_type" == "Linux" ]]; then @@ -311,6 +353,25 @@ configure_java_environment() { echo " /usr/lib/jvm/java-1.$jdk_version.0-openjdk (RHEL/CentOS)" fi + # Create tron_java_env.sh even when user skips configuration + echo "" + echo ">>> Creating tron_java_env.sh for manual use later..." + 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="$expected_java_home" +export PATH="$expected_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 " ✓ Created $env_script" + # Show the same application instructions as automatic configuration show_java_env_instructions "$expected_java_home" "$expected_java_bin_path" @@ -328,6 +389,31 @@ configure_java_environment() { # Use the helper function for macOS java_home=$(get_java_paths "$jdk_version" "$os_type" "$arch") java_bin_path="$java_home/bin" + + # Debug output for macOS + echo " Detected Java path: $java_home" + if [[ ! -d "$java_home" ]]; then + echo " Warning: Java home directory not found at: $java_home" + echo " Attempting to find JDK installation..." + + # Try to find the installation using brew + if command -v brew &> /dev/null; then + local brew_list=$(brew list --formula | grep "openjdk@$jdk_version" || echo "") + if [[ -n "$brew_list" ]]; then + echo " Found Homebrew package: $brew_list" + local brew_prefix=$(brew --prefix openjdk@$jdk_version 2>/dev/null || echo "") + if [[ -n "$brew_prefix" && -d "$brew_prefix" ]]; then + java_home="$brew_prefix" + java_bin_path="$java_home/bin" + echo " Updated Java path to: $java_home" + fi + else + echo " Error: openjdk@$jdk_version not found in Homebrew packages" + echo " Try running: brew list | grep openjdk" + return 1 + fi + fi + fi elif [[ "$os_type" == "Linux" ]]; then # Linux paths - try to find the actual installation if [[ "$jdk_version" == "8" ]]; then @@ -377,7 +463,6 @@ configure_java_environment() { # 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) @@ -390,8 +475,14 @@ echo " JAVA_HOME: \$JAVA_HOME" echo " Java version: \$(java -version 2>&1 | head -n 1)" EOF chmod +x "$env_script" + echo "" + echo " ✓ Created $env_script" echo "" + echo " Applying Java environment to current shell session..." + # Source the environment script to apply it immediately + source "$env_script" + show_java_env_instructions "$java_home" "$java_bin_path" else @@ -472,13 +563,19 @@ install_macos() { else echo ">>> Installing JDK 8..." fi - brew install openjdk@8 - - # Use unified Java environment configuration - if configure_java_environment "8" "Darwin" "$ARCH"; then - echo "Environment has been updated! Java 8 is now configured." + if brew install openjdk@8; then + echo ">>> JDK 8 installation completed successfully." + + # Use unified Java environment configuration + 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 else - echo "Java 8 installed but environment not configured. You may need to set JAVA_HOME manually." + echo "Error: Failed to install JDK 8 via Homebrew." + echo "Please try installing manually with: brew install openjdk@8" + exit 1 fi fi @@ -499,13 +596,19 @@ install_macos() { else echo ">>> Installing JDK 17..." fi - brew install openjdk@17 + if brew install openjdk@17; then + echo ">>> JDK 17 installation completed successfully." - # Use unified Java environment configuration - if configure_java_environment "17" "Darwin" "$ARCH"; then - echo "Environment has been updated! Java 17 is now configured." + # Use unified Java environment configuration + 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 else - echo "Java 17 installed but environment not configured. You may need to set JAVA_HOME manually." + echo "Error: Failed to install JDK 17 via Homebrew." + echo "Please try installing manually with: brew install openjdk@17" + exit 1 fi fi @@ -550,12 +653,54 @@ install_linux() { fi install_first_available() { + local target_version="$1" + shift + local installed_package="" + for pkg in "$@"; do + echo " Attempting to install: $pkg" if $INSTALL_CMD "$pkg"; then - return 0 + installed_package="$pkg" + echo " Successfully installed: $pkg" + break + else + echo " Failed to install: $pkg" fi done - return 1 + + if [[ -n "$installed_package" ]]; then + # Verify what version was actually installed + echo " Verifying installed Java version..." + if command -v java &> /dev/null; then + local actual_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + echo " Installed Java version: $actual_version" + + # Check if the installed version matches what we expected + if [[ "$target_version" == "8" ]]; then + if [[ "$actual_version" =~ ^1\.8\. ]]; then + echo " ✓ JDK 8 installed successfully" + return 0 + else + echo " ✗ Expected JDK 8 but got: $actual_version" + echo " This may happen if JDK 8 is not available in your distribution" + return 2 + fi + elif [[ "$target_version" == "17" ]]; then + if [[ "$actual_version" =~ ^17\. ]]; then + echo " ✓ JDK 17 installed successfully" + return 0 + else + echo " ✗ Expected JDK 17 but got: $actual_version" + return 2 + fi + fi + else + echo " ✗ Java command not found after installation" + return 1 + fi + else + return 1 + fi } if [[ "$ARCH" == "x86_64" ]]; then @@ -576,16 +721,86 @@ install_linux() { echo ">>> Installing JDK 8..." fi if [[ "$PKG_MANAGER" == "apt-get" ]]; then - install_first_available openjdk-8-jdk + if install_first_available "8" openjdk-8-jdk; then + install_result=0 + else + install_result=$? + fi 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 install_first_available "8" java-1.8.0-amazon-corretto-devel java-1.8.0-openjdk-devel; then + install_result=0 + else + install_result=$? + fi + fi - # Use unified Java environment configuration - if configure_java_environment "8" "Linux" "$ARCH"; then - echo "Environment has been updated! Java 8 is now configured." + if [[ $install_result -eq 0 ]]; then + # Use unified Java environment configuration + 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 + elif [[ $install_result -eq 2 ]]; then + # JDK 8 package is installed but default version is different + # Need to switch to JDK 8 using update-alternatives + local actual_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + echo ">>> JDK 8 package is installed, but system default is: $actual_version" + echo ">>> Switching system default to JDK 8 using update-alternatives..." + + # Try to switch to JDK 8 + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + local jdk8_path="/usr/lib/jvm/java-8-openjdk-amd64" + if [[ -d "$jdk8_path" ]]; then + echo " Found JDK 8 at: $jdk8_path" + # Set JDK 8 as default using update-alternatives + sudo update-alternatives --set java "$jdk8_path/jre/bin/java" 2>/dev/null || \ + sudo update-alternatives --set java "$jdk8_path/bin/java" 2>/dev/null || \ + echo " Note: Could not auto-switch. Please run: sudo update-alternatives --config java" + + sudo update-alternatives --set javac "$jdk8_path/bin/javac" 2>/dev/null || \ + echo " Note: Could not auto-switch javac. Please run: sudo update-alternatives --config javac" + + # Verify the switch + local new_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + if [[ "$new_version" =~ ^1\.8\. ]]; then + echo " ✓ Successfully switched to JDK 8: $new_version" + # Now configure environment for JDK 8 + if configure_java_environment "8" "Linux" "$ARCH"; then + echo "Environment has been updated! Java 8 is now configured." + else + echo "Java 8 is active but environment not configured. You may need to set JAVA_HOME manually." + fi + else + echo " ✗ Auto-switch failed. Current version: $new_version" + echo " Please manually switch to JDK 8:" + echo " sudo update-alternatives --config java" + echo " sudo update-alternatives --config javac" + echo " Then configure environment for JDK 8" + fi + else + echo " ✗ JDK 8 directory not found at expected location: $jdk8_path" + echo " Please manually locate and configure JDK 8" + fi + else + # For yum/dnf systems + echo " Please manually switch to JDK 8:" + echo " sudo alternatives --config java" + echo " sudo alternatives --config javac" + echo "" + echo " After switching, you can configure the environment." + + # Still create tron_java_env.sh for manual use + if configure_java_environment "8" "Linux" "$ARCH"; then + echo "Environment configuration completed for JDK 8." + else + echo "tron_java_env.sh has been created for manual use." + echo "After switching to JDK 8, run: source ./tron_java_env.sh" + fi + fi else - echo "Java 8 installed but environment not configured. You may need to set JAVA_HOME manually." + echo "Error: Unable to install any JDK on $PKG_MANAGER" + exit 1 fi fi @@ -607,16 +822,91 @@ install_linux() { echo ">>> Installing JDK 17..." fi if [[ "$PKG_MANAGER" == "apt-get" ]]; then - install_first_available openjdk-17-jdk + if install_first_available "17" openjdk-17-jdk; then + install_result=0 + else + install_result=$? + fi 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 install_first_available "17" java-17-amazon-corretto-devel java-17-openjdk-devel; then + install_result=0 + else + install_result=$? + fi + fi - # Use unified Java environment configuration - if configure_java_environment "17" "Linux" "$ARCH"; then - echo "Environment has been updated! Java 17 is now configured." + if [[ $install_result -eq 0 ]]; then + # Use unified Java environment configuration + 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 + elif [[ $install_result -eq 2 ]]; then + # JDK 17 package is installed but default version is different + # Need to switch to JDK 17 using update-alternatives + local actual_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + echo ">>> JDK 17 package is installed, but system default is: $actual_version" + echo ">>> Switching system default to JDK 17 using update-alternatives..." + + # Try to switch to JDK 17 + if [[ "$PKG_MANAGER" == "apt-get" ]]; then + local jdk17_path="" + if [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then + jdk17_path="/usr/lib/jvm/java-17-openjdk-arm64" + else + jdk17_path="/usr/lib/jvm/java-17-openjdk-amd64" + fi + + if [[ -d "$jdk17_path" ]]; then + echo " Found JDK 17 at: $jdk17_path" + # Set JDK 17 as default using update-alternatives + sudo update-alternatives --set java "$jdk17_path/bin/java" 2>/dev/null || \ + echo " Note: Could not auto-switch. Please run: sudo update-alternatives --config java" + + sudo update-alternatives --set javac "$jdk17_path/bin/javac" 2>/dev/null || \ + echo " Note: Could not auto-switch javac. Please run: sudo update-alternatives --config javac" + + # Verify the switch + local new_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) + if [[ "$new_version" =~ ^17\. ]]; then + echo " ✓ Successfully switched to JDK 17: $new_version" + # Now configure environment for JDK 17 + if configure_java_environment "17" "Linux" "$ARCH"; then + echo "Environment has been updated! Java 17 is now configured." + else + echo "Java 17 is active but environment not configured. You may need to set JAVA_HOME manually." + fi + else + echo " ✗ Auto-switch failed. Current version: $new_version" + echo " Please manually switch to JDK 17:" + echo " sudo update-alternatives --config java" + echo " sudo update-alternatives --config javac" + echo " Then configure environment for JDK 17" + fi + else + echo " ✗ JDK 17 directory not found at expected location: $jdk17_path" + echo " Please manually locate and configure JDK 17" + fi + else + # For yum/dnf systems + echo " Please manually switch to JDK 17:" + echo " sudo alternatives --config java" + echo " sudo alternatives --config javac" + echo "" + echo " After switching, you can configure the environment." + + # Still create tron_java_env.sh for manual use + if configure_java_environment "17" "Linux" "$ARCH"; then + echo "Environment configuration completed for JDK 17." + else + echo "tron_java_env.sh has been created for manual use." + echo "After switching to JDK 17, run: source ./tron_java_env.sh" + fi + fi else - echo "Java 17 installed but environment not configured. You may need to set JAVA_HOME manually." + echo "Error: Unable to install any JDK on $PKG_MANAGER" + exit 1 fi fi @@ -641,9 +931,27 @@ echo "" echo ">>> Verification Commands:" echo " git --version" echo " java -version" +echo "" + +# Verify that Java is actually working +echo ">>> Verifying Java installation..." +if command -v java &> /dev/null; then + echo " Java command found: $(which java)" + if java -version &> /dev/null; then + echo " Java version: $(java -version 2>&1 | head -n 1)" + else + echo " ✗ Java command exists but cannot run properly" + echo " Please run: source ./tron_java_env.sh" + fi +else + echo " ✗ Java command not found in PATH" + echo " Please run: source ./tron_java_env.sh" + echo " If that doesn't work, check the Java environment configuration above." +fi + echo "" echo ">>> Troubleshooting:" -echo " - If 'java -version' shows incorrect version, check Configuring Java environment instructions shown above." +echo " - If 'java -version' shows incorrect version, run: source ./tron_java_env.sh" +echo " - For permanent configuration, follow the instructions shown above." echo "" -echo "Your development environment is ready for TRON!" echo "" \ No newline at end of file