Upgrade from within openhabian-config 4.3.4 > 4.3.7

Im a bit lost here.

Im running openhabian on Rpi4 with openhab 4.3.4.
Im not quite ready to upgrade to openhab 5 yet. But I can see there is a openhab 4.3.7 release. How to upgrade to this using the openhabian-config?

If/when I choose to upgrade to opehab 5. Will java 21 be installed as well. Or do I have to install it manually?

I’m sure there are more ways but this is how I did it on my one machine that isn’t running Docker.

sudo apt install openhab=4.3.7-1 openhab-addons=4.3.7-1
sudo apt-mark hold openhab openhab-addons

The above assumes you’ve installed openhab-addons in addition to just openHAB by itself.

The first line installs the specific version and the second line freezes it at the currently installed version so it won’t upgrade when you run sudo apt upgrade

If you are using openHABian I think it will install Java 21 automatically but I’m not 100% positive about that. For all other installations you must install Java 21 manually.

Thanks Rich.. I just thought it would be possible directe from openhabian-config.
I have not installed the addons manually, so I guess this could become quite a hassle.

There is not any deep description for upgrade/update in openhabian. Usually I would just upgrade to the latest. But openHab 5. is quite special, as it requires 64bit OS. And to be honest, I have no idea which OS I´m using, wether its 32 or 64bit. So I need to figure that one first.

No hassle. I’m pretty certain openHABian installs openhab-addons by default. But you can easily tell with the command:

apt list --installed | grep openhab

If openhab-addons is not installed, simply remove those from the commands above.

sudo apt install openhab=4.3.7-1
sudo apt-mark hold openhab

From the openHABian docs:

Many RPi users are still on a 32 bit based Linux OS (you can check bitness using the command getconf LONG_BIT).

If that command returns 32 you are running a 32-bit OS and need to upgrade the whole OS. If it reads 64 you can do an in -place upgrade.

Hmm. I think it is the other way round. You must prepare the foundation before you (try to) install OH on it. So first make sure you are on a 64 bit OS, then use the openHABian-config menu to setup Java 21, then finally use the openHABian-config menu to setup OH 5.0

If you are already on 64-bit, from the release notes which are linked to from the openHABian docs:

If you are on 64 bit, proceed to

upgrade

  • Use SSH to connect to the command line and run sudo openhabian-config.

  • When being asked, answer that you want to update openHABian (note that’s not about openHAB itself).

  • If needed check which version you run via menu option 00.

  • If on Raspberry, create an image copy of your SD card using menu option 54.

  • Switching to openHAB 5.0.0 release depends on what version you’re upgrading from:

    a) If you have been running a 4.x release version, select menu entry 03 “Install or upgrade to latest openHAB” option.

    b) If you have been running a snapshot or milestone release of 5.0, select the first entry in menu option 41 (“Release”).

If you are still on 32 bit OS, you can stay with your current openHAB 4 setup or

There is no mention of installing Java 21 separately and the whole point of openHABian is to do stuff like that for you.

@Kim_Andersen , if you are indeed on a 32-bit OS, the instructions you will want to follow to eventually upgrade will be:

reinstall your OS to 64 bit

If you have 64 bit capable ARM hardware (RPi3 or newer) and want to run openHAB 5, you will need to reinstall your system with a 64 bit OS.
The next instructions also apply if you want to change hardware.

Cross-check with the HW docs section.
Use another SD card to have your working one available as a fallback should things go wrong.
You should be installing latest openHABian as provided when using the Raspi imager.
Select your image from the ‘Other specific-purpose OS → Home assistants and home automation → openHAB’ menu and make sure to choose the 64 bit image.

install openHAB 4 first

Now see these instructions how to edit the openhabian.conf config file.
Set clonebranch=openHAB4 and java_opt=Temurin21.
Configure your fresh image to automatically import it: make the initialconfig option point to your configuration backup zipfile.
To migrate your config, export (“backup”) your working config using menu option 50 and copy it over to your PC - your openHABian box will provide a Windows share to access it.

Next place the card in your RPi and boot to start the installation process. You will be installed latest openHAB 4, 4.3.7 at the time of writing.

