155 lines
5.0 KiB
Bash
Executable File
155 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
toolName="fhem"
|
|
toolUser="$toolName"
|
|
toolHome="/opt/fhem"
|
|
toolVersion="6.0"
|
|
toolDpkg="fhem-${toolVersion}.deb"
|
|
toolUrl="http://fhem.de/$toolDpkg"
|
|
# default deps listed at https://debian.fhem.de/
|
|
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)
|
|
toolDeps2+=" libnet-xmpp-perl libxml-stream-perl libnet-jabber-perl"
|
|
|
|
|
|
# Get script working directory
|
|
# (when called from a different directory)
|
|
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
|
|
WSUBDIR="${WDIR}/${toolName}"
|
|
#CONFIG_FILE="$WDIR/${toolName}.cfg"
|
|
#CONFIG_FILE_DEFAULT="${CONFIG_FILE}.example"
|
|
|
|
#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() { ALIAS="install"; }
|
|
step_1() {
|
|
local aptOpt=
|
|
if [ $QUIET != 0 ] ; 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 "Download and install $toolName version $toolVersion"; }
|
|
step_2() {
|
|
exe wget "$toolUrl" -O "$downPath"
|
|
endReturn -o $? "Download of $toolName failed"
|
|
exe dpkg -i "$downPath"
|
|
endReturn -o $? "Installation of $toolName failed"
|
|
}
|
|
downPath="/tmp/$toolDpkg"
|
|
|
|
step_3_info() { echo "Start $toolName service"; }
|
|
step_3() {
|
|
exe systemctl restart fhem.service
|
|
}
|
|
|
|
step_20_info() { echo "List $toolName prerequisits"; }
|
|
step_20_alias() { ALIAS="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() { ALIAS="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 -ne 0 ] ; 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() { ALIAS="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() { ALIAS="exe"; }
|
|
step_40() {
|
|
shift
|
|
exe perl "${toolHome}/fhem.pl" 7072 "$1"
|
|
}
|
|
|
|
VERSION_SEQREV=11
|
|
. /usr/local/bin/sequencer.sh
|