From 098715ec46c04bd2cc6adb18fd8c1d6032689117 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Wed, 14 Oct 2020 09:23:29 +0200 Subject: [PATCH] Installation of knxd now uses knxd package from standard package repository Changed from building and installing latest source to installing the knxd package provided by several distrubutions. Package is available in Debian, Raspberry Pi OS, and Ubuntu (starting 20.04). Closes #651. Added bats test case. Signed-off-by: Holger Friedrich --- functions/packages.bash | 43 +++++++++++++++++++++++++++++++---------- functions/packages.bats | 14 ++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/functions/packages.bash b/functions/packages.bash index 4fe78d034..bda1b4918 100644 --- a/functions/packages.bash +++ b/functions/packages.bash @@ -396,27 +396,50 @@ find_setup() { ## knxd_setup() ## knxd_setup() { - local introText="This will install and setup kndx (successor to eibd) as your EIB/KNX IP gateway and router to support your KNX bus system.\\n\\nThis routine was provided by 'Michels Tech Blog': https://bit.ly/3dzeoKh" - local successText="Setup was successful.\\n\\nPlease edit '/etc/default/knxd' to meet your interface requirements. For further information on knxd options, please type 'knxd --help'\\n\\nFurther details can be found under: https://bit.ly/3dzeoKh\\n\\nIntegration into openHAB 2 is described here: https://github.com/openhab/openhab/wiki/KNX-Binding" + local introText="This will install kndx as your EIB/KNX IP gateway and router to support your KNX bus system.\\n\\nNOTE: Typically, you don't need this if you connect via an IP interface or router to your KNX installation. This package is to turn an USB or serial interface into an IP interface.\n\nNOTE: openHABian changed from building and installing latest source to installing the knxd package provided by several distributions." + local missingText="Setup could not find knxd package.\n\nopenHABian changed from building and installing latest source to installing the knxd package provided by several distrubutions. In case you have an installation of openHABian on a custom Linux which does not provide knxd package, you could try to installation routine we used before as described at 'Michels Tech Blog': https://bit.ly/3dzeoKh" + local errorText="Installation of knxd package failed, see console log for details." + local successText="Installation was successful.\\n\\nPlease edit '/etc/default/knxd' to meet your interface requirements. For further information on knxd options, please type 'knxd --help' or see /usr/share/doc/knxd/.\\n\\nIntegration into openHAB 2 is described here: https://github.com/openhab/openhab/wiki/KNX-Binding" local temp temp="$(mktemp "${TMPDIR:-/tmp}"/openhabian.XXXXX)" - echo -n "$(timestamp) [openHABian] Beginning setup of EIB/KNX IP Gateway and Router with knxd (https://bit.ly/3dzeoKh)... " + echo -n "$(timestamp) [openHABian] Beginning setup of knxd package... " if [[ -n $INTERACTIVE ]]; then - if (whiptail --title "knxd installation?" --yes-button "Continue" --no-button "Cancel" --yesno "$introText" 10 80); then echo "OK"; else echo "CANCELED"; return 0; fi + if (whiptail --title "knxd installation?" --yes-button "Continue" --no-button "Cancel" --yesno "$introText" 15 80); then echo "OK"; else echo "CANCELED"; return 0; fi else echo "OK" fi - echo -n "$(timestamp) [openHABian] Installing knxd... " - # TODO: serve file from the repository - if ! cond_redirect wget -O "$temp" https://michlstechblog.info/blog/download/electronic/install_knxd_systemd.sh; then echo "FAILED (fetch installer)"; return 1; fi - # NOTE: install_knxd_systemd.sh currently does not give proper exit status for errors, so installer claims success... - if cond_redirect bash "$temp"; then rm -f "$temp"; echo "OK (reboot required)"; else echo "FAILED (install)"; return 1; fi + if ! apt-cache show knxd &>/dev/null; then + echo "FAILED (install)"; + if [[ -n $INTERACTIVE ]]; then + whiptail --title "knxd install failed" --msgbox "$missingText" 15 80 + fi + return 1 + fi + + echo -n "$(timestamp) [openHABian] Installing package knxd... " + if cond_redirect apt-get install --yes knxd; then + echo "OK"; + else + echo "FAILED (install)" + if [[ -n $INTERACTIVE ]]; then + whiptail --title "knxd install failed" --msgbox "$errorText" 15 80 + fi + return 1 + fi + + # optional package which contains command line tools, it is allowed to fail + echo -n "$(timestamp) [openHABian] Installing optional package knxd-tools... " + if cond_redirect apt-get install --yes knxd-tools; then + echo "OK"; + else + echo "FAILED (optional install)" + fi if [[ -n $INTERACTIVE ]]; then - whiptail --title "Operation Successful!" --msgbox "$successText" 15 80 + whiptail --title "knxd install sucessful" --msgbox "$successText" 15 80 fi } diff --git a/functions/packages.bats b/functions/packages.bats index b01aea884..737e967e1 100644 --- a/functions/packages.bats +++ b/functions/packages.bats @@ -43,6 +43,20 @@ teardown_file() { echo -e "# ${COL_GREEN}$(timestamp) [openHABian] MQTT service is running.${COL_DEF}" >&3 } +@test "destructive-knxd_install" { + echo -e "# ${COL_CYAN}$(timestamp) [openHABian] knxd installation starting...${COL_DEF}" >&3 + run knxd_setup 3>&- + if [ "$status" -ne 0 ]; then echo "$output" >&3; fi + [ "$status" -eq 0 ] + echo -e "# ${COL_GREEN}$(timestamp) [openHABian] knxd installation successful.${COL_DEF}" >&3 + + # knxd service must be configured and is not started automatically, but we can call knxd executable + run knxd --version 3>&- + if [ "$status" -ne 0 ]; then echo "$output" >&3; fi + [ "$status" -eq 0 ] + echo -e "# ${COL_GREEN}$(timestamp) [openHABian] knxd executable ok.${COL_DEF}" >&3 +} + @test "destructive-1wire_install" { echo -e "# ${COL_CYAN}$(timestamp) [openHABian] 1wire installation starting...${COL_DEF}" >&3 run 1wire_setup 3>&-