Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge Adopt Open jdk changes into testbuild #894

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
env: aarch64
arch: arm64
script:
- sed -i 's/java_arch=32-bit$/java_arch=64-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu64/' build-image/openhabian.conf
- docker build -t openhabian/dev-openhabian -f Dockerfile.openhabian-aarch64-native .
- docker run -i openhabian/dev-openhabian bash -c '/usr/local/bin/bats -r -f "dev-." .'
- docker run -i openhabian/dev-openhabian bash -c '/usr/local/bin/bats -r -f "unit-." .'
Expand All @@ -58,7 +58,7 @@ jobs:
script:
# 64bit Azul Java native on 64bit x86 on 64bit OS on Travis AMD64 HW
- export HW=x86
- sed -i 's/java_arch=32-bit$/java_arch=64-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-x86 .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Enterprise Java on virtual $HW ...\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -68,7 +68,7 @@ jobs:
script:
# 32bit Azul Java on 32bit ARMv6hf (RPi0(W) and RPi1) on 32bit OS on Travis Arm64 HW
- export HW=rpi01
- sed -i 's/java_arch=64-bit$/java_arch=32-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-ARMv6hf-native .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- docker run --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -78,7 +78,7 @@ jobs:
script:
# 32bit Azul Java on 32bit ARMv7l (RPi2) on 32bit OS on Travis Arm64 HW
- export HW=rpi2
- sed -i 's/java_arch=64-bit$/java_arch=32-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian
Expand All @@ -88,7 +88,7 @@ jobs:
script:
# 32bit Azul Java on 64bit ARMv8 (CM3, RPi3) on 32bit OS on Travis Arm64 HW
- export HW=cm3
- sed -i 's/java_arch=64-bit$/java_arch=32-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu32/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-CM3 .
- echo -e "\n\e[36mopenHABian test installation 32bit Azul Embedded Java on virtual $HW ...\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
Expand All @@ -99,7 +99,7 @@ jobs:
# 64bit Azul Java on 32bit ARMv8 (RPi3, CM3) on 32bit OS on Travis Arm64 HW
# This is known to not work - openHABian is supposed to downgrade to 32bit on install.
- export HW=rpi3
- sed -i 's/java_arch=32-bit$/java_arch=64-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ..."
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\n"
Expand All @@ -111,7 +111,7 @@ jobs:
# 64bit Azul Java on 64bit ARMv8 (RPi3,4) on 32bit OS on Travis Arm64 HW
# This is known to not work - openHABian is supposed to downgrade to 32bit on install.
- export HW=rpi3
- sed -i 's/java_arch=32-bit$/java_arch=64-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-native .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java on virtual $HW ..."
- echo -e "\e[31m ** This is known to not work. openHABian is supposed to force install down to 32bit **\n"
Expand All @@ -122,8 +122,18 @@ jobs:
script:
# 64bit Azul Java on 64bit ARMv8 (RPi3,4) on 64bit OS on Travis Arm64 HW
- export HW=rpi4
- sed -i 's/java_arch=32-bit$/java_arch=64-bit/' build-image/openhabian.conf
- sed -i 's/^java_opt=.*/java_opt=Zulu64/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-64bit .
- echo -e "\n\e[36mopenHABian test installation 64bit Azul Embedded Java \e[31m on 64bit OS\e[36m on virtual $HW ...\n"
- docker run --memory="2G" --memory-reservation="2G" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
- env: aarch64
arch: arm64
script:
# AdoptOpenJDK Java on 32bit ARMv7 on 32bit OS on Travis Arm64 HW
- export HW=rpi2
- sed -i 's/^java_opt=.*/java_opt=AdoptOpenJDK/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-arm32hf-native .
- echo -e "\n\e[36mopenHABian test installation 64bit AdoptOpenJDK Java \e[31m on 32bit OS\e[36m on virtual $HW ...\n"
- docker run --memory="1g" --memory-reservation="1g" --name "openhabian-${HW}" -d openhabian/${HW}-openhabian;
- docker exec -i "openhabian-${HW}" bash -c './build.bash local-test && mv ~/.profile ~/.bash_profile && /etc/rc.local'
2 changes: 1 addition & 1 deletion build-image/openhabian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ clonebranch=master
mode=unattended

# Java architecture mode
# values: "Zulu32", "Zulu64" or "AdoptOpenJDK"
# Valid arguments: "AdoptOpenJDK", "Zulu32", or "Zulu64"
java_arch=32-bit

# vim: filetype=sh
4 changes: 2 additions & 2 deletions build-image/openhabian.pi-raspbian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ wifi_country=""
# Eventually disable all IPv6 e.g. on installation problems
# values: "enable", "disable"
ipv6=enable

