#!/bin/bash readonly toolName="fhem" readonly toolUser="$toolName" readonly toolHome="/opt/fhem" readonly toolVersion="6.1" readonly toolDpkg="fhem-${toolVersion}.deb" readonly toolUrl="http://fhem.de/${toolDpkg}" # default deps listed at https://debian.fhem.de/ readonly toolDeps="perl-base libdevice-serialport-perl libwww-perl libio-socket-ssl-perl libcgi-pm-perl libjson-perl sqlite3 libdbd-sqlite3-perl libtext-diff-perl libtimedate-perl libmail-imapclient-perl libgd-graph-perl libtext-csv-perl libxml-simple-perl liblist-moreutils-perl fonts-liberation2 libimage-librsvg-perl libgd-text-perl libsocket6-perl libio-socket-inet6-perl libmime-base64-urlsafe-perl libimage-info-perl libusb-1.0-0-dev libnet-server-perl" toolDeps2="libdate-manip-perl libhtml-treebuilder-xpath-perl libmojolicious-perl libxml-bare-perl libauthen-oath-perl libconvert-base32-perl libmodule-pluggable-perl libnet-bonjour-perl libcrypt-urandom-perl" # for rounding operations e.g.: # { use Math::Round qw/nearest/;; nearest('0.01',ReadingsVal("1WT_28_5728E9070000", "temperature", 0)-1.1);; } toolDeps2+=" libmath-round-perl" # for fritzbox connection toolDeps2+=" libsoap-lite-perl libjson-xs-perl" # for xmpp support (no special solution needed for raspbian buster) toolDepsJabber=" libnet-xmpp-perl libxml-stream-perl libnet-jabber-perl" aptOpt= #step_config() { # echo "Called once before executing steps." # echo "e.g. to source a config file:" # #. "$CONFIG_FILE" #} step_1_info() { echo "Install prerequisits for $toolName"; } step_1_alias() { echo "install"; } step_1() { local aptOpt= if quiet ; then aptOpt="-y" fi #exe apt update exe apt install $toolDeps $toolDeps2 "$aptOpt" #exe apt install "$toolDeps2" "$aptOpt" endReturn -o $? "Installation of prerequisits failed" } step_2_info() { echo "Install jabber prerequisits"; echoinfo "(May be skipped)"; } step_2() { exe apt install $toolDepsJabber "$aptOpt" endReturn -o $? "Installation of prerequisits for jabber failed" } step_3_info() { echo "Download and install $toolName version $toolVersion"; } step_3() { exe wget "$toolUrl" -O "$downPath" endReturn -o $? "Download of $toolName failed" exe dpkg -i "$downPath" endReturn -o $? "Installation of $toolName failed" info "$toolName is now running on http://$(hostname -I | cut -d " " -f 1):8083" } downPath="/tmp/$toolDpkg" step_20_info() { echo "List $toolName prerequisits"; } step_20_alias() { echo "listdeps"; } step_20() { echo " [I] $toolName prerequisits:" echo "$toolDeps $toolDeps2" } step_30_info() { echo "Create user $toolUser"; } step_30() { exe useradd --system --home "$toolHome" --gid dialout --shell /bin/false "$toolUser" endReturn -o $? "Creating user $toolUser failed" } step_32_info() { echo "Create $toolName systemd service"; } step_32() { exe cp "${toolHome}/contrib/init-scripts/fhem.service" "$systemdConfigLoc" exe systemctl daemon-reload } systemdConfigLoc="/etc/systemd/system" step_34_info() { echo "Downgrade $toolName jabber dependencies (callbackIQ -> FHEM crash)"; } step_34_alias() { echo "downgrade_xmpp"; } step_34() { if [ ! -f $libnetDown ]; then exe wget "$libnetUrl" -O "$libnetDown" endReturn -o $? "Download of $libnetUrl failed" fi if [ ! -f $libxmlDown ]; then exe wget "$libxmlUrl" -O "$libxmlDown" endReturn -o $? "Download of $libxmlUrl failed" fi local aptOption= if quiet ; then aptOption="-y" else aptOption="" fi exe apt remove libnet-jabber-perl $aptOption saveReturn $? exe apt remove libnet-xmpp-perl $aptOption saveReturn $? exe apt remove libxml-stream-perl $aptOption saveReturn $? endReturn "Failed removing packages; Manual fix required" exe dpkg -i "$libxmlDown" saveReturn $? exe dpkg -i "$libnetDown" saveReturn $? exe apt install libnet-jabber-perl $aptOption saveReturn $? endReturn "Failed removing packages; Manual fix required" exe rm "$libxmlDown" "$libnetDown" } libnetName="libnet-xmpp-perl_1.02-3_all.deb" libnetDown="/tmp/$libnetName" libnetUrl="http://ftp.de.debian.org/debian-archive/debian/pool/main/libn/libnet-xmpp-perl/$libnetName" libxmlName="libxml-stream-perl_1.23-2_all.deb" libxmlDown="/tmp/$libxmlName" libxmlUrl="http://ftp.de.debian.org/debian/pool/main/libx/libxml-stream-perl/$libxmlName" step_35_info() { echo "Pin downgraded $toolName jabber dependencies"; } step_35() { addConf -s "$aptPinXmpp" "$aptPinFile" } aptPinFile="/etc/apt/preferences.d/00_FhemJabber" aptPinXmpp="Package: libnet-xmpp-perl Pin: version 1.02-3* Pin-Priority: 1000 Package: libxml-stream-perl Pin: version 1.23-2 Pin-Priority: 1000" step_37_info() { echo "Download latest speedtest python script"; } step_37_alias() { echo "speedtestdownload"; } step_37() { local lSpeedPath="/usr/local/bin/speedtest-cli" exe wget -O "$lSpeedPath" https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py exe chmod +x "$lSpeedPath" } step_40_info() { echo "Execute fhem [COMMAND]"; } step_40_alias() { echo "exe"; } step_40() { shift exe perl "${toolHome}/fhem.pl" 7072 "${1:-}" } readonly sqr_minVersion=16 . /usr/local/bin/sequencer.sh