diff --git a/.travis.yml b/.travis.yml index 1f845d7c2..f662ef3c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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; @@ -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; @@ -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 @@ -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; @@ -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" @@ -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" @@ -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; diff --git a/build-image/openhabian.conf b/build-image/openhabian.conf index 1dfe398b0..a79490441 100644 --- a/build-image/openhabian.conf +++ b/build-image/openhabian.conf @@ -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 diff --git a/build-image/openhabian.pi-raspbian.conf b/build-image/openhabian.pi-raspbian.conf index 418d5bac5..a2f71ef51 100644 --- a/build-image/openhabian.pi-raspbian.conf +++ b/build-image/openhabian.pi-raspbian.conf @@ -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 diff --git a/build-image/openhabian.pine64-xenial.conf b/build-image/openhabian.pine64-xenial.conf index 78ea6a1c9..e208f1dec 100644 --- a/build-image/openhabian.pine64-xenial.conf +++ b/build-image/openhabian.pine64-xenial.conf @@ -27,4 +27,4 @@ wifi_country="" # Java architecture mode # Use 32-bit or 64-bit -java_arch=32-bit +java_opt=Zulu32 diff --git a/functions/adoptopenjdk-java.bash b/functions/adoptopenjdk-java.bash new file mode 100644 index 000000000..ed49efb49 --- /dev/null +++ b/functions/adoptopenjdk-java.bash @@ -0,0 +1,22 @@ +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 + cond_redirect systemctl stop openhab2.service + echo -n "$(timestamp) [openHABian] Installing AdoptOpenJDK... " + cond_redirect update-alternatives --remove-all java + 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 "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 +} diff --git a/functions/adoptopenjdk-java.bats b/functions/adoptopenjdk-java.bats new file mode 100644 index 000000000..b19ad6d6f --- /dev/null +++ b/functions/adoptopenjdk-java.bats @@ -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"* ]] +} diff --git a/functions/config.bash b/functions/config.bash index 216516b07..e7fc22d39 100644 --- a/functions/config.bash +++ b/functions/config.bash @@ -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" diff --git a/functions/helpers.bash b/functions/helpers.bash index 5e36dfe61..f7b8c5bbb 100644 --- a/functions/helpers.bash +++ b/functions/helpers.bash @@ -169,5 +169,5 @@ tryUntil() { echo -n ".${i}." ((i-=1)) done - return $i + return "$i" } diff --git a/functions/java-jre.bash b/functions/java-jre.bash index 5627d3977..57aaa527d 100644 --- a/functions/java-jre.bash +++ b/functions/java-jre.bash @@ -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 diff --git a/functions/menu.bash b/functions/menu.bash index e3016ad7b..6075bc6b2 100644 --- a/functions/menu.bash +++ b/functions/menu.bash @@ -137,9 +137,11 @@ 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 ;; @@ -147,6 +149,7 @@ show_main_menu() { 42\ *) openhab_shell_interfaces ;; 43\ *) nginx_setup ;; *Delay\ rules\ load) delayed_rules yes;; + 45\ *) update_config_java "AdoptOpenJDK" && java_install_or_update "$java_opt";; *Default\ order) delayed_rules no;; "") return 0 ;; *) whiptail --msgbox "A not supported option was selected (probably a programming error):\\n \"$choice2\"" 8 80 ;; @@ -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 diff --git a/functions/system.bash b/functions/system.bash index aaf419de5..472442064 100644 --- a/functions/system.bash +++ b/functions/system.bash @@ -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() { diff --git a/openhabian-setup.sh b/openhabian-setup.sh index 956d22aef..4e655ab29 100755 --- a/openhabian-setup.sh +++ b/openhabian-setup.sh @@ -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 diff --git a/openhabian.conf.dist b/openhabian.conf.dist index 3c6ca0d23..562535387 100644 --- a/openhabian.conf.dist +++ b/openhabian.conf.dist @@ -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