Finally, login and run openHABian menu option 03 to upgrade to OH 5. This process will migrate parts of your config where needed.
That’s it, you’re running openHAB 5 now.

But in the mean time, if you happen to be on 32-bit OS upgrading openHAB will fail anyway so you don’t necessarily need to fix the version using the two commands posted above unless you want to remove that error when you upgrade the rest of the OS.

Erm. I am mentioning it here now for you..

  • Menu 45 allows to select the Java version
  • Menu 41 allows to select the OH version

openHABian will install the default, Temurin 21. If you want a different JRE for what ever reason, would use Menu 45.

When you change the version of OH to install (though Menu 41)(openhabian/functions/menu.bash at 40e088cf306b17038a6184796868cbbfa34e2097 · openhab/openhabian · GitHub), it executes this function. You can see here that if the version of OH is 5, it changes the default jre and installs Temeruin21 if it’s not already installed automatically as part of changing the version of OH.

The full code is posted below so you don’t have to jump around multiple files.

Menu 41:

    case "$choice2" in
      41\ *) openhab_setup "release";;
      *openHAB\ Milestone) openhab_setup "milestone";;
      *openHAB\ Snapshot) openhab_setup "snapshot";;
      42\ *) openhab_shell_interfaces;;
      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";;
      46\ *) jsscripting_npm_install "openhab";;
      *Uninstall\ openhab-js) jsscripting_npm_install "openhab" "uninstall";;
      47\ *) jsscripting_npm_install "openhab_rules_tools";;
      *Uninstall\ openhab_rules_tools) jsscripting_npm_install "openhab_rules_tools" "uninstall";;
      "") return 0 ;;
      *) whiptail --msgbox "An unsupported option was selected (probably a programming error):\\n  \"$choice2\"" 8 80 ;;
    esac

openhab_setup()

