Skip to content

Commit

Permalink
Add Option for AdoptOpenJDK
Browse files Browse the repository at this point in the history
Fixes #868
See Also #629

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed May 8, 2020
1 parent bd72ac5 commit e9ff7bc
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 34 deletions.
27 changes: 19 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@ 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=Zulu32$/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-." .'
- env: aarch64
arch: arm64
script:
# 64bit Azul Java on 64bit ARMv8 (RPi3,4) on 64bit OS on Travis Arm64 HW
- export HW=rpi4
- sed -i 's/java_opt=Zulu64$/java_opt=AdoptOpenJDK/' build-image/openhabian.conf
- sed -i 's/java_opt=Zulu32$/java_opt=AdoptOpenJDK/' build-image/openhabian.conf
- docker build -t openhabian/${HW}-openhabian -f Dockerfile.openhabian-aarch64-64bit .
- echo -e "\n\e[36mopenHABian test installation 64bit AdoptOpenJDK 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'
- stage: BATS and shellcheck tests
env: arm32hf
arch: arm64
Expand All @@ -58,7 +69,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=Zulu32$/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 +79,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=Zulu64$/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 +89,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=Zulu64$/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 +99,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=Zulu64$/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 +110,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=Zulu32$/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 +122,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=Zulu32$/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,7 +133,7 @@ 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=Zulu32$/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;
Expand Down
2 changes: 1 addition & 1 deletion build-image/openhabian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ mode=unattended

# Java architecture mode
# Use 32-bit or 64-bit
java_arch=64-bit
java_opt=Zulu64

# vim: filetype=sh
2 changes: 1 addition & 1 deletion build-image/openhabian.pi-raspbian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ mode=unattended

# Java architecture mode
# Use 32-bit or 64-bit
java_arch=32-bit
java_opt=Zulu32

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

# Java architecture mode
# Use 32-bit or 64-bit
java_arch=32-bit
java_opt=Zulu32
23 changes: 23 additions & 0 deletions functions/adoptopenjdk-java.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
adoptopenjdk_install_apt(){
local adoptKey="/tmp/adoptopenjdk.asc"
if ! dpkg -s 'adoptopenjdk-8-hotspot-jre' >/dev/null 2>&1; then # Check if already is installed
echo -n "$(timestamp) [openHABian] Adding AdoptOpenJDK keys to apt... "
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)"; exit 1; fi
rm -f "$adoptKey"
echo -n "$(timestamp) [openHABian] Installing AdoptOpenJDK... "
cond_redirect systemctl stop openhab2.service
cond_redirect update-alternatives --remove-all java
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 --yes install adoptopenjdk-8-hotspot-jre; then echo "OK"; else echo "FAILED"; exit 1; fi
cond_redirect systemctl start openhab2.service
fi
}
adoptopenjdk_uninstall_apt(){
if dpkg -s 'adoptopenjdk-8-hotspot-jre' >/dev/null 2>&1; then
echo -n "$(timestamp) [openHABian] Removing AdoptOpenJDK... "
rm /etc/apt/sources.list.d/adoptopenjdk.list
if cond_redirect apt-get --yes remove adoptopenjdk-8-hotspot-jre; then echo "OK"; else echo "FAILED"; exit 1; fi
fi
}
16 changes: 16 additions & 0 deletions functions/adoptopenjdk-java.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load adoptopenjdk-java
load helpers

@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"* ]]
}
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"
}
33 changes: 20 additions & 13 deletions functions/java-jre.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@
# shellcheck disable=SC2181

