openjdk-17.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_OpenJDK17() {
  11. if [ "${Family}" == 'rhel' ]; then
  12. if [[ "${RHEL_ver}" =~ ^7$ ]]; then
  13. cat > /etc/yum.repos.d/adoptium.repo << EOF
  14. [Adoptium]
  15. name=Adoptium
  16. baseurl=https://mirrors.tuna.tsinghua.edu.cn/Adoptium/rpm/rhel\$releasever-\$basearch/
  17. enabled=1
  18. gpgcheck=0
  19. EOF
  20. yum -y install temurin-17-jdk
  21. JAVA_HOME=/usr/lib/jvm/temurin-17-jdk
  22. else
  23. yum -y install java-17-openjdk-devel
  24. JAVA_HOME=/usr/lib/jvm/java-17-openjdk
  25. fi
  26. elif [ "${Family}" == 'debian' ]; then
  27. if [[ "${Debian_ver}" =~ ^9$|^10$ ]]; then
  28. #wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | apt-key add -
  29. cat ${oneinstack_dir}/src/adoptium.key | sudo apt-key add -
  30. apt-add-repository --yes https://mirrors.tuna.tsinghua.edu.cn/Adoptium/deb
  31. apt -y update
  32. apt-get --no-install-recommends -y install temurin-17-jdk
  33. JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-${SYS_ARCH}
  34. else
  35. apt-get --no-install-recommends -y install openjdk-17-jdk
  36. JAVA_HOME=/usr/lib/jvm/java-17-openjdk-${SYS_ARCH}
  37. fi
  38. elif [ "${Family}" == 'ubuntu' ]; then
  39. if [[ "${Ubuntu_ver}" =~ ^16$ ]]; then
  40. cat ${oneinstack_dir}/src/adoptium.key | sudo apt-key add -
  41. apt-add-repository --yes https://mirrors.tuna.tsinghua.edu.cn/Adoptium/deb
  42. apt -y update
  43. apt-get --no-install-recommends -y install temurin-17-jdk
  44. JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-${SYS_ARCH}
  45. else
  46. apt-get --no-install-recommends -y install openjdk-17-jdk
  47. JAVA_HOME=/usr/lib/jvm/java-17-openjdk-${SYS_ARCH}
  48. fi
  49. fi
  50. if [ -e "${JAVA_HOME}/bin/java" ]; then
  51. cat > /etc/profile.d/openjdk.sh << EOF
  52. export JAVA_HOME=${JAVA_HOME}
  53. export CLASSPATH=\$JAVA_HOME/lib/tools.jar:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib
  54. EOF
  55. . /etc/profile.d/openjdk.sh
  56. echo "${CSUCCESS}OpenJDK17 installed successfully! ${CEND}"
  57. else
  58. echo "${CFAILURE}OpenJDK17 install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  59. kill -9 $$; exit 1;
  60. fi
  61. }