## Function to install / upgrade / downgrade the installed openHAB version
## Valid argument 1: "release", "milestone" or "testing", or "snapshot" or "unstable"
## Valid argument 2 (optional): Linux package name to install
##
##    openhab_setup(String release)
##
openhab_setup() {
  local introText
  local keyName="openhab"
  local openhabVersion
  local installVersion
  local repo
  local successText
  local noJVMText="We were unable to install/upgrade your system to openHAB 5.\\nThis requires Java version 21, and we have been unable to identify and install a suitable Java JVM package for your hardware-OS combo."
  local ohPkgName="openhab"
  local textsize=9

  if [[ $1 == "snapshot" || $1 == "unstable" ]]; then
    introText="Proceed with caution!\\n\\nYou are about to switch over to the latest $ohPkgName unstable snapshot build. The daily snapshot builds contain the latest features and improvements but might also suffer from bugs or incompatibilities. Please be sure to take a full openHAB configuration backup first!\\n\\nBeware that downgrading will not be possible, you can only re-install old software and re-important the config backup you should have made before the upgrade."
    successText="The latest unstable snapshot build of $ohPkgName is now running 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\\nIf you find any problems or bugs, please report them and state the snapshot version you are on. To stay up-to-date with improvements and bug fixes you should upgrade your packages (using menu option 02) regularly."
    repo="deb [signed-by=/usr/share/keyrings/${keyName}.gpg] https://openhab.jfrog.io/artifactory/openhab-linuxpkg unstable main"
    echo -n "$(timestamp) [openHABian] Beginning install of latest $ohPkgName snapshot build (unstable repo)... "
  elif [[ $1 == "release" || $1 == "stable" ]]; then
    introText="You are about to install or change to the latest stable $ohPkgName release.\\n\\nPlease be aware that downgrading from a newer unstable snapshot build is not supported. Please consult with the documentation or community forum and be sure to take a full openHAB configuration backup first!"
    successText="The stable 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 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 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)... "
  fi

  if [[ -n $INTERACTIVE ]]; then
    if (whiptail --title "openHAB software change" --yes-button "Continue" --no-button "Cancel" --yesno "$introText" 20 80); then echo "OK"; else echo "CANCELED"; return 1; fi
    export DEBIAN_FRONTEND=noninteractive
  else
    echo "OK"
  fi

  # date needs to be > Apr 1, 24 for openhab repo signing key to be valid
  # note RPis have no real time clock
  if [[ $(date +%y%m%d) -lt 240401 ]]; then
    systemctl stop systemd-timesyncd
    timedatectl set-time "2024-04-09 00:00:00"
    systemctl start systemd-timesyncd
  fi
  if running_in_docker || [[ -z $OFFLINE ]]; then
    if ! add_keys "https://openhab.jfrog.io/artifactory/api/gpg/key/public" "$keyName"; then return 1; fi

    rm -f /etc/apt/sources.list.d/openhab*.list
    echo "$repo" > /etc/apt/sources.list.d/openhab.list

    dpkg --configure -a --force-confnew
    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 | 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 "Temurin21"
        java_install "Temurin21"
      fi
    fi

    javaVersionNeu="$(java -version |& head -1 | awk -F'"' '{ print $2 }' | cut -d '.' -f1)"
    if [[ $openhabMajorVersion = 5 ]] && [[ $javaVersionNeu -lt 21 ]] ; then
      echo "FAILED (could not install required Java 21)"
      if [[ -n $INTERACTIVE ]]; then
        unset DEBIAN_FRONTEND
        if is_arm && [[ "$(getconf LONG_BIT)" == "32" ]]; then
          noJVMText+="\\n\\nThere is currently no suitable JVM package for ARM processors that works\\nwith a 32 bit OS image."
	  textsize=12
        fi
        whiptail --title "Operation failed!" --msgbox "$noJVMText" ${textsize} 80
      fi
      return 1
    fi

    if [[ -n $openhabVersion ]]; then
      installVersion="${ohPkgName}=${openhabVersion} ${ohPkgName}-addons=${openhabVersion}"
    else
      installVersion="${ohPkgName} ${ohPkgName}-addons"
    fi

    # shellcheck disable=SC2086
    if cond_redirect apt-get install --allow-downgrades --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" --option Dpkg::Options::="--force-confnew" $installVersion; then echo "OK"; else echo "FAILED"; return 1; fi
  else
    echo -n "$(timestamp) [openHABian] Installing cached openHAB version... "
    if cond_redirect apt-get install --yes -o DPkg::Lock::Timeout="$APTTIMEOUT" --option Dpkg::Options::="--force-confnew" ${ohPkgName} ${ohPkgName}-addons; then echo "OK"; else echo "FAILED"; return 1; fi
  fi

  # shellcheck disable=SC2154
  gid="$(id -g "$username")"
  cond_redirect usermod -g "openhab" "$username" &> /dev/null
  cond_redirect usermod -aG "$gid" "$username" &> /dev/null

  echo -n "$(timestamp) [openHABian] Setting up openHAB service... "
  if ! cond_redirect zram_dependency install ${ohPkgName}; then 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
  dashboard_add_tile "openhabiandocs"

  if [[ -n $INTERACTIVE ]]; then
    unset DEBIAN_FRONTEND
    whiptail --title "Operation successful!" --msgbox "$successText" 15 80
  fi
}

update_copnfig_java()

## Update requested version of Java in '$configFile'.
## Valid arguments: "11", "17"
##
##    update_config_java(String type)
##
update_config_java() {
  if ! cond_redirect sed -i -e 's|^java_opt.*$|java_opt='"${1}"'|' "$configFile"; then return 1; fi
  source "$configFile"
}

java_install()

## 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)
##
java_install() {
  if openhab_is_running; then
    cond_redirect systemctl stop openhab.service
  fi

  if [[ -d /opt/jdk ]]; then
    java_alternatives_reset
    rm -rf /opt/jdk
  fi
  if [[ $1 == Temurin* ]]; then
    adoptium_install_apt "${1/Temurin/}"
  else
    openjdk_install_apt "$1"
  fi

  if openhab_is_installed; then
    cond_redirect systemctl restart openhab.service
  fi
}

Note that update_java_config and java_install will also get called from the scripts called by menu 45 and they also get called when doing an upgrade if there is no Java already installed. For the system upgrade, the version defaults to Temerun21

In openHABian you only need to install Java 21 separately if you want a JRE different from Temurin21. Otherwise Java 17 will upgrade to Java 21 Temurin automatically.