## Install appropriate Java version based on current platform.
## Valid arguments: 64-bit, 32-bit
## Valid arguments: AdoptOpenJDK, Zulu32, Zulu64
##
## java_install_and_update(String arch)
##
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
else
if java_zulu_tar_update_available 64-bit; then
java_zulu_8_tar 64-bit
fi
# Make sure we don't overwrite existing unsupported installations
if ! [ -x "$(command -v java)" ] || [[ ! "$(java -version)" == *"Zulu"* ]] || [[ ! "$(java -version)" == *"AdoptOpenJDK"* ]]; then
if [ "$1" == "AdoptOpenJDK" ]; then
adoptopenjdk_install_apt
else
if dpkg -s 'adoptopenjdk-8-hotspot-jre' >/dev/null 2>&1; then
adoptopenjdk_uninstall_apt
fi
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
else # Default to 32-bit installation
if java_zulu_tar_update_available 32-bit; then
java_zulu_8_tar 32-bit
fi
fi
fi
fi
Expand Down
7 changes: 5 additions & 2 deletions functions/menu.bash
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ show_main_menu() {
"43 | Reverse Proxy" "Setup Nginx with password authentication and/or HTTPS access" \
"44 | Delay rules load" "Delay loading rules to speed up overall startup" \
" | Default order" "Reset config load order to default (random)" \
"45 | Use AdoptOpenJDK" "Install AdoptOpenJDK as primary java provider" \
3>&1 1>&2 2>&3)
if [ $? -eq 1 ] || [ $? -eq 255 ]; then return 0; fi
# shellcheck disable=SC2154
case "$choice2" in
41\ *) openhab2_setup ;;
*openHAB\ testing) openhab2_setup testing ;;
Expand All @@ -148,6 +150,7 @@ show_main_menu() {
43\ *) nginx_setup ;;
*Delay\ rules\ load) delayed_rules yes;;
*Default\ order) delayed_rules no;;
45\ *) update_config_java "AdoptOpenJDK" && java_install_or_update "$java_opt";;
"") return 0 ;;
*) whiptail --msgbox "A not supported option was selected (probably a programming error):\\n \"$choice2\"" 8 80 ;;
esac
Expand Down Expand Up @@ -184,8 +187,8 @@ show_main_menu() {
if [ $? -eq 1 ] || [ $? -eq 255 ]; then return 0; fi
if [[ $choosenComponents == *"62"* ]]; then apt-get upgrade -y && basic_packages && needed_packages; fi
# shellcheck disable=SC2154
if [[ $choosenComponents == *"63"* ]]; then update_config_java "32-bit"; java_install_or_update "$java_arch"; fi
if [[ $choosenComponents == *"Zulu OpenJDK 64-bit"* ]]; then update_config_java "64-bit"; java_install_or_update "$java_arch"; fi
if [[ $choosenComponents == *"63"* ]]; then update_config_java "Zulu32"; java_install_or_update "$java_opt"; fi
if [[ $choosenComponents == *"Zulu OpenJDK 64-bit"* ]]; then update_config_java "Zulu64"; java_install_or_update "$java_opt"; fi
if [[ $choosenComponents == *"64"* ]]; then openhab2_setup; fi
if [[ $choosenComponents == *"openHAB testing"* ]]; then openhab2_setup testing; fi
if [[ $choosenComponents == *"openHAB unstable"* ]]; then openhab2_setup unstable; fi
Expand Down
2 changes: 1 addition & 1 deletion functions/system.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ system_upgrade() {
echo -n "$(timestamp) [openHABian] Updating repositories and upgrading installed packages... "
cond_redirect apt-get --yes upgrade
# shellcheck disable=SC2154
if cond_redirect java_install_or_update "$java_arch"; then echo "OK"; else echo "FAILED"; exit 1; fi
if cond_redirect java_install_or_update "$java_opt"; then echo "OK"; else echo "FAILED"; exit 1; fi
}

basic_packages() {
Expand Down
2 changes: 1 addition & 1 deletion openhabian-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if [[ -n "$UNATTENDED" ]]; then
vimrc_copy
firemotd_setup
# shellcheck disable=SC2154
java_install_or_update "$java_arch"
java_install_or_update "$java_opt"
openhab2_setup
vim_openhab_syntax
nano_openhab_syntax
Expand Down
2 changes: 1 addition & 1 deletion openhabian.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ mode=unattended

# Java architecture mode
# Use 32-bit or 64-bit
java_arch=64-bit
java_opt=64-bit

# vim: filetype=sh

0 comments on commit e9ff7bc

Please sign in to comment.