diff --git a/.github/workflows/bats-action.yml b/.github/workflows/bats-action.yml index 9567043bc..644578af5 100644 --- a/.github/workflows/bats-action.yml +++ b/.github/workflows/bats-action.yml @@ -33,6 +33,7 @@ jobs: name: ${{ matrix.platform }} BATS runs-on: ${{ matrix.runner }} if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + strategy: matrix: include: diff --git a/.github/workflows/installation-action.yml b/.github/workflows/installation-action.yml index a456eda2c..ca1053f79 100644 --- a/.github/workflows/installation-action.yml +++ b/.github/workflows/installation-action.yml @@ -52,11 +52,17 @@ jobs: runner: ubuntu-24.04 buildx_platform: linux/amd64 java_opt: 17 - - platform: rpi3-bellsoft21 - dockerfile: ./tests/Dockerfile.rpi3-installation + - platform: rpi5-openjdk21 + dockerfile: ./tests/Dockerfile.rpi5-installation runner: ubuntu-24.04-arm - buildx_platform: linux/arm/v7 - java_opt: BellSoft21 + buildx_platform: linux/arm64 + java_opt: 21 + continue-on-error: true # Experimental currently + - platform: rpi5-temurin21 + dockerfile: ./tests/Dockerfile.rpi5-installation + runner: ubuntu-24.04-arm + buildx_platform: linux/arm64 + java_opt: Temurin21 continue-on-error: true # Experimental currently steps: @@ -65,7 +71,7 @@ jobs: - name: Setup environment run: | sudo -E ./tests/ci-setup.bash github - sed -i 's|^java_opt=.*$|java_opt=${{ matrix.java_opt }}|' build-image/openhabian.conf + sed -i 's|^java_opt=.*$|java_opt='"${{ matrix.java_opt }}"'|' build-image/openhabian.conf - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3.8.0 diff --git a/build-image/openhabian.conf b/build-image/openhabian.conf index 65720ab8a..203ff1391 100644 --- a/build-image/openhabian.conf +++ b/build-image/openhabian.conf @@ -74,7 +74,7 @@ apttimeout=60 # osrelease= # Java version to install -# Valid arguments: 11, 17, Zulu11-32, Zulu11-64, Zulu21-64 +# Valid arguments: 17, 21, Temurin17, Temurin21, 11 (legacy) java_opt=17 # install zram per default, set to "disable" to skip installation diff --git a/functions/influxdb+grafana.bash b/functions/influxdb+grafana.bash index 3fedd868d..22f2e5324 100644 --- a/functions/influxdb+grafana.bash +++ b/functions/influxdb+grafana.bash @@ -194,8 +194,8 @@ influxdb_install() { else myOS="$(lsb_release -si)" fi - myRelease="$(lsb_release -sc)" - if [[ "$myRelease" == "n/a" ]]; then + myRelease="$(lsb_release -sc | head -1)" + if [[ "$myRelease" == "n/a" ]] || running_in_docker; then myRelease=${osrelease:-bookworm} fi diff --git a/functions/java-jre.bash b/functions/java-jre.bash index 82ed6f19f..d6814b832 100644 --- a/functions/java-jre.bash +++ b/functions/java-jre.bash @@ -1,7 +1,8 @@ #!/usr/bin/env bash -## Install Java version from default repo -## Valid arguments: "11", "17" +## Install Java version from dpkg repositories dynamically. +## This function is a wrapper for the OpenJDK and Adoptium Eclipse Temurin JDK install functions. +## Valid arguments: "17", "21", "Temurin17", "Temurin21", 11 (legacy) ## ## java_install(String version) ## @@ -14,8 +15,8 @@ java_install() { java_alternatives_reset rm -rf /opt/jdk fi - if [[ $1 == "BellSoft21" ]]; then - liberica_install_apt + if [[ $1 == Temurin* ]]; then + adoptium_install_apt "${1/Temurin/}" else openjdk_install_apt "$1" fi @@ -25,443 +26,91 @@ java_install() { fi } -## Fetch OpenJDK using APT repository. +## Fetch Adoptium Eclipse Temurin JDK builds (AdoptOpenJDK) using APT repository. ## -## openjdk_fetch_apt() +## adoptium_fetch_apt() ## -openjdk_fetch_apt() { - if ! apt-cache show "openjdk-${1}-jre-headless" &> /dev/null; then - if is_pi; then - echo "deb http://archive.raspberrypi.org/debian/ ${osrelease:-bookworm} main" > /etc/apt/sources.list.d/java.list - else - echo "deb http://deb.debian.org/debian/ stable main" > /etc/apt/sources.list.d/java.list - fi - cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC - cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138 +adoptium_fetch_apt() { + local keyName="adoptium" - # important to avoid release mixing: - # prevent RPi from using the Debian distro for normal Raspbian packages - # echo -e "Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n" > /etc/apt/preferences.d/limit-unstable - fi + echo -n "$(timestamp) [openHABian] Fetching Adoptium Eclipse Temurin JDK... " + if ! cond_redirect add_keys "https://packages.adoptium.net/artifactory/api/gpg/key/public" "$keyName"; then echo "FAILED (add keys)"; return 1; fi + echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://packages.adoptium.net/artifactory/deb ${osrelease:-bookworm} main" > /etc/apt/sources.list.d/adoptium.list - dpkg --configure -a - echo -n "$(timestamp) [openHABian] Fetching OpenJDK ${1}... " - if cond_redirect apt-get install --download-only --yes "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi + if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi + if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi + if cond_redirect apt-get install --download-only --yes "temurin-${1}-jre"; then echo "OK"; else echo "FAILED"; return 1; fi } -## Install OpenJDK using APT repository. +## Install Adoptium Eclipse Temurin JDK builds (AdoptOpenJDK) using APT repository. ## -## openjdk_install_apt() +## adoptium_install_apt() ## -openjdk_install_apt() { - if ! dpkg -s "openjdk-${1}-jre-headless" &> /dev/null; then # Check if already is installed - openjdk_fetch_apt "$1" - echo -n "$(timestamp) [openHABian] Installing OpenJDK ${1}... " +adoptium_install_apt() { + if ! dpkg -s "temurin-${1}-jre" &> /dev/null; then # Check if already is installed + adoptium_fetch_apt "$1" + echo -n "$(timestamp) [openHABian] Installing Adoptium Eclipse Temurin JDK... " cond_redirect java_alternatives_reset - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi - elif dpkg -s "openjdk-${1}-jre-headless" &> /dev/null; then - echo -n "$(timestamp) [openHABian] Reconfiguring OpenJDK ${1}... " - cond_redirect java_alternatives_reset - if cond_redirect dpkg-reconfigure "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi - update-alternatives --set java /usr/lib/jvm/java-"${1}"-openjdk-armhf/bin/java - fi -} - -## Fetch BellSoft Liberica JDK using APT repository. -## -## liberica_fetch_apt() -## -liberica_fetch_apt() { - local pkgname="bellsoft-java21-lite" - if ! apt-cache show $pkgname &> /dev/null; then - local keyName="bellsoft_liberica" - - if ! add_keys "https://download.bell-sw.com/pki/GPG-KEY-bellsoft" "$keyName"; then return 1; fi - - echo -n "$(timestamp) [openHABian] Adding BellSoft repository to apt... " - - # architectures available: amd64, i386, arm64, armhf; those could be added to the repo string via [arch=...] - if ! echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://apt.bell-sw.com/ stable main" > /etc/apt/sources.list.d/bellsoft.list; then echo "FAILED"; return 1; fi - if cond_redirect apt-get update; then echo "OK"; else echo "FAILED (update apt lists)"; return 1; fi - fi -} - -## Install BellSoft Liberica JDK using APT repository. -## -## liberica_install_apt() -## -liberica_install_apt() { - local pkgname="bellsoft-java21-lite" - if ! dpkg -s $pkgname &> /dev/null; then # Check if already is installed - liberica_fetch_apt - echo -n "$(timestamp) [openHABian] Installing BellSoft Liberica JDK... " - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" $pkgname; then echo "OK"; else echo "FAILED"; return 1; fi - elif dpkg -s $pkgname &> /dev/null; then - echo -n "$(timestamp) [openHABian] Reconfiguring BellSoft Liberica JDK... " - if cond_redirect dpkg-reconfigure $pkgname; then echo "OK"; else echo "FAILED"; return 1; fi - # shellcheck disable=SC2012 - update-alternatives --set java "$(ls -d /usr/lib/jvm/bellsoft-java21-lite-* | head -n1)"/bin/java - fi -} - -# LEGACY SECTION - -## Install appropriate Java version based on current choice. -## Valid arguments: "Adopt11", "Zulu11-32", or "Zulu11-64" -## -## java_install_or_update(String type) -## -java_install_or_update() { - # Just in case it gets called with the new arguments - if [[ $1 -eq 11 ]] || [[ $1 -eq 17 ]]; then java_install "$1"; return 0; fi - - local branch - - branch="$(git -C "${BASEDIR:-/opt/openhabian}" rev-parse --abbrev-ref HEAD)" - - # Make sure we don't overwrite existing unsupported installations - if ! [[ -x $(command -v java) ]] || [[ "$(java -version 2>&1 > /dev/null)" == *"Zulu"* ]] || dpkg -s 'openjdk-11-jre-headless' &> /dev/null || dpkg -s 'openjdk-17-jre-headless' &> /dev/null; then - if ! [[ -x $(command -v java) ]] && [[ "${cached_java_opt:-Zulu11-32}" == "${java_opt:-Zulu11-32}" ]] && [[ -n $UNATTENDED ]] && java_zulu_dir; then - echo "$(timestamp) [openHABian] Installing cached version of Java to ensure that some form of Java is installed!" - java_zulu_prerequisite "${cached_java_opt:-Zulu11-32}" - java_zulu_install "${cached_java_opt:-Zulu11-32}" - fi - if [[ $1 == "Zulu11-64" ]] || [[ $1 == "Zulu21-64" ]]; then - if is_aarch64 || is_x86_64 && [[ $(getconf LONG_BIT) == 64 ]]; then - if is_x86_64; then - java_zulu_enterprise_apt "$@" - else - if cond_redirect java_zulu_update_available "$1"; then - java_zulu_prerequisite "$1" - if [[ $branch == "openHAB3" ]] && [[ -z $UNATTENDED ]]; then - java_zulu_stable "$1" - else - java_zulu_fetch "$1" - java_zulu_install "$1" - fi - fi - fi - else - 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 Java Zulu 11 32-bit installation." 9 80 - else - echo "$(timestamp) [openHABian] Zulu OpenJDK 64-bit: this option does not currently work on your platform. Defaulting to Java Zulu 11 32-bit installation." - if cond_redirect java_zulu_update_available "Zulu11-32"; then - java_zulu_prerequisite "Zulu11-32" - if [[ $branch == "openHAB3" ]] && [[ -z $UNATTENDED ]]; then - java_zulu_stable "Zulu11-32" - else - java_zulu_fetch "Zulu11-32" - java_zulu_install "Zulu11-32" - fi - fi - fi - fi - elif [[ $1 == "BellSoft21" ]]; then - liberica_install_apt - else # Default to 32-bit installation - if cond_redirect java_zulu_update_available "Zulu11-32"; then - java_zulu_prerequisite "Zulu11-32" - if [[ $branch == "openHAB3" ]] && [[ -z $UNATTENDED ]]; then - java_zulu_stable "Zulu11-32" - else - java_zulu_fetch "Zulu11-32" - java_zulu_install "Zulu11-32" - fi - fi - fi - fi - if [[ -x $(command -v java) ]]; then - cond_redirect java --version - else - echo "$(timestamp) [openHABian] Somewhere, somehow, something went wrong and Java has not been installed. Until resolved, openHAB will be broken." - fi -} - -## Install Java Zulu prerequisites (libc, libstdc++, zlib1g) -## Valid arguments: "Zulu11-32" or "Zulu11-64" -## -## java_zulu_prerequisite(String type) -## -java_zulu_prerequisite() { - echo -n "$(timestamp) [openHABian] Installing Java Zulu prerequisites (libc, libstdc++, zlib1g)... " - if [[ $1 == "Zulu11-64" ]]; then - if is_aarch64 && [[ $(getconf LONG_BIT) == 64 ]]; then - if dpkg -s 'libc6:arm64' 'libstdc++6:arm64' 'zlib1g:arm64' &> /dev/null; then echo "OK"; return 0; fi - dpkg --add-architecture arm64 - if [[ -z $OFFLINE ]]; then - if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - fi - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" libc6:arm64 libstdc++6:arm64 zlib1g:arm64; then echo "OK"; else echo "FAILED"; return 1; fi - elif is_x86_64 && [[ $(getconf LONG_BIT) == 64 ]]; then - if dpkg -s 'libc6:amd64' 'libstdc++6:amd64' 'zlib1g:amd64' &> /dev/null; then echo "OK"; return 0; fi - dpkg --add-architecture amd64 - if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" libc6:amd64 libstdc++6:amd64 zlib1g:amd64; then echo "OK"; else echo "FAILED"; return 1; fi - fi + if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" "temurin-${1}-jre"; then echo "OK"; else echo "FAILED"; return 1; fi else - if is_arm; then - if dpkg -s 'libc6:armhf' 'libstdc++6:armhf' 'zlib1g:armhf' &> /dev/null; then echo "OK"; return 0; fi - dpkg --add-architecture armhf - if [[ -z $OFFLINE ]]; then - if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - fi - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" libc6:armhf libstdc++6:armhf zlib1g:armhf; then echo "OK"; else echo "FAILED"; return 1; fi - else - if dpkg -s 'libc6:i386' 'libstdc++6:i386' 'zlib1g:i386' &> /dev/null; then echo "OK"; return 0; fi - dpkg --add-architecture i386 - if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" libc6:i386 libstdc++6:i386 zlib1g:i386; then echo "OK"; else echo "FAILED"; return 1; fi + echo -n "$(timestamp) [openHABian] Reconfiguring Adoptium Eclipse Temurin JDK... " + cond_redirect java_alternatives_reset + if cond_redirect dpkg-reconfigure "temurin-${1}-jre"; then echo "OK"; else echo "FAILED"; return 1; fi + if is_aarch64; then + update-alternatives --set java /usr/lib/jvm/temurin-"${1}"-jre-arm64/bin/java + elif is_armv6l || is_armv7l; then + update-alternatives --set java /usr/lib/jvm/temurin-"${1}"-jre-armhf/bin/java fi fi } -## Use special handling when installing Zulu on the stable branch -## Valid arguments: "Zulu11-32" or "Zulu11-64" -## -## java_zulu_stable(String type) -## -java_zulu_stable() { - local updateText - local consoleText - - updateText="Updating Java may result in issues as it has not received extensive testing to verify compatibility.\\n\\nIf you wish to continue and encounter any errors please let us know so we can look into them to improve future compatibility." - consoleText="[openHABian] WARNING: Untested Java Version, you may experience issues as this version of Java has not received extensive testing to verify compatibility." - - if [[ -n $INTERACTIVE ]]; then - if ! (whiptail --defaultno --title "Untested Version of Java" --no-button "Back" --yes-button "Continue" --yesno "$updateText" 11 80); then echo "CANCELED"; return 0; fi - else - echo "$(timestamp) [openHABian] $consoleText" - fi - java_zulu_fetch "$1" - java_zulu_install "$1" -} - -## Install Java Zulu directly from fetched files -## Valid arguments: "Zulu11-32", or "Zulu11-64" +## Fetch OpenJDK using APT repository. ## -## java_zulu_install(String type) +## openjdk_fetch_apt() ## -java_zulu_install() { - local jdkBin - local jdkLib - - jdkBin="$(find /opt/jdk/*/bin ... -print -quit)" - jdkLib="$(find /opt/jdk/*/lib ... -print -quit)" +openjdk_fetch_apt() { + local keyName="debian-bookworm" - if [[ $1 == "Zulu11-32" ]]; then - echo -n "$(timestamp) [openHABian] Installing Java Zulu 11 32-Bit OpenJDK... " - elif [[ $1 == "Zulu11-64" ]]; then - echo -n "$(timestamp) [openHABian] Installing Java Zulu 11 64-Bit OpenJDK... " - elif [[ $1 == "Zulu21-64" ]]; then - echo -n "$(timestamp) [openHABian] Installing Java Zulu 21 64-Bit OpenJDK... " + echo -n "$(timestamp) [openHABian] Fetching OpenJDK ${1}... " + if [[ $1 == "21" ]]; then + if ! cond_redirect add_keys "https://ftp-master.debian.org/keys/archive-key-12.asc" "$keyName"; then echo "FAILED (add keys)"; return 1; fi # Add keys for older systems that need them + echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/java.list + # Avoid release mixing: prevent RPi from using the Debian distro for normal Raspbian packages + echo -e "Package: *\\nPin: release a=unstable\\nPin-Priority: 90\\n" > /etc/apt/preferences.d/limit-unstable + if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi + + if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi + if cond_redirect apt-get install --download-only --yes -t unstable "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED (download)"; return 1; fi else - echo "$(timestamp) [openHABian] Installing something that probably won't work... FAILED" - return 1 - fi - - if openhab_is_running; then - cond_redirect systemctl stop openhab.service - fi - - java_alternatives_reset - # shellcheck disable=SC2016 - cond_redirect find "$jdkBin" -maxdepth 1 -perm -111 -type f -exec bash -c 'update-alternatives --install /usr/bin/$(basename {}) $(basename {}) {} 1000000' \; - echo "$jdkLib" > /etc/ld.so.conf.d/java.conf - echo "$jdkLib"/jli >> /etc/ld.so.conf.d/java.conf - echo "$jdkLib"/client >> /etc/ld.so.conf.d/java.conf - if ldconfig; then echo "OK"; else echo "FAILED"; return 1; fi - - java_zulu_install_crypto_extension "$@" - - if openhab_is_installed; then - cond_redirect systemctl restart openhab.service - fi -} - -## Fetch Java Zulu directly from Azul API v1 -## Valid arguments: "Zulu11-32" or "Zulu11-64" -## -## java_zulu_fetch(String type, String prefix) -## -java_zulu_fetch() { - local downloadLink - local jdkInstallLocation - local link - local temp - - jdkInstallLocation="${2}/opt/jdk" - link="https://api.azul.com/zulu/download/community/v1.0/bundles/latest/binary/?os=linux&ext=tar.gz&javafx=false" - temp="$(mktemp "${TMPDIR:-/tmp}"/openhabian.XXXXX)" - - if [[ $1 == "Zulu11-32" ]]; then - echo -n "$(timestamp) [openHABian] Downloading Java Zulu 11 32-Bit OpenJDK... " - if is_arm; then - downloadLink="$(curl "${link}&jdk_version=11&arch=arm&hw_bitness=32&abi=hard_float" -s -L -I -o /dev/null -w '%{url_effective}')" - else - downloadLink="$(curl "${link}&jdk_version=11&arch=x86&hw_bitness=32&bundle_type=jre" -s -L -I -o /dev/null -w '%{url_effective}')" - fi - elif [[ $1 == "Zulu11-64" ]]; then - echo -n "$(timestamp) [openHABian] Downloading Java Zulu 11 64-Bit OpenJDK... " - if is_arm; then - downloadLink="$(curl "${link}&jdk_version=11&arch=arm&hw_bitness=64" -s -L -I -o /dev/null -w '%{url_effective}')" - else - downloadLink="$(curl "${link}&jdk_version=11&arch=x86&hw_bitness=64&bundle_type=jre" -s -L -I -o /dev/null -w '%{url_effective}')" - fi - elif [[ $1 == "Zulu21-64" ]]; then - echo -n "$(timestamp) [openHABian] Downloading Java Zulu 21 64-Bit OpenJDK... " - if is_arm; then - downloadLink="$(curl "${link}&jdk_version=21&arch=arm&hw_bitness=64" -s -L -I -o /dev/null -w '%{url_effective}')" - else - downloadLink="$(curl "${link}&jdk_version=21&arch=x86&hw_bitness=64&bundle_type=jre" -s -L -I -o /dev/null -w '%{url_effective}')" - fi + if ! cond_redirect dpkg --configure -a; then echo "FAILED (dpkg)"; return 1; fi + if cond_redirect apt-get install --download-only --yes "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED (download)"; return 1; fi fi - if [[ -z $downloadLink ]]; then echo "FAILED (download link)"; return 1; fi - - if ! mkdir -p "$jdkInstallLocation"; then echo "FAILED (create directory)"; return 1; fi - if ! cond_redirect wget -nv -O "$temp" "$downloadLink"; then echo "FAILED (download)"; rm -f "$temp"; return 1; fi - if ! cond_redirect tar -xpzf "$temp" -C "$jdkInstallLocation"; then echo "FAILED (extract)"; rm -rf "${jdkInstallLocation:?}/$(basename "$downloadLink" | sed -e 's/.tar.gz//')"; rm -f "$temp"; return 1; fi - if ! cond_redirect find "$jdkInstallLocation" -mindepth 1 -maxdepth 1 -name "$(basename "$downloadLink" | sed -e 's/.tar.gz//')" -prune -o -exec rm -rf {} \;; then echo "FAILED (clean directory)"; return 1; fi - if rm -f "$temp"; then echo "OK"; else echo "FAILED (cleanup)"; return 1; fi } -## Check if a newer version of Java Zulu is available. -## Returns 0 / true if new version exists -## Valid arguments: "Zulu11-32" or "Zulu11-64" +## Install OpenJDK using APT repository. ## -## java_zulu_update_available(String type) +## openjdk_install_apt() ## -java_zulu_update_available() { - if ! [[ -x $(command -v java) ]]; then return 0; fi - - local availableVersion - local filter - local javaArch - local javaVersion - local jdkBin - local link - local requestedArch - - if ! [[ -x $(command -v jq) ]]; then - echo -n "$(timestamp) [openHABian] Installing Java Zulu prerequisites (jq)... " - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" jq; then echo "OK"; else echo "FAILED"; return 1; fi - fi - - filter='[.jdk_version[] | tostring] | join(".")' - jdkBin="$(find /opt/jdk/*/bin ... -print -quit)" - # shellcheck disable=SC1117 - javaVersion="$("${jdkBin}"/java -version |& grep -m 1 -o "[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}[\.+][0-9]\{0,3\}" | head -1 | sed 's|+|.|g')" - link="https://api.azul.com/zulu/download/community/v1.0/bundles/latest/?os=linux&ext=tar.gz&javafx=false" - - if [[ $1 == "Zulu11-32" ]]; then - if is_arm; then - requestedArch="aarch32hf" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=11&arch=arm&hw_bitness=32&abi=hard_float" | jq -r "$filter")" - else - requestedArch="i686" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=11&arch=x86&hw_bitness=32&bundle_type=jre" | jq -r "$filter")" - fi - elif [[ $1 == "Zulu11-64" ]]; then - if is_arm; then - requestedArch="aarch64" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=11&arch=arm&hw_bitness=64" | jq -r "$filter")" - else - requestedArch="x64" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=11&arch=x86&hw_bitness=64&bundle_type=jre" | jq -r "$filter")" - fi - elif [[ $1 == "Zulu21-64" ]]; then - if is_arm; then - requestedArch="aarch64" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=21&arch=arm&hw_bitness=64" | jq -r "$filter")" +openjdk_install_apt() { + if ! dpkg -s "openjdk-${1}-jre-headless" &> /dev/null; then # Check if already is installed + openjdk_fetch_apt "$1" + echo -n "$(timestamp) [openHABian] Installing OpenJDK ${1}... " + cond_redirect java_alternatives_reset + if [[ $1 == "21" ]]; then + if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" -t unstable "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi else - requestedArch="x64" - availableVersion="$(curl -s -H "Accept: application/json" "${link}&jdk_version=21&arch=x86&hw_bitness=64&bundle_type=jre" | jq -r "$filter")" - fi - fi - if [[ -z $requestedArch ]] || [[ -z $availableVersion ]]; then echo "FAILED (java update available)"; return 1; fi - - if [[ $jdkBin == *"aarch32hf"* ]]; then javaArch="aarch32hf"; fi - if [[ $jdkBin == *"i686"* ]]; then javaArch="i686"; fi - if [[ $jdkBin == *"aarch64"* ]]; then javaArch="aarch64"; fi - if [[ $jdkBin == *"x64"* ]]; then javaArch="x64"; fi - - if [[ $javaVersion == "$availableVersion" ]] && [[ $javaArch == "$requestedArch" ]]; then - return 1 # Java is up-to-date - fi -} - -## Install Azul's Java Zulu Enterprise using APT repository. -## Package manager distributions are only available on x86-64bit platforms when checked in January 2021 -## -## java_zulu_enterprise_apt(String ver) -## -java_zulu_enterprise_apt() { - local keyName="zulu_enterprise" - - if ! add_keys "https://www.azul.com/files/0xB1998361219BD9C9.txt" "$keyName"; then return 1; fi - - echo -n "$(timestamp) [openHABian] Adding Zulu repository to apt... " - if ! echo "deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://repos.azul.com/zulu/deb/ stable main" > /etc/apt/sources.list.d/zulu-enterprise.list; then echo "FAILED"; return 1; fi - if cond_redirect apt-get update; then echo "OK"; else echo "FAILED (update apt lists)"; return 1; fi - - if openhab_is_running; then - cond_redirect systemctl stop openhab.service - fi - if [[ $1 == "Zulu21-64" ]]; then - if ! dpkg -s 'zulu-21' &> /dev/null; then - echo -n "$(timestamp) [openHABian] Installing Zulu 21 Enterprise 64-Bit OpenJDK... " - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" zulu21; then echo "OK"; else echo "FAILED"; return 1; fi + if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi fi else - if ! dpkg -s 'zulu-11' &> /dev/null; then - echo -n "$(timestamp) [openHABian] Installing Zulu 11 Enterprise 64-Bit OpenJDK... " - if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" zulu11; then echo "OK"; else echo "FAILED"; return 1; fi + echo -n "$(timestamp) [openHABian] Reconfiguring OpenJDK ${1}... " + cond_redirect java_alternatives_reset + if cond_redirect dpkg-reconfigure "openjdk-${1}-jre-headless"; then echo "OK"; else echo "FAILED"; return 1; fi + if is_aarch64; then + update-alternatives --set java /usr/lib/jvm/java-"${1}"-openjdk-arm64/bin/java + elif is_armv6l || is_armv7l; then + update-alternatives --set java /usr/lib/jvm/java-"${1}"-openjdk-armhf/bin/java fi fi - if openhab_is_installed; then - cond_redirect systemctl restart openhab.service - fi - - java_zulu_install_crypto_extension "$@" -} - -## Install Zulu Cryptography Extension Kit to enable cryptos using more then 128 bits -## -## java_zulu_install_crypto_extension(String path) -## -# shellcheck disable=SC2120 -java_zulu_install_crypto_extension() { - if [[ -n $OFFLINE ]]; then - echo "$(timestamp) [openHABian] Using cached Java Zulu CEK to enable unlimited cipher strength... OK" - return 0 - fi - - local jdkSecurity - local policyTempLocation - - jdkSecurity="${1:-"$(realpath /usr/bin/java | sed 's|/java||')/../lib/security"}" - policyTempLocation="$(mktemp -d "${TMPDIR:-/tmp}"/openhabian.XXXXX)" - - echo -n "$(timestamp) [openHABian] Installing Java Zulu CEK to enable unlimited cipher strength... " - if ! cond_redirect mkdir -p "$jdkSecurity"; then echo "FAILED (create directory)"; return 1; fi - if ! cond_redirect wget -qO "$policyTempLocation"/crypto.zip https://cdn.azul.com/zcek/bin/ZuluJCEPolicies.zip; then echo "FAILED (download)"; rm -rf "$policyTempLocation"; return 1; fi - if ! cond_redirect unzip "$policyTempLocation"/crypto.zip -d "$policyTempLocation"; then echo "FAILED (unzip)"; rm -rf "$policyTempLocation"; return 1; fi - if cond_redirect cp -u "$policyTempLocation"/ZuluJCEPolicies/*.jar "$jdkSecurity"; then echo "OK"; else echo "FAILED (copy)"; rm -rf "$policyTempLocation"; return 1; fi - - cond_redirect rm -rf "$policyTempLocation" -} - -## Check if Java Zulu is already in the filesystem -## -## java_zulu_dir() -## -java_zulu_dir() { - local dir - - for dir in /opt/jdk/*; do - if [[ -d $dir ]]; then return 0; fi - done - return 1 } ## Reset Java in update-alternatives diff --git a/functions/java-jre.bats b/functions/java-jre.bats index 8134862bf..ec5aecaf6 100644 --- a/functions/java-jre.bats +++ b/functions/java-jre.bats @@ -11,10 +11,26 @@ load helpers.bash echo -e "# ${COL_GREEN}$(timestamp) [openHABian] OpenJDK 17 Java installation successful.${COL_DEF}" >&3 } -@test "installation-java_install_zulujdk21" { - echo -e "# ${COL_CYAN}$(timestamp) [openHABian] Azul Zulu JDK 21 Java is being (test-)installed...${COL_DEF}" >&3 - run java_install_or_update "Zulu21-64" 3>&- +@test "installation-java_install_openjdk21" { + echo -e "# ${COL_CYAN}$(timestamp) [openHABian] OpenJDK 21 Java is being (test-)installed...${COL_DEF}" >&3 + run java_install "21" 3>&- if [ "$status" -ne 0 ]; then echo "$output" >&3; fi [ "$status" -eq 0 ] - echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Azul Zulu JDK 21 Java installation successful.${COL_DEF}" >&3 + echo -e "# ${COL_GREEN}$(timestamp) [openHABian] OpenJDK 21 Java installation successful.${COL_DEF}" >&3 +} + +@test "installation-java_install_temurin17" { + echo -e "# ${COL_CYAN}$(timestamp) [openHABian] Temurin 17 Java is being (test-)installed...${COL_DEF}" >&3 + run java_install "Temurin17" 3>&- + if [ "$status" -ne 0 ]; then echo "$output" >&3; fi + [ "$status" -eq 0 ] + echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Temurin 17 Java installation successful.${COL_DEF}" >&3 +} + +@test "installation-java_install_temurin21" { + echo -e "# ${COL_CYAN}$(timestamp) [openHABian] Temurin 21 Java is being (test-)installed...${COL_DEF}" >&3 + run java_install "Temurin21" 3>&- + if [ "$status" -ne 0 ]; then echo "$output" >&3; fi + [ "$status" -eq 0 ] + echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Temurin 21 Java installation successful.${COL_DEF}" >&3 } diff --git a/functions/menu.bash b/functions/menu.bash index 181e742e8..a0a6ef6df 100644 --- a/functions/menu.bash +++ b/functions/menu.bash @@ -31,7 +31,6 @@ Menu 50 provides options to backup and restore either your openHAB configuration show_main_menu() { local choice local version - local javaVersion choice=$(whiptail --title "openHABian Configuration Tool — $(get_git_revision)" --menu "Setup Options" 24 118 16 --cancel-button Exit --ok-button Execute \ @@ -74,13 +73,6 @@ show_main_menu() { return 255 fi - javaVersion="$(java -version |& grep -m 1 -o "[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}[\.+][0-9]\{0,3\}" | head -1|cut -d '.' -f1)" - if [[ $(apt-cache madison openhab | head -n 1 | awk '{ print $3 }' | cut -d'.' -f1) = 4 ]]; then - if [[ $javaVersion -lt 17 ]] ; then - update_config_java "17" - java_install "17" - fi - fi repo=$(apt-cache madison openhab | head -n 1 | awk '{ print $6 }' |cut -d'/' -f1) # shellcheck disable=SC2154 openhab_setup "${repo:-release}" "${openhabpkgversion}" @@ -219,12 +211,11 @@ show_main_menu() { "42 | Remote Console" "Bind the openHAB SSH console to all external interfaces" \ "43 | Clean cache" "Clean the cache for openHAB" \ "44 | Nginx Proxy" "Setup reverse and forward web proxy" \ - "45 | OpenJDK 17" "Install and activate OpenJDK 17 as Java provider (now default)" \ - " | OpenJDK 11" "Install and activate OpenJDK 11 as Java provider" \ - " | Zulu 11 OpenJDK 32-bit" "Install Zulu 11 32-bit OpenJDK as Java provider" \ - " | Zulu 11 OpenJDK 64-bit" "Install Zulu 11 64-bit OpenJDK as Java provider" \ - " | Zulu 21 OpenJDK 64-bit" "Install Zulu 21 64-bit OpenJDK as Java provider" \ - " | BellSoft Liberica JDK 21" "Install BellSoft Liberica JDK 21, supports 32bit RPi (EXPERIMENTAL)" \ + "45 | OpenJDK 17" "Install and activate OpenJDK 17 as Java provider (default)" \ + " | OpenJDK 21" "Install and activate OpenJDK 21 as Java provider (upcoming default)" \ + " | Temurin 17" "Install and activate Temurin 17 as Java provider (default alternative)" \ + " | Temurin 21" "Install and activate Temurin 21 as Java provider (upcoming alternative default)" \ + " | OpenJDK 11" "Install and activate OpenJDK 11 as Java provider (legacy)" \ "46 | Install openhab-js" "JS Scripting: Upgrade to latest version of openHAB JavaScript library (advanced)" \ " | Uninstall openhab-js" "JS Scripting: Switch back to included version of openHAB JavaScript library" \ "47 | Install openhab_rules_tools" "JS Scripting: Manually install openhab_rules_tools (auto-installed)" \ @@ -243,11 +234,10 @@ show_main_menu() { 43\ *) openhab_clean_cache;; 44\ *) nginx_setup;; *OpenJDK\ 17) update_config_java "17" && java_install "17";; + *OpenJDK\ 21) update_config_java "21" && java_install "21";; + *Temurin\ 17) update_config_java "Temurin17" && java_install "Temurin17";; + *Temurin\ 21) update_config_java "Temurin21" && java_install "Temurin21";; *OpenJDK\ 11) update_config_java "11" && java_install "11";; - *Zulu\ 11\ OpenJDK\ 32-bit) update_config_java "Zulu11-32" && java_install_or_update "Zulu11-32";; - *Zulu\ 11\ OpenJDK\ 64-bit) update_config_java "Zulu11-64" && java_install_or_update "Zulu11-64";; - *Zulu\ 21\ OpenJDK\ 64-bit) update_config_java "Zulu21-64" && java_install_or_update "Zulu21-64";; - *BellSoft\ Liberica\ JDK\ 21) update_config_java "BellSoft21" && java_install_or_update "BellSoft21";; 46\ *) jsscripting_npm_install "openhab";; *Uninstall\ openhab-js) jsscripting_npm_install "openhab" "uninstall";; 47\ *) jsscripting_npm_install "openhab_rules_tools";; diff --git a/functions/nodejs-apps.bash b/functions/nodejs-apps.bash index f2807c0bd..9c0c60959 100644 --- a/functions/nodejs-apps.bash +++ b/functions/nodejs-apps.bash @@ -14,9 +14,9 @@ nodejs_setup() { local temp - myDistro="$(lsb_release -sc)" - if [[ "$myDistro" == "n/a" ]]; then - myDistro=${osrelease:-bullseye} + myDistro="$(lsb_release -sc | head -1)" + if [[ "$myDistro" == "n/a" ]] || running_in_docker; then + myDistro=${osrelease:-bookworm} fi temp="$(mktemp "${TMPDIR:-/tmp}"/openhabian.XXXXX)" diff --git a/functions/openhab.bash b/functions/openhab.bash index 0113f80eb..46662c5f8 100644 --- a/functions/openhab.bash +++ b/functions/openhab.bash @@ -65,7 +65,7 @@ openhab_setup() { repo="deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://openhab.jfrog.io/artifactory/openhab-linuxpkg stable main" echo -n "$(timestamp) [openHABian] Beginning install of latest $ohPkgName release (stable repo)... " elif [[ $1 == "milestone" || $1 == "testing" ]]; then - introText="You are about to install or change to the latest milestone $ohPkgName build. Note this is openHAB 4!\\n\\nMilestones contain the latest features and is supposed to run stable, but if you experience bugs or incompatibilities, please help with enhancing openHAB by posting them on the community forum or by raising a GitHub issue in the proper place.\\n\\nPlease be aware that downgrading from a newer build is not supported!\\n\\nPlease consult with the documentation or community forum and be sure to take a full openHAB configuration backup first!" + introText="You are about to install or change to the latest milestone $ohPkgName build. Note this is openHAB 5!\\n\\nMilestones contain the latest features and is supposed to run stable, but if you experience bugs or incompatibilities, please help with enhancing openHAB by posting them on the community forum or by raising a GitHub issue in the proper place.\\n\\nPlease be aware that downgrading from a newer build is not supported!\\n\\nPlease consult with the documentation or community forum and be sure to take a full openHAB configuration backup first!" successText="The testing release of $ohPkgName is now installed on your system.\\n\\nPlease test the correct behavior of your setup. You might need to adapt your configuration, if available. If you made changes to the files in '/var/lib/${ohPkgName}' they were replaced, but you can restore them from backup files next to the originals.\\n\\nCheck the \"openHAB Release Notes\" and the official announcements to learn about additons, fixes and changes." repo="deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://openhab.jfrog.io/artifactory/openhab-linuxpkg testing main" echo -n "$(timestamp) [openHABian] Beginning install of latest $ohPkgName milestone build (testing repo)... " @@ -95,7 +95,21 @@ openhab_setup() { echo -n "$(timestamp) [openHABian] Installing openHAB... " if ! apt-get clean --yes -o DPkg::Lock::Timeout="$APTTIMEOUT"; then echo "FAILED (apt cache clean)"; return 1; fi cond_redirect apt-get update -o DPkg::Lock::Timeout="$APTTIMEOUT" - openhabVersion="${2:-$(apt-cache madison ${ohPkgName} | head -n 1 | cut -d'|' -f2 | xargs)}" + openhabVersion="${2:-$(apt-cache madison ${ohPkgName} | head -n 1 | awk '{ print $3 }')}" + openhabMajorVersion="$(echo "$openhabVersion" | cut -d'.' -f1)" + javaVersion="$(java -version |& head -1 | awk -F'"' '{ print $2 }' | cut -d '.' -f1)" + if [[ $openhabMajorVersion = 4 ]]; then + if [[ $javaVersion -lt 17 ]] ; then + update_config_java "17" + java_install "17" + fi + elif [[ $openhabMajorVersion = 5 ]]; then + if [[ $javaVersion -lt 21 ]] ; then + update_config_java "21" + java_install "21" + fi + fi + if [[ -n $openhabVersion ]]; then installVersion="${ohPkgName}=${openhabVersion} ${ohPkgName}-addons=${openhabVersion}" else @@ -116,7 +130,8 @@ openhab_setup() { echo -n "$(timestamp) [openHABian] Setting up openHAB service... " if ! cond_redirect zram_dependency install ${ohPkgName}; then return 1; fi - if cond_redirect systemctl enable ${ohPkgName}.service; then echo "OK"; else echo "FAILED (enable service)"; return 1; fi + if ! cond_redirect systemctl -q daemon-reload; then echo "FAILED (reload)"; return 1; fi + if cond_redirect systemctl enable --now ${ohPkgName}.service; then echo "OK"; else echo "FAILED (enable service)"; return 1; fi openhab_misc create_systemd_dependencies @@ -125,12 +140,6 @@ openhab_setup() { fi dashboard_add_tile "openhabiandocs" - # see https://github.com/openhab/openhab-core/issues/1937 - echo -n "$(timestamp) [openHABian] Restarting openHAB service the hard way to play it safe... " - if cond_redirect systemctl restart ${ohPkgName}.service; then echo "OK"; else echo "FAILED (restart service)"; return 1; fi - sleep 60 - pkill -9 java - if [[ -n $INTERACTIVE ]]; then unset DEBIAN_FRONTEND whiptail --title "Operation successful!" --msgbox "$successText" 15 80 diff --git a/functions/openhabian.bash b/functions/openhabian.bash index 5cf5477b8..db17c968b 100644 --- a/functions/openhabian.bash +++ b/functions/openhabian.bash @@ -318,6 +318,8 @@ system_check_default_password() { ## config_ipv6() ## config_ipv6() { + if running_in_docker; then echo "$(timestamp) [openHABian] Making sure router advertisements are available... SKIPPED"; return 0; fi + local aptConf="/etc/apt/apt.conf.d/S90force-ipv4" local sysctlConf="/etc/sysctl.d/99-sysctl.conf" diff --git a/functions/packages.bash b/functions/packages.bash index 1eb61cf22..e653688a0 100644 --- a/functions/packages.bash +++ b/functions/packages.bash @@ -681,8 +681,8 @@ deconz_setup() { if ! add_keys "http://phoscon.de/apt/deconz.pub.key" "$keyName"; then return 1; fi myOS="$(lsb_release -si)" - myRelease="$(lsb_release -sc)" - if [[ "$myRelease" == "n/a" ]]; then + myRelease="$(lsb_release -sc | head -1)" + if [[ "$myRelease" == "n/a" ]] || running_in_docker; then myRelease=${osrelease:-bookworm} fi @@ -856,7 +856,7 @@ install_esphomedashboard() { return fi - if [[ $1 == "install" ]]; then + if [[ $1 == "install" ]]; then if [[ -n $INTERACTIVE ]]; then whiptail --title "ESPhome dashboard installation" --msgbox "$installText" 8 80 fi @@ -922,5 +922,3 @@ install_esphomedashboard() { return fi } - - diff --git a/functions/system.bash b/functions/system.bash index b5706a29a..47bd1d8f3 100644 --- a/functions/system.bash +++ b/functions/system.bash @@ -36,7 +36,7 @@ system_upgrade() { # bad packages may require interactive input despite of this setting so do not mask output (no cond_redirect) if ! apt-get upgrade --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"; then echo "FAILED"; return 1; fi if ! cond_redirect java -version &> /dev/null; then - update_config_java "11" && java_install "11" + update_config_java "17" && java_install "17" fi unset DEBIAN_FRONTEND }