Skip to content

Commit

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

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed May 5, 2020
1 parent 376177a commit fac05ed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ jobs:
- 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_arch=64-bit$/java_arch=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 Down
19 changes: 19 additions & 0 deletions functions/adoptopenjdk-java.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
adoptopenjdk_install_apt(){
if ! dpkg -s 'adoptopenjdk-8-hotspot-jre' >/dev/null 2>&1; then # Check if already is installed
cond_redirect systemctl stop openhab2.service
echo -n "$(timestamp) [openHABian] Installing AdoptOpenJDK... "
cond_redirect update-alternatives --remove-all java
if cond_redirect wget -O - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -; then echo "OK"; else echo "FAILED (keyserver)"; exit 1; fi
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
}
4 changes: 2 additions & 2 deletions functions/config.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clean_config_userpw() {
}

## Update java architecture in config file
## Valid options: "32-bit" & "64-bit"
## Valid options: "32-bit", "64-bit", "AdoptOpenJDK"
update_config_java() {
if [ "$1" == "64-bit" ]; then
if (! is_x86_64 && ! [ "$(getconf LONG_BIT)" == "64" ]) || (! is_aarch64 && ! [ "$(getconf LONG_BIT)" == "64" ]); then
Expand All @@ -41,7 +41,7 @@ update_config_java() {
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"
fi
fi
else
cond_redirect grep -q '^java_arch' "$CONFIGFILE" && sed -i "s/^java_arch.*/java_arch=$1/" "$CONFIGFILE" || echo "java_arch=$1" >> "$CONFIGFILE"
fi
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"
}
9 changes: 8 additions & 1 deletion functions/java-jre.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
##
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 ! [ -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
fi
if [ "$1" == "64-bit" ]; then
if is_x86_64; then
java_zulu_enterprise_8_apt
Expand Down
3 changes: 3 additions & 0 deletions functions/menu.bash
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,19 @@ show_main_menu() {
"42 | Remote Console" "Bind the openHAB SSH console to all external interfaces" \
"43 | Reverse Proxy" "Setup Nginx with password authentication and/or HTTPS access" \
"44 | Delay rules load" "Delay loading rules to speed up overall startup" \
"45 | Use AdoptOpenJDK" "Install AdoptOpenJDK as primary java provider" \
" | Default order" "Reset config load order to default (random)" \
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 ;;
*openHAB\ snapshot) openhab2_setup unstable ;;
42\ *) openhab_shell_interfaces ;;
43\ *) nginx_setup ;;
*Delay\ rules\ load) delayed_rules yes;;
45\ *) update_config_java "AdoptOpenJDK" && java_install_or_update "$java_arch";;
*Default\ order) delayed_rules no;;
"") return 0 ;;
*) whiptail --msgbox "A not supported option was selected (probably a programming error):\\n \"$choice2\"" 8 80 ;;
Expand Down

0 comments on commit fac05ed

Please sign in to comment.