#!/bin/bash SCRIPTVERSION="$Id:2.1$" # Author: Adimarantis # License: GPL #Install script for FHEM including signal-cli FHEMVERSION=6.0 FHEMUSER=fhem FHEMGROUP=fhem SIGNALVAR=/var/lib/signal-cli SIGNALBOTSOURCE=https://github.com/bublath/FHEM-Signalbot LOG=/tmp/docker_install.log TMPFILE=/tmp/signal$$.tmp OPERATION=$1 BUILDDIR=$HOME/fhem #Space separated list of additional packages, installed with apt (linux), cpan (perl) or npm (node.js) APT="usbutils libimage-librsvg-perl perl libcpan-changes-perl liburi-perl" CPAN="local::lib" NPM= #for signal-cli APT="$APT wget default-jre zip base-files libdbus-1-dev zip build-essential" #APT="$APT wget haveged default-jre qrencode pkg-config gcc zip libexpat1-dev libxml-parser-perl libtemplate-perl libxml-xpath-perl build-essential xml-twig-tools base-files" CPAN="$CPAN Protocol::DBus" #for DBLOG APT="$APT default-mysql-client libdbd-mysql libdbd-mysql-perl" #for FRITZBOX #APT="$APT libjson-perl libwww-perl libsoap-lite-perl libjson-xs-perl libnet-telnet-perl" #for GoogleCast #APT="$APT python3 python3-pip python3-dev libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libglib2.0-dev libdbus-1-dev bluez libbluetooth-dev" #CPAN="$PERL Protocol::WebSocket" #for Alexa #APT="$APT nodejs npm" #NPM="$NPM alexa-fhem" #gassistent #APT="$APT nodejs npm libjson-perl" #NPM="$NPM gassistant-fhem" #Get OS data if [ -e /etc/os-release ]; then source /etc/os-release cat /etc/os-release >$LOG else echo "Could not find OS release data - are you on Linux?" exit fi if grep -q docker /proc/1/cgroup; then echo "Cannot install Docker inside Docker" exit fi USER=`id | grep root` if [ -z "$USER" ]; then echo "Docker Installation needs to run under root" exit fi FHEM_UID=`id -u $FHEMUSER` FHEM_GID=`id -g $FHEMGROUP` echo "Will create a Docker FHEM instance including signal-cli for Signalbot usage" echo echo "Please verify that these settigns are correct:" echo "FHEM-Version: $FHEMVERSION" echo "SIGNALBOT Repository $SIGNALBOTSOURCE" echo "BUILD directory $BUILDDIR" echo "User $FHEMUSER ($FHEM_UID)" echo "Group $FHEMGROUP ($FHEM_GID)" # install_and_check() { #Check availability of tools and install via apt if missing TOOL=$1 PACKAGE=$2 echo -n "Checking for $TOOL..." WHICH=`which $TOOL` if [ -z "$WHICH" ]; then echo -n "installing ($PACKAGE)" apt-get -q -y install $PACKAGE >>$LOG WHICH=`which $TOOL` if [ -z "$TOOL" ]; then echo "Failed to install $TOOL" exit else echo "done" fi else echo "available" fi } install_by_file() { #Check availability of tools and install via apt if missing FILE=$1 PACKAGE=$2 echo -n "Checking for $FILE..." if ! [ -e "$FILE" ]; then echo -n "installing ($PACKAGE)" apt-get -q -y install $PACKAGE >>$LOG if ! [ -e "$FILE" ]; then echo "Failed to install $FILE" exit else echo "done" fi else echo "available" fi } check_and_create_path() { #Check if path is available and create of not CHECK=$1 echo -n "Checking for $CHECK..." if ! [ -d $CHECK ]; then mkdir $1 if ! [ -d $CHECK ]; then echo "Failed to create $CHECK - did you run on sudo?" exit else echo "created" fi else echo "found" fi if ! [ -w $CHECK ]; then echo "Cannot write to $CHECK - did you start this script with sudo?" exit fi } check_and_compare_file() { #Check if a file exists and compare if its the same as our internal reference file CHECK=$1 COMPARE=$2 echo -n "Checking for $CHECK..." if [ -e $CHECK ]; then echo "found" diff $CHECK $COMPARE DIFF=`diff -q $CHECK $COMPARE` if ! [ -z "$DIFF" ]; then echo "$CHECK differs, update (Y/n)? " read REPLY if [ "$REPLY" = "y" ]; then cp $COMPARE $CHECK echo "$CHECK updated" else echo "$CHECK left untouched" fi fi else cp $COMPARE $CHECK echo "$CHECK installed" fi } #Main part - do always, check basic system requirements like OS, packages etc - does not install any signal specific stuff ARCH=`arch` OSNAME=`uname` RASPI="" if [ $OSNAME != "Linux" ]; then echo "Only Linux systems are supported (you: $OSNAME), quitting" exit fi if [ "$ID" = "raspbian" ] || [ "$ID" = "Raspian" ] || [ "$ARCH" = "armv7l" ]; then echo "You seem to be on a Raspberry pi with $ARCH" RASPI=1 else if [ "$ID" = "ubuntu" ] || [ "$ID" = "Ubuntu" ]; then echo "You seem to run Ubuntu on $ARCH" else echo "Your configuration" uname -a echo "has not been tested, continue at own risk" fi fi check_and_update() { APTCMD=`which apt` if [ -z "$APTCMD" ]; then echo "Can't find apt command - are you on a supported system?" exit fi check_and_create_path $BUILDDIR install_and_check docker docker.io install_and_check wget wget cd $BUILDDIR cat >docker-compose.yml <Dockerfile <entry.sh </tmp/start.log 2>/tmp/start.err fi sudo -u $FHEMUSER perl fhem.pl fhem.cfg echo -n "Waiting for fhem to terminate." WAIT="runs" while [ -n "\$WAIT" ] do WAIT=\`ps -eo pid,command | grep fhem.pl | grep -v grep\` echo -n "." sleep 1 done echo "stopped" EOF cat >org.asamk.Signal.conf < EOF cat >org.asamk.Signal.service <