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 <mrtops03@gmail.com>
  • Loading branch information
ecdye committed Jan 13, 2025
1 parent 742ec53 commit bf8455e
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 91 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/bats-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
bats-tests:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
services:
registry:
image: registry:2
ports:
- 5000:5000

strategy:
matrix:
Expand Down Expand Up @@ -76,14 +71,12 @@ jobs:
context: .
file: ./tests/Dockerfile.${{ matrix.platform }}-BATS
builder: ${{ steps.buildx.outputs.name }}
tags: localhost:5000/openhabian/${{ matrix.platform }}-openhabian:latest
tags: openhabian/${{ matrix.platform }}-openhabian:latest
platforms: ${{ matrix.buildx_platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
load: true
- name: BATS tests on ${{ matrix.platform }} platform
run: |
docker run --rm --name "openhabian-${{ matrix.platform }}" --platform ${{ matrix.buildx_platform }} -d localhost:5000/openhabian/${{ matrix.platform }}-openhabian
docker run --rm --name "openhabian-${{ matrix.platform }}" --platform ${{ matrix.buildx_platform }} -d openhabian/${{ matrix.platform }}-openhabian
docker exec -i "openhabian-${{ matrix.platform }}" bash -c 'bats --tap --recursive --filter "development-." .'
docker exec -i "openhabian-${{ matrix.platform }}" bash -c 'bats --tap --recursive --filter "unit-." .'
docker exec -i "openhabian-${{ matrix.platform }}" bash -c 'bats --tap --recursive --filter "installation-." .'
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/installation-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ jobs:
installation-tests:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
services:
registry:
image: registry:2
ports:
- 5000:5000

strategy:
matrix:
Expand Down Expand Up @@ -76,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 QEMU
if: ${{ matrix.qemu_platform != '' }}
uses: docker/setup-qemu-action@v3.3.0
Expand All @@ -93,13 +88,11 @@ jobs:
context: .
file: ${{ matrix.dockerfile }}
builder: ${{ steps.buildx.outputs.name }}
tags: localhost:5000/openhabian/${{ matrix.platform }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
tags: openhabian/${{ matrix.platform }}:latest
platforms: ${{ matrix.buildx_platform }}
push: true
load: true
- name: openHABian installation test with ${{ matrix.platform }}
run: |
docker run --privileged --rm --platform ${{ matrix.buildx_platform }} --name "openhabian-${{ matrix.platform }}" -d localhost:5000/openhabian/${{ matrix.platform }}
docker run --privileged --rm --platform ${{ matrix.buildx_platform }} --name "openhabian-${{ matrix.platform }}" -d openhabian/${{ matrix.platform }}
docker exec -i "openhabian-${{ matrix.platform }}" bash -c './build.bash local-test && /boot/first-boot.bash'
shell: bash
20 changes: 15 additions & 5 deletions build-image/first-boot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if ! is_bookworm; then
rfkill unblock wifi # Wi-Fi is blocked by Raspi OS default since bullseye(?)
fi
webserver=/boot/webserver.bash
ln -s /boot/firmware/webserver.bash "$webserver"
ln -sfn /boot/firmware/webserver.bash "$webserver"

if [[ "${debugmode:-on}" == "on" ]]; then
unset SILENT
Expand Down Expand Up @@ -93,7 +93,7 @@ hotSpot=${hotspot:-enable}
wifiSSID="$wifi_ssid"
# shellcheck source=/etc/openhabian.conf disable=SC2154
wifiPassword="$wifi_password"
if 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

Expand All @@ -105,7 +105,7 @@ if is_bookworm; then
#elif [[ -z $wifiSSID ]]; then
elif grep -qs "up" /sys/class/net/eth0/operstate; then
# Actually check if ethernet is working
echo -n "$(timestamp) [openHABian] Setting up Ethernet connection... OK"
echo "$(timestamp) [openHABian] Setting up Ethernet connection... OK"
elif [[ -n $wifiSSID ]] && grep -qs "openHABian" /etc/wpa_supplicant/wpa_supplicant.conf && ! grep -qsE "^[[:space:]]*dtoverlay=(pi3-)?disable-wifi" /boot/config.txt; then
echo -n "$(timestamp) [openHABian] Checking if WiFi is working... "
if iwlist wlan0 scan |& grep -qs "Interface doesn't support scanning"; then
Expand Down Expand Up @@ -219,7 +219,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 @@ -254,7 +254,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
}


Loading

0 comments on commit bf8455e

Please sign in to comment.