- set -e
- #so what happened, one installs with puppet openjdk 11, it doesn't work
- #and one simply uncomment the puppet code, without reverting
- #the installation, so the alternatives, that provide the link to the proper
- #java executables, are all messy. Those need to be fixed.
- LIST_OF_JAVA_ALTERNATIVES=(
- #not including the man pages and excluding those already done manually.
- #javac
- #javadoc
- #javap
- #jcmd
- #jconsole
- #jdb
- #jdeprscan
- #jdeps
- jexec
- jexec-binfmt
- jfr
- jhsdb
- jimage
- jinfo
- jjs
- jlink
- jmap
- jmod
- jps
- jrunscript
- jshell
- jstack
- jstat
- jstatd
- keytool
- pack200
- rmic
- rmid
- rmiregistry
- serialver
- unpack200
- )
- for JAVA_ALT_CMD in ${LIST_OF_JAVA_ALTERNATIVES[@]}; do
- #find if the program has the same name in the working java installation
- JAVA_CMD_PATH=$( find /opt/java/bin/ /opt/java/lib/ -iname "${JAVA_ALT_CMD}" | head -1 )
- #the two paths where things can be, given that the jre is also there but unwanted.
- #if the program is only once there add it as alternative (otherwise remove the alternative)
- #and the path is not too short (compared to the command name itself)
- if [[ ${#JAVA_CMD_PATH} -gt ${#JAVA_ALT_CMD} ]] && \
- [[ $( echo "${JAVA_CMD_PATH}" | wc -l ) -eq 1 ]]; then
- update-alternatives --install /usr/bin/$JAVA_ALT_CMD $JAVA_ALT_CMD $JAVA_CMD_PATH 2000000
- fi
- #remove the previous wrong installation
- # the installation was in one of those two locations
- # /usr/lib/jvm/java-11-openjdk-amd64/bin/cmdname
- # /usr/lib/jvm/java-11-openjdk-amd64/lib/cmdname
- update-alternatives --remove $JAVA_ALT_CMD /usr/lib/jvm/java-11-openjdk-amd64/bin/$JAVA_ALT_CMD
- update-alternatives --remove $JAVA_ALT_CMD /usr/lib/jvm/java-11-openjdk-amd64/lib/$JAVA_ALT_CMD
- echo "all fine? press enter to continue"
- read answer
- done