# Generated by TGLinuxReleaser

pre_upgrade() {
    :
#!/bin/sh

if [ -f "/usr/lib/Syncovery/SyncoveryCL" ]; then
   /usr/lib/Syncovery/SyncoveryCL stop
fi

exit 0

}

post_install() {
    :
#!/bin/sh

ln -fs /usr/lib/Syncovery/SyncoveryCL /usr/bin

if [ -x "$(command -v semodule)" ]; then
   echo Importing SyncoveryCL SELinux Policy
   semodule -i /usr/lib/Syncovery/Misc/SyncoveryCL.pp
   /usr/lib/Syncovery/SyncoveryCL /DETECTCONFIGPATH /SELINUX
else
   /usr/lib/Syncovery/SyncoveryCL /DETECTCONFIGPATH
fi

/usr/lib/Syncovery/SyncoveryCL SET /WEBSERVER=0.0.0.0

#if [[ `systemctl` =~ -\.mount ]]; then

itissystemd="0";

if [ -x "$(command -v systemctl)" ]; then
   if systemctl | grep -q "\-.mount"; then
      itissystemd="1";
   fi
fi

if [ "$itissystemd" = "1" ] ; then
   echo "Preparing service for systemd"

#    remove obsolete SysV files from older installs
   if [ -f "/etc/rc.d/init.d/syncoverycl" ]; then
      if [ -x "$(command -v chkconfig)" ]; then
         chkconfig --del syncoverycl >/dev/null 2>&1
      fi
      rm /etc/rc.d/init.d/syncoverycl
   fi

   if [ -f "/etc/init.d/syncoverycl" ]; then
      rm /etc/init.d/syncoverycl
      if [ -x "$(command -v update-rc.d)" ]; then
         update-rc.d -f syncoverycl remove >/dev/null 2>&1
      fi
   fi

   if [ -f "/run/systemd/generator.late/syncovery.service" ]; then
      rm /run/systemd/generator.late/syncovery.service
   fi

   if [ -f "/run/systemd/generator.late/syncoverycl.service" ]; then
      rm /run/systemd/generator.late/syncoverycl.service
   fi

   cp /usr/lib/Syncovery/Misc/syncoverycl.service /etc/systemd/system
   systemctl daemon-reload
   systemctl enable syncoverycl
   sleep 1
   systemctl start syncoverycl
else
   echo "Preparing service for SysV init"
   if [ -d "/etc/init.d" ]; then
      cp /usr/lib/Syncovery/Misc/syncoverycl /etc/init.d
   else
      if [ -d "/etc/rc.d/init.d" ]; then
         cp /usr/lib/Syncovery/Misc/syncoverycl /etc/rc.d/init.d
      else
         echo "init.d directory not found"
      fi
   fi
   if [ -x "$(command -v chkconfig)" ]; then
      chkconfig --add syncoverycl
   else
      if [ -x "$(command -v update-rc.d)" ]; then
         update-rc.d syncoverycl defaults
      fi
   fi
fi

# possibly redundant ...
sleep 1
/usr/lib/Syncovery/SyncoveryCL start

exit 0

}

post_upgrade() {
    :
#!/bin/sh

ln -fs /usr/lib/Syncovery/SyncoveryCL /usr/bin

if [ -x "$(command -v semodule)" ]; then
   echo Importing SyncoveryCL SELinux Policy
   semodule -i /usr/lib/Syncovery/Misc/SyncoveryCL.pp
   /usr/lib/Syncovery/SyncoveryCL /DETECTCONFIGPATH /SELINUX
else
   /usr/lib/Syncovery/SyncoveryCL /DETECTCONFIGPATH
fi

/usr/lib/Syncovery/SyncoveryCL SET /WEBSERVER=0.0.0.0

#if [[ `systemctl` =~ -\.mount ]]; then

itissystemd="0";

if [ -x "$(command -v systemctl)" ]; then
   if systemctl | grep -q "\-.mount"; then
      itissystemd="1";
   fi
fi

if [ "$itissystemd" = "1" ] ; then
   echo "Preparing service for systemd"

#    remove obsolete SysV files from older installs
   if [ -f "/etc/rc.d/init.d/syncoverycl" ]; then
      if [ -x "$(command -v chkconfig)" ]; then
         chkconfig --del syncoverycl >/dev/null 2>&1
      fi
      rm /etc/rc.d/init.d/syncoverycl
   fi

   if [ -f "/etc/init.d/syncoverycl" ]; then
      rm /etc/init.d/syncoverycl
      if [ -x "$(command -v update-rc.d)" ]; then
         update-rc.d -f syncoverycl remove >/dev/null 2>&1
      fi
   fi

   if [ -f "/run/systemd/generator.late/syncovery.service" ]; then
      rm /run/systemd/generator.late/syncovery.service
   fi

   if [ -f "/run/systemd/generator.late/syncoverycl.service" ]; then
      rm /run/systemd/generator.late/syncoverycl.service
   fi

   cp /usr/lib/Syncovery/Misc/syncoverycl.service /etc/systemd/system
   systemctl daemon-reload
   systemctl enable syncoverycl
   sleep 1
   systemctl start syncoverycl
else
   echo "Preparing service for SysV init"
   if [ -d "/etc/init.d" ]; then
      cp /usr/lib/Syncovery/Misc/syncoverycl /etc/init.d
   else
      if [ -d "/etc/rc.d/init.d" ]; then
         cp /usr/lib/Syncovery/Misc/syncoverycl /etc/rc.d/init.d
      else
         echo "init.d directory not found"
      fi
   fi
   if [ -x "$(command -v chkconfig)" ]; then
      chkconfig --add syncoverycl
   else
      if [ -x "$(command -v update-rc.d)" ]; then
         update-rc.d syncoverycl defaults
      fi
   fi
fi

# possibly redundant ...
sleep 1
/usr/lib/Syncovery/SyncoveryCL start

exit 0

}

pre_remove() {
    :
#!/bin/sh

/usr/lib/Syncovery/SyncoveryCL stop

killall SyncoveryCL >/dev/null 2>&1
killall -9 SyncoveryCL >/dev/null 2>&1

if [ -x "$(command -v semodule)" ]; then
   echo Removing SyncoveryCL SELinux Policy
   semodule -r SyncoveryCL
fi


rm -f "/usr/bin/SyncoveryCL"

   if [ -f "/etc/rc.d/init.d/syncoverycl" ]; then
      if [ -x "$(command -v chkconfig)" ]; then
         chkconfig --del syncoverycl
      fi
      rm /etc/rc.d/init.d/syncoverycl
   fi

   if [ -f "/etc/init.d/syncoverycl" ]; then
      rm /etc/init.d/syncoverycl
      if [ -x "$(command -v update-rc.d)" ]; then
         update-rc.d -f syncoverycl remove
      fi
   fi

   if [ -f "/run/systemd/generator.late/syncovery.service" ]; then
      rm /run/systemd/generator.late/syncovery.service
   fi

   if [ -f "/run/systemd/generator.late/syncoverycl.service" ]; then
      rm /run/systemd/generator.late/syncoverycl.service
   fi

   if [ -f "/etc/systemd/system/syncoverycl.service" ]; then
      systemctl disable syncoverycl
      rm /etc/systemd/system/syncoverycl.service
   fi

exit 0

}

