Skip to content

Commit

Permalink
Fixup to make sure OH5 checks for Java 21
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Feb 3, 2025
1 parent 051adfd commit ea486da
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 69 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bats-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/installation-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,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/[email protected]
Expand Down
18 changes: 14 additions & 4 deletions build-image/first-boot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ! is_bookworm; then
rfkill unblock wifi # Wi-Fi is blocked by Raspi OS default since bullseye(?)
fi
webserver=/boot/webserver.bash
[[ -f /boot/firmware/webserver.bash ]] && ln -s /boot/firmware/webserver.bash "$webserver"
[[ -f /boot/firmware/webserver.bash ]] && ln -sfn /boot/firmware/webserver.bash "$webserver"

if [[ "${debugmode:-on}" == "on" ]]; then
unset SILENT
Expand Down Expand Up @@ -91,7 +91,7 @@ hotSpot=${hotspot:-enable}
wifiSSID="$wifi_ssid"
# shellcheck source=/etc/openhabian.conf disable=SC2154
wifiPassword="$wifi_password"
if is_pi && is_bookworm; then
if ! running_in_docker && is_bookworm; then
echo -n "$(timestamp) [openHABian] Setting up NetworkManager and Wi-Fi connection... "
systemctl enable --now NetworkManager
nmcli r wifi on
Expand Down Expand Up @@ -217,7 +217,7 @@ fi

# shellcheck disable=SC2154
echo -n "$(timestamp) [openHABian] Updating myself from ${repositoryurl:-https://github.com/openhab/openhabian.git}, ${clonebranch:-openHAB} branch... "
if [[ $(eval "$(openhabian_update "${clonebranch:-openHAB}" &> /dev/null)") -eq 0 ]]; then
if running_in_docker || [[ $(eval "$(openhabian_update "${clonebranch:-openHAB}" &> /dev/null)") -eq 0 ]]; then
echo "OK"
else
echo "FAILED"
Expand Down Expand Up @@ -252,7 +252,17 @@ if running_in_docker; then
ps -auxq "$(cat "$PID")" | awk '/openhab/ {print "size/res="$5"/"$6" KB"}'
else
echo -e "\\n${COL_RED}Karaf PID missing, openHAB process not running (yet?).${COL_DEF}"
exit 1
cat /var/log/openhab/openhab.log
systemctl restart openhab.service
systemctl status openhab.service
journalctl -xeu openhab.service
sleep 30
if [[ -f "$PID" ]]; then
ps -auxq "$(cat "$PID")" | awk '/openhab/ {print "size/res="$5"/"$6" KB"}'
else
echo -e "\\n${COL_RED}Karaf PID still missing, openHAB process not running.${COL_DEF}"
exit 1
fi
fi
echo -e "$COL_DEF"
fi
Expand Down
4 changes: 2 additions & 2 deletions build-image/openhabian.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ clonebranch=openHAB

# debug verbosity mode
# off, on (verbose output in log) or maximum (show every command)
debugmode=off
debugmode=maximum

