#!/bin/sh
# Copyright (C) 2000-2016 Synology Inc. All rights reserved.

### This script will be execute when package installed and upgraded.
### Actions before package installed.
### ex. check environment.

res=$(ps -e | grep SyncoveryCL | grep ./ 2>&1)

/usr/syno/bin/synologset1 sys info 0x11100000 "[Syncovery] Status before installation: $res"

echo "[Syncovery] Status before installation:" >>"$SYNOPKG_PKGDEST"/log.txt
echo "$res" >>"$SYNOPKG_PKGDEST"/log.txt

   if [ "$(pidof SyncoveryGuardian)" ]
   then
      echo "preinst: Guardian Running" >>"$SYNOPKG_PKGDEST"/log.txt
#      killall SyncoveryGuardian >>"$SYNOPKG_PKGDEST"/log.txt 2>&1

      res=$(/var/packages/SyncoveryGuardian/scripts/start-stop-status stop >>"$SYNOPKG_PKGDEST"/log.txt 2>&1)

      echo "Guardian Stopped Hopefully" >>"$SYNOPKG_PKGDEST"/log.txt
      echo "Guardian" >/tmp/syncoveryguardianstatus 2>"$SYNOPKG_PKGDEST"/log.txt
   else
      echo "preinst: Guardian Not Running" >>"$SYNOPKG_PKGDEST"/log.txt
      rm /tmp/syncoveryguardianstatus  >>"$SYNOPKG_PKGDEST"/log.txt 2>&1
   fi

exit 0