And this is as it should be. The whole point of openHABian is the end users shouldn’t have to worry about this stuff unless they want to. If one chooses to upgrade to OH 5, and the OS can handle it, all the dependencies also get installed which, in this case, is Java 21.

On a bare new install it will install the (now new) default. But on an upgrade it may keep the (prior) default. So IMHO you should not assume that you have the correct Java version for v5.0 unless you specifically set it up via menu 45

Look at the code. It doesn’t assume anything. If OH 5 is to be installed, either as a fresh install or as an upgrade, if Java 21 isn’t already installed, it installs Temurin21.

    elif [[ $openhabMajorVersion = 5 ]]; then
      if [[ $javaVersion -lt 21 ]] ; then
        update_config_java "Temurin21"
        java_install "Temurin21"
      fi
    fi

That’s in openhab_setup() which is what’s called by Menu 41 and it does the following steps:

  1. configures the repo based on what was chosen between snapshot, release, or milestone.
  2. does a work around with the clock to ensure the signing key works
  3. if the machine is online (i.e. can reach the internet)
    a. configure the repo key
    b. runs apt clean and apt update
    c. collect the latest openHAB version in the repo and the installed java version
    d. if the latest version of OH available is 5 and the java version is less than 21 install Temurin21
  4. check to see if Java 21 is installed if the latest version of OH is 5 and error if it’s not.
  5. finally install the latest OH in the selected repo
  6. change file ownership and do some final config steps (e.g. zram redirects)

It was awhile since I looked at this code which is why I said “I think” above. But it is definite. You do not need to upgrade to Java 21 manually or as a separate step when using openHABian. Upgrading OH using menu 41 will upgrade Java automatically for you.

Ok. I concede.

thanks a whole lot, Rich, for your extensive explanations!

All readers, now that Rich turned you into experts I hope you now realize it’s not as hard to get into as you might have thought.
We’re happy if you to join us as contributors. Kudos @AndrewFG for your first contribution.

I really appreciate your thanks @mstormi .. however if you check your history you will find that it was not really my first contribution..

1 Like

Rich is doing a fine job, no question about that. But regarding not as hard to get into, I think that depends on, wether the user is running 32 or 64bit.

I dont complaint though.. Its a term for beeing able to run openHAB 5.0. One day I might spend the time going through this “hassle”. Untill then, I just wanted to upgrade to 4.3.7, which I dont think openhabian-config can help with, because there is a newer openHAB (5.0).
So I guess the trick is to do this manually, as Rich wrote.

Thanks Rich..
The way understand the procedure is like starting all over, but using 64bit insted.
Thats fine. But I dont understand, why install openHAB 4 first, insted of openHAB 5, if the goal is to get to openHAB 5? Is it something in the config (old 32bit) files, which cant be imported/merged aftwerwards?

When you are restoring a backup, it’s always best to restore to the same version of OH that the backup was taken. Since you are taking the backup from 4.3.7 it’s best to restore that to a 4.3.7 instance of OH.

There are lots of variables which can break things when you try to restore a backup to a different version of OH. For example, if it was a full backup, you’ll populate tmp and cache with the jar files for the backup version instead of the version that version of OH need to run. For example, restoring a 4.3.7 full backup over OH 5 will cause OH 5 to try to use the 4.3.7 versions of the add-ons, which is almost certainly going to fail.

In addition, restoring a backup skips the upgradeTool. This is a tool that runs during an upgrade that modifies your managed configs to adjust for breaking changes so you don’t have to do so manually. If this tool doesn’t run, your JSONDB files may not be compatible with OH 5.

During the upgrade process, you will get a list of the major breaking changes so you will know right then and there what is likely to break and need to be fixed.

Can you restore a 4.3.7 backup to an OH 5 instance? Sure but you have to account for all of the above and perform a lot of manual steps. But if you restore to 4.3.7 and then upgrade to OH 5 all that happens automatically and you are more likely to end up with a working version of OH in the end.

The linked instructions above require the fewest manual steps and have the highest likelihood to avoid problems. Therefore it’s the recommended way. And to be clear, this approach is the recommended approach for all upgrades like this which involve moving to a new system. The 32-bit/64-bit detail is not relevant. It’s the restore to a new instance that is the concern.

on openHABian I mean

I even did one previously on that..