# the framebuffer on RPi is enabled by default
framebuffer=enable
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions functions/influxdb+grafana.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 28 additions & 25 deletions functions/java-jre.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Install Java version from dpkg repositories dynamically.
## This function is a wrapper for the OpenJDK and Adoptium Eclipse Temurin JDK install functions.
## Valid arguments: "11", "17", "Temurin17", "Temurin21"
## Valid arguments: "17", "21", "Temurin17", "Temurin21", 11 (legacy)
##
## java_install(String version)
##
Expand All @@ -16,7 +16,7 @@ java_install() {
rm -rf /opt/jdk
fi
if [[ $1 == Temurin* ]]; then
adoptium_fetch_apt "${1/Temurin/}"
adoptium_install_apt "${1/Temurin/}"
else
openjdk_install_apt "$1"
fi
Expand All @@ -31,18 +31,14 @@ java_install() {
## adoptium_fetch_apt()
##
adoptium_fetch_apt() {
if ! apt-cache show "temurin-${1}-jre" &> /dev/null; then
local keyName="adoptium"

if ! add_keys "https://packages.adoptium.net/artifactory/api/gpg/key/public" "$keyName"; then return 1; fi
cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 843C48A565F8F04B

echo -n "$(timestamp) [openHABian] Adding Adoptium repository to apt... "
if ! echo "deb https://packages.adoptium.net/artifactory/deb ${osrelease:-bookworm} main" > /etc/apt/sources.list.d/adoptium.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
local keyName="adoptium"

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

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
}

Expand All @@ -56,7 +52,7 @@ adoptium_install_apt() {
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" "temurin-${1}-jre"; then echo "OK"; else echo "FAILED"; return 1; fi
elif dpkg -s "temurin-${1}-jre" &> /dev/null; then
else
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
Expand All @@ -73,19 +69,22 @@ adoptium_install_apt() {
## openjdk_fetch_apt()
##
openjdk_fetch_apt() {
if ! apt-cache show "openjdk-${1}-jre-headless" &> /dev/null; then
echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/java.list
cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
cond_redirect apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
local keyName="debian-bookworm"

# important to avoid release mixing:
# prevent RPi from using the Debian distro for normal Raspbian packages
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
fi
if ! cond_redirect apt-get update; then echo "FAILED (update apt lists)"; return 1; fi

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 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
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
}

## Install OpenJDK using APT repository.
Expand All @@ -97,8 +96,12 @@ openjdk_install_apt() {
openjdk_fetch_apt "$1"
echo -n "$(timestamp) [openHABian] Installing OpenJDK ${1}... "
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
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
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
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
Expand Down
8 changes: 0 additions & 8 deletions functions/menu.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions functions/nodejs-apps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
2 changes: 1 addition & 1 deletion functions/nodejs-apps.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ teardown_file() {
echo -e "# ${COL_GREEN}$(timestamp) [openHABian] Frontail service is running.${COL_DEF}" >&3
}

@test "disabled-zigbee2mqtt_install" {
@test "installation-zigbee2mqtt_install" {
echo -e "# ${COL_CYAN}$(timestamp) [openHABian] Zigbee2MQTT installation starting...${COL_DEF}" >&3
run zigbee2mqtt_setup "install" 3>&-
if [ "$status" -ne 0 ]; then echo "$output" >&3; fi
Expand Down
33 changes: 17 additions & 16 deletions functions/openhab.bash
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,23 @@ 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}"
if dpkg --compare-versions "$installVersion" ge "5.0.0"; then
if [[ -n $INTERACTIVE ]]; then
if ! (whiptail --title "openHAB software change" --msgbox "openHAB 5 requires Java 21.\\n\\nPlease use menu option 45 to install Java 21." 20 80); then echo "CANCELED"; return 1; fi
else
echo "FAILED (openHAB 5 requires Java 21)"
return 1
fi
fi
else
installVersion="${ohPkgName} ${ohPkgName}-addons"
fi
Expand All @@ -124,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)"; journalctl -xeu openhab.service; systemctl status openhab.service; return 1; fi

openhab_misc
create_systemd_dependencies
Expand All @@ -133,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
Expand Down
2 changes: 2 additions & 0 deletions functions/openhabian.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 3 additions & 5 deletions functions/packages.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -922,5 +922,3 @@ install_esphomedashboard() {
return
fi
}


2 changes: 1 addition & 1 deletion functions/system.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions tests/Dockerfile.amd64-installation
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ ENTRYPOINT ["./tests/entry.sh"]

# Setup openHABian environment
COPY . /opt/openhabian/
COPY ./build-image/webserver.bash /boot/firmware/webserver.bash
WORKDIR /opt/openhabian/
RUN install -m 755 ./tests/runlevel /sbin/runlevel
1 change: 1 addition & 0 deletions tests/Dockerfile.rpi3-installation
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ ENTRYPOINT ["./tests/entry.sh"]

# Setup openHABian environment
COPY . /opt/openhabian/
COPY ./build-image/webserver.bash /boot/firmware/webserver.bash
WORKDIR /opt/openhabian/
RUN install -m 755 ./tests/runlevel /sbin/runlevel
1 change: 1 addition & 0 deletions tests/Dockerfile.rpi5-installation
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ ENTRYPOINT ["./tests/entry.sh"]

# Setup openHABian environment
COPY . /opt/openhabian/
COPY ./build-image/webserver.bash /boot/firmware/webserver.bash
WORKDIR /opt/openhabian/
RUN install -m 755 ./tests/runlevel /sbin/runlevel
20 changes: 19 additions & 1 deletion tests/test.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -e

## This function formats log messages
##
Expand All @@ -19,6 +18,25 @@ if [[ $1 == "shellcheck" ]]; then
shellcheck -x -s bash functions/*.bash
shellcheck -x -s bash build-image/*.bash
shellcheck -x -s bash build.bash tests/ci-setup.bash
elif [[ $1 == "docker-install" ]]; then
if [[ -n $2 ]]; then
saved_java_opt="$(ggrep -oP 'java_opt=\K.*' build-image/openhabian.conf)"
gsed -i 's|java_opt=.*$|java_opt='"${2}"'|' build-image/openhabian.conf
fi
if [[ -n $3 ]]; then
saved_debugmode="$(ggrep -oP 'debugmode=\K.*' build-image/openhabian.conf)"
gsed -i 's|debugmode=.*$|debugmode='"${3}"'|' build-image/openhabian.conf
fi
docker buildx build --tag openhabian/install-openhabian -f tests/Dockerfile.rpi5-installation --platform linux/arm64 .
docker run --privileged --rm --platform linux/arm64 --name openhabian -d openhabian/install-openhabian:latest
docker exec -i "openhabian" bash -c './build.bash local-test && /boot/first-boot.bash'
docker stop openhabian
if [[ -n $2 ]]; then
gsed -i 's|java_opt=.*$|java_opt='"${saved_java_opt}"'|' build-image/openhabian.conf
fi
if [[ -n $3 ]]; then
gsed -i 's|debugmode=.*$|debugmode='"${saved_debugmode}"'|' build-image/openhabian.conf
fi
else
echo_process "Please provide a valid test profile, \"shellcheck\". Exiting"
exit 0
Expand Down

0 comments on commit ea486da

Please sign in to comment.