File: //usr/syno/plugin/dirsvs_join/AccountCacheDirsvsJoinLeave.sh
#!/bin/sh -x
case $1 in
--sdk-mod-ver)
echo "1.0";
;;
--name)
echo "accountdb cache dirsvs_leave hook"
;;
--pkg-ver)
echo "1.0";
;;
--vendor)
echo "Synology";
;;
--pre)
;;
--post)
# only for domain
if [ "$TYPE" != "domain" ]; then
exit 0
fi
# unlink cache
/usr/bin/systemctl stop accountdb-cache
if [ -L "/usr/syno/etc/private/@accountcache" ]; then
MNT_REALPATH=$(/bin/realpath /usr/syno/etc/private/@accountcache | grep accountcache)
DEVNO_MNT=$(/bin/stat -c "%D" "$MNT_REALPATH")
MNT_REALPATH_PARENT=$(/bin/dirname "$MNT_REALPATH")
DEVNO_PARENT=$(/bin/stat -c "%D" "$MNT_REALPATH_PARENT")
if [ "$DEVNO_MNT" = "$DEVNO_PARENT" ]; then
# not mount
rm -r "/usr/syno/etc/private/@accountcache" "${MNT_REALPATH}"
else
# still mount skip
exit 0
fi
fi
rm "/usr/syno/etc/private/.account.cache.img"
for FILE in /volume*/@accountdb/.account.cache.img
do
if [ -f "$FILE" ]; then
rm "$FILE"
fi
done
if [[ "enabled" == $(/usr/syno/bin/synosystemctl get-enable-status "accountdb-cache") ]]; then
/usr/bin/systemctl start accountdb-cache
fi
;;
*)
echo "Usage: $0 --sdk-mod-ver|--name|--pkg-ver|--vendor|--pre|--post"
;;
esac