#!/bin/bash## Sets up a new Java JDK# Loosely based on https://askubuntu.com/questions/1079239/can-not-install-jdk11-using-update-alternatives-installset +eu
function usage {echo"Usage: $(basename $0) [-h] JDK [PRIORITY [ALIAS]] Configures a new Java JDK as downloaded from https://jdk.java.net and untarred into /usr/lib/jvm. -h prints this help and exits JDK the OpenJDK directory in /usr/lib/jvm/\$JDK PRIORITY an optional priority value (numeric), default: 1010 ALIAS an optional JDK alias Allows supporting multiple JDKs on the same Ubuntu installation, and the use of update-java-alternatives to switch between them. This script expects the OpenJDK root folder to be in /usr/lib/jvm and its name to match the first argument (JDK); it will also create .\$JDK.jinfo file in the /usr/lib/jvm folder (used by the update-java-alternatives command). See also: http://manpages.ubuntu.com/manpages/precise/man8/update-java-alternatives.8.html Author: Marco Massenzio (https://codetrips.com) (c) 2020. All rights reserved. Released under the Apache 2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html)"}if[[${1:-}=="-h"]];then usage
exit0fijdk=${1:-}priority=${2:-1010}alias=${3:-${jdk}}jinfo="/usr/lib/jvm/.${jdk}.jinfo"if[[ -z ${jdk}|| ! -d /usr/lib/jvm/${jdk}]];then usage
exit1ficat <<EOF >${jinfo}name=${jdk}alias=${alias}priority=${priority}section=mainEOFfor c in $(ls /usr/lib/jvm/${jdk}/bin);dobin=/usr/lib/jvm/${jdk}/bin/$c update-alternatives --install /usr/bin/$c$c${bin}${priority}echo"jdkhl $c${bin}" >>${jinfo}doneupdate-java-alternatives -s ${jdk}
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199