# repo to clone from (if not master for build and test)
repositoryurl=https://github.com/openhab/openhabian.git
clonebranch=master
Expand All @@ -38,7 +38,7 @@ clonebranch=master
mode=unattended

# Java architecture mode
# values: "Zulu32", "Zulu64" or "AdoptOpenJDK"
# Valid arguments: "AdoptOpenJDK", "Zulu32", or "Zulu64"
java_arch=32-bit

# vim: filetype=sh
4 changes: 2 additions & 2 deletions build-image/openhabian.pine64-xenial.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ wifi_country=""
# vim: filetype=sh

# Java architecture mode
# Use 32-bit or 64-bit
java_arch=32-bit
# Valid arguments: "AdoptOpenJDK", "Zulu32", or "Zulu64"
java_opt=Zulu32
8 changes: 4 additions & 4 deletions functions/config.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ clean_config_userpw() {
}

## Update java architecture in config file
## Valid options: "32-bit" & "64-bit"
## Valid options: "Zulu32", "Zulu64", "AdoptOpenJDK"
update_config_java() {
if [ "$1" == "64-bit" ]; then
if [ "$1" == "Zulu64" ]; then
if (! is_x86_64 && ! [ "$(getconf LONG_BIT)" == "64" ]) || (! is_aarch64 && ! [ "$(getconf LONG_BIT)" == "64" ]); then
if [ -n "$INTERACTIVE" ]; then
whiptail --title "Incompatible hardware detected" --msgbox "Zulu OpenJDK 64-bit: this option does not currently work on your platform.\\n\\nDefaulting to 32-bit installation." 10 60
else
echo "Zulu OpenJDK 64-bit: this option does not currently work on your platform. Defaulting to 32-bit installation."
fi
cond_redirect grep -q '^java_arch' "$CONFIGFILE" && sed -i "s/^java_arch.*/java_arch=32-bit/" "$CONFIGFILE" || echo "java_arch=32-bit" >> "$CONFIGFILE"
cond_redirect grep -q '^java_opt' "$CONFIGFILE" && sed -i "s/^java_opt.*/java_opt=Zulu32/" "$CONFIGFILE" || echo "java_opt=Zulu32" >> "$CONFIGFILE"
fi
else
cond_redirect grep -q '^java_arch' "$CONFIGFILE" && sed -i "s/^java_arch.*/java_arch=$1/" "$CONFIGFILE" || echo "java_arch=$1" >> "$CONFIGFILE"
cond_redirect grep -q '^java_opt' "$CONFIGFILE" && sed -i "s/^java_opt.*/java_opt=$1/" "$CONFIGFILE" || echo "java_opt=$1" >> "$CONFIGFILE"
fi
# shellcheck disable=SC1090
source "$CONFIGFILE"
Expand Down
2 changes: 1 addition & 1 deletion functions/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ tryUntil() {
echo -n ".${i}."
((i-=1))
done
return $i
return "$i"
}
150 changes: 116 additions & 34 deletions functions/java-jre.bash
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
#!/usr/bin/env bash
# shellcheck disable=SC2181
# shellcheck disable=SC2144

## Install appropriate Java version based on current platform.
## Valid arguments: 64-bit, 32-bit
## Install appropriate Java version based on current choice.
## Valid arguments: "AdoptOpenJDK", "Zulu32", or "Zulu64"
##
## java_install_and_update(String arch)
## java_install_and_update(String type)
##
java_install_or_update(){
# Make sure we don't overwrite existing non Java Zulu installations
if ! [ -x "$(command -v java)" ] || [[ ! "$(java -version)" == *"Zulu"* ]]; then
if [ "$1" == "64-bit" ]; then
if is_x86_64; then
java_zulu_enterprise_8_apt
# Make sure we don't overwrite existing unsupported installations
if ! [ -x "$(command -v java)" ] || [[ ! "$(java -version > /dev/null 2>&1)" == *"Zulu"* ]] || [[ ! "$(java -version > /dev/null 2>&1)" == *"AdoptOpenJDK"* ]]; then
if [ "$1" == "AdoptOpenJDK" ]; then
adoptopenjdk_install_apt
elif ! [ "$1" == "AdoptOpenJDK" ]; then
if [[ "$(java -version > /dev/null 2>&1)" == *"AdoptOpenJDK"* ]] && [ -d /opt/jdk/* ]; then
cond_redirect systemctl stop openhab2.service
cond_redirect java_alternatives_reset "Zulu"
cond_redirect systemctl start openhab2.service
else
if java_zulu_tar_update_available 64-bit; then
java_zulu_8_tar 64-bit
if [ "$1" == "Zulu64" ]; then
if is_x86_64; then
java_zulu_enterprise_8_apt
else
if java_zulu_tar_update_available 64-bit; then
java_zulu_8_tar 64-bit
fi
fi
else # Default to 32-bit installation
if java_zulu_tar_update_available 32-bit; then
java_zulu_8_tar 32-bit
fi
fi
fi

else # Default to 32-bit installation
if java_zulu_tar_update_available 32-bit; then
java_zulu_8_tar 32-bit
fi
fi
fi
cond_redirect java -version
}

## Install Java Zulu 8 directly from fetched .tar.gz file
## Valid arguments: 64-bit, 32-bit
## Valid arguments: "32-bit" or "64-bit"
##
## java_zulu_8_tar(String arch)
##
java_zulu_8_tar(){
local link
local jdkTempLocation
local jdkInstallLocation
local jdkBin
local jdkLib
local jdkArch

Expand Down Expand Up @@ -101,12 +110,9 @@ java_zulu_8_tar(){
rmdir "${jdkTempLocation}"

# Update system with new installation
jdkBin=$(find "${jdkInstallLocation}"/*/bin ... -print -quit)
jdkLib=$(find "${jdkInstallLocation}"/*/lib ... -print -quit)
cond_redirect update-alternatives --remove-all java
## TODO: remove sometime in late 2020
cond_redirect update-alternatives --remove-all javac
cond_redirect update-alternatives --install /usr/bin/java java "$jdkBin"/java 1083000
cond_redirect java_alternatives_reset "Zulu"
cond_redirect update-alternatives --remove-all javac ## TODO: remove sometime in late 2020
echo "$jdkLib"/"$jdkArch" > /etc/ld.so.conf.d/java.conf
echo "$jdkLib"/"$jdkArch"/jli >> /etc/ld.so.conf.d/java.conf
ldconfig
Expand All @@ -122,19 +128,20 @@ java_zulu_8_tar(){
##
java_zulu_enterprise_8_apt(){
if ! dpkg -s 'zulu-8' >/dev/null 2>&1; then # Check if already is installed
cond_redirect systemctl stop openhab2.service
echo -n "$(timestamp) [openHABian] Installing Zulu Enterprise 64-Bit OpenJDK... "
cond_redirect apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 219BD9C9
if [ $? -ne 0 ]; then echo "FAILED (keyserver)"; exit 1; fi
echo "deb http://repos.azulsystems.com/debian stable main" > /etc/apt/sources.list.d/zulu-enterprise.list
cond_redirect apt-get update
if cond_redirect apt-get --yes install zulu-8 && java_zulu_install_crypto_extension; then echo "OK"; else echo "FAILED"; exit 1; fi
cond_redirect systemctl start openhab2.service
fi
echo -n "$(timestamp) [openHABian] Adding Zulu keys to apt... "
cond_redirect apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 219BD9C9
if [ $? -ne 0 ]; then echo "FAILED (keyserver)"; exit 1; fi
cond_redirect systemctl stop openhab2.service
echo -n "$(timestamp) [openHABian] Installing Zulu Enterprise 64-Bit OpenJDK... "
echo "deb http://repos.azulsystems.com/debian stable main" > /etc/apt/sources.list.d/zulu-enterprise.list
cond_redirect apt-get update
if cond_redirect apt-get --yes install zulu-8 && java_zulu_install_crypto_extension; then echo "OK"; else echo "FAILED"; exit 1; fi
cond_redirect systemctl start openhab2.service
fi
}

## Fetch Java Zulu 8 directly from Azul API v1
## Valid arguments: 64-bit, 32-bit
## Valid arguments: "32-bit" or "64-bit"
##
## fetch_zulu_tar_url(String arch)
##
Expand Down Expand Up @@ -170,12 +177,12 @@ fetch_zulu_tar_url(){

## Check if a newer version of Java Zulu 8 is available.
## Returns 0 / true if new version exists
## Valid arguments: 64-bit, 32-bit
## Valid arguments: "32-bit" or "64-bit"
##
## java_zulu_tar_update_available(String arch)
##
java_zulu_tar_update_available(){
if [ ! -x "$(command -v java)" ]; then return 0; fi
if [ ! -x "$(command -v java)" ] || [[ "$(java -version 2>&1)" == *"AdoptOpenJDK"* ]]; then return 0; fi
local availableVersion
local javaVersion
local filter
Expand Down Expand Up @@ -231,3 +238,78 @@ java_zulu_install_crypto_extension(){
rm -rf "${policyTempLocation}"
return 0
}

## Fetch AdoptOpenJDK using APT repository.
##
adoptopenjdk_fetch_apt(){
local adoptKey="/tmp/adoptopenjdk.asc"
echo -n "$(timestamp) [openHABian] Adding AdoptOpenJDK keys to apt... "
cond_redirect wget -qO "$adoptKey" https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public
if cond_redirect apt-key add "$adoptKey"; then
echo "OK"
else
echo "FAILED (keyserver)"
rm -f "$adoptKey"
exit 1;
fi
echo -n "$(timestamp) [openHABian] Fetching AdoptOpenJDK... "
echo "deb http://adoptopenjdk.jfrog.io/adoptopenjdk/deb buster main" > /etc/apt/sources.list.d/adoptopenjdk.list
cond_redirect apt-get update
if cond_redirect apt-get install --download-only adoptopenjdk-8-hotspot-jre; then echo "OK"; else echo "FAILED"; exit 1; fi
}

## Install AdoptOpenJDK using APT repository.
##
adoptopenjdk_install_apt(){
if ! dpkg -s 'adoptopenjdk-8-hotspot-jre' > /dev/null 2>&1; then # Check if already is installed
echo -n "$(timestamp) [openHABian] Installing AdoptOpenJDK... "
adoptopenjdk_fetch_apt
cond_redirect systemctl stop openhab2.service
cond_redirect java_alternatives_reset
if cond_redirect apt-get install --yes adoptopenjdk-8-hotspot-jre; then echo "OK"; else echo "FAILED"; exit 1; fi
cond_redirect systemctl start openhab2.service
elif dpkg -s 'adoptopenjdk-8-hotspot-jre' >/dev/null 2>&1; then
cond_redirect systemctl stop openhab2.service
cond_redirect java_alternatives_reset
if cond_redirect dpkg-reconfigure adoptopenjdk-8-hotspot-jre; then echo "OK"; else echo "FAILED"; exit 1; fi
cond_redirect systemctl start openhab2.service
fi
}

## Reset Java in update-alternatives
## Valid arguments: "Zulu"
##
## java_alternatives_reset(String opt)
##
java_alternatives_reset(){
update-alternatives --remove-all java
update-alternatives --remove-all jjs
update-alternatives --remove-all keytool
update-alternatives --remove-all orbd
update-alternatives --remove-all pack200
update-alternatives --remove-all policytool
update-alternatives --remove-all rmid
update-alternatives --remove-all rmiregistry
update-alternatives --remove-all servertool
update-alternatives --remove-all tnameserv
update-alternatives --remove-all unpack200
update-alternatives --remove-all jexec
if [[ "$1" == "Zulu" ]]; then
local jdkBin
local jdkLib
jdkBin=$(find /opt/jdk/*/bin ... -print -quit)
jdkLib=$(find /opt/jdk/*/lib ... -print -quit)
update-alternatives --install /usr/bin/java java "$jdkBin"/java 1000000
update-alternatives --install /usr/bin/jjs jjs "$jdkBin"/jjs 1000000
update-alternatives --install /usr/bin/keytool keytool "$jdkBin"/keytool 1000000
update-alternatives --install /usr/bin/orbd orbd "$jdkBin"/orbd 1000000
update-alternatives --install /usr/bin/pack200 pack200 "$jdkBin"/pack200 1000000
update-alternatives --install /usr/bin/policytool policytool "$jdkBin"/policytool 1000000
update-alternatives --install /usr/bin/rmid rmid "$jdkBin"/rmid 1000000
update-alternatives --install /usr/bin/rmiregistry rmiregistry "$jdkBin"/rmiregistry 1000000
update-alternatives --install /usr/bin/servertool servertool "$jdkBin"/servertool 1000000
update-alternatives --install /usr/bin/tnameserv tnameserv "$jdkBin"/tnameserv 1000000
update-alternatives --install /usr/bin/unpack200 unpack200 "$jdkBin"/unpack200 1000000
update-alternatives --install /usr/bin/jexec jexec "$jdkLib"/jexec 1000000
fi
}
14 changes: 14 additions & 0 deletions functions/java-jre.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ load helpers
[[ $output == *"Zulu"* ]]
[[ $output == *"32"* ]]
}

@test "destructive-install_adopt" {
echo -e "# \e[36mAdoptOpenJDK Java installation is being (test-)installed..." >&3
run systemctl start openhab2
run adoptopenjdk_install_apt
echo -e "# \e[32mAdoptOpenJDK Java installation successful." >&3
[ "$status" -eq 0 ]
echo -e "# \e[32mAdoptOpenJDK Java installation successful." >&3
run systemctl is-active --quiet openhab2
[ "$status" -eq 0 ]
run java -version
[ "$status" -eq 0 ]
[[ $output == *"AdoptOpenJDK"* ]]
}
Loading