diff --git a/fhem/contrib/DEBIAN/postinst b/fhem/contrib/DEBIAN/postinst index 523ed27b3..e992d92a7 100644 --- a/fhem/contrib/DEBIAN/postinst +++ b/fhem/contrib/DEBIAN/postinst @@ -1,12 +1,10 @@ #!/bin/bash # $Id$ - set -e -#set -x - - -if ! getent passwd fhem >/dev/null; then +user_exists=$(id -u fhem > /dev/null 2>&1; echo $?) +if [ "$user_exists" -eq "1" ]; then + echo "creating user fhem" useradd --system --home /opt/fhem --gid dialout --shell /bin/false fhem fi @@ -16,14 +14,27 @@ chown -R fhem:dialout /opt/fhem sed -i /debian.fhem.de/d /etc/apt/sources.list # set up of autostart -# Sysvinit; upstart no longer supported +# systemd: supported +# sysvinit: supported +# upstart: not supported -#mkdir -p /etc/init.d -cp /opt/fhem/contrib/init-scripts/fhem.3 /etc/init.d/fhem -chmod ugo+x /etc/init.d/fhem -update-rc.d fhem defaults +# detect init system +test=$(stat /sbin/init |grep "File") +re="systemd$" -if test -f /etc/init.d/fhem; then - /etc/init.d/fhem start noaptmark +if [[ $test =~ $re ]]; +then + cp /opt/fhem/contrib/init-scripts/fhem.service /etc/systemd/system + systemctl daemon-reload + systemctl enable fhem.service + systemctl start fhem.service +else + cp /opt/fhem/contrib/init-scripts/fhem.3 /etc/init.d/fhem + chmod ugo+x /etc/init.d/fhem + update-rc.d fhem defaults + if test -f /etc/init.d/fhem; then + /etc/init.d/fhem start noaptmark + fi fi + exit 0 diff --git a/fhem/contrib/DEBIAN/postrm b/fhem/contrib/DEBIAN/postrm index 957d4a3bf..7db8c5ee4 100755 --- a/fhem/contrib/DEBIAN/postrm +++ b/fhem/contrib/DEBIAN/postrm @@ -1,10 +1,11 @@ #!/bin/bash +# $Id:$ -#set -x -set -e # required by lintian -set +e # Don't know how to check presence of fhem in passwd with -e +set -e -if grep -q fhem /etc/passwd; then +user_exists=$(id -u fhem > /dev/null 2>&1; echo $?) +if [ "$user_exists" -eq "0" ]; then + echo "deleting user fhem" userdel fhem fi @@ -15,3 +16,7 @@ fi if test -f /etc/init.d/fhem; then rm /etc/init.d/fhem fi + +if test -f /etc/systemd/system/fhem.service; then + rm /etc/systemd/system/fhem.service +fi diff --git a/fhem/contrib/DEBIAN/prerm b/fhem/contrib/DEBIAN/prerm index d5ca1da36..a7fe84d46 100755 --- a/fhem/contrib/DEBIAN/prerm +++ b/fhem/contrib/DEBIAN/prerm @@ -1,14 +1,18 @@ -#!/bin/sh +#!/bin/bash +# $Id:$ -#set -x set -e -apt-mark unhold fhem +# detect init system +test=$(stat /sbin/init |grep "File") +re="systemd$" -# stop fhem if running -if test -f /etc/init.d/fhem; then - /etc/init.d/fhem stop noaptmark +if [[ $test =~ $re ]]; then + systemctl stop fhem.service + systemctl disable fhem.service +else + if test -f /etc/init.d/fhem; then + /etc/init.d/fhem stop noaptmark + fi + update-rc.d fhem remove fi - -# remove fhem autostart -update-rc.d -f fhem remove