forked from crazy-max/docker-matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matomo_watch_plugins
42 lines (38 loc) · 1.74 KB
/
matomo_watch_plugins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
function isPluginInstalled() {
grep -Fxq "PluginsInstalled[] = \"${1}\"" /data/config/config.ini.php
}
inotifywait -e create,delete,close_write,moved_to,moved_from -m /data/config/ /data/plugins/ |
while read -r directory events file; do
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] === Event(s) '$events' triggered for '$file'"
# config.ini.php modified
if [ "$directory" = "/data/config/" -a "$file" = "config.ini.php" -a ${events} = "CLOSE_WRITE,CLOSE" ]; then
sleep 2
plugins=$(ls -l /var/www/plugins | egrep '^l' | awk '{print $9}')
for plugin in ${plugins}; do
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] Check plugin $plugin"
if ! isPluginInstalled ${plugin}; then
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] Remove orphan plugin $plugin"
rm -f /var/www/plugins/${plugin}
rm -rf /data/plugins/${plugin}
fi
done
fi
# handle plugins in /data/plugins/
if [ "$directory" = "/data/plugins/" ]; then
if [ ${events} = "CREATE,ISDIR" -o ${events} = "MOVED_TO,ISDIR" ]; then
if [ -d /var/www/plugins/${file} ]; then
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] Remove '/var/www/plugins/${file}'"
rm -rf /var/www/plugins/${file}
fi
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] Create symlink to '/var/www/plugins/${file}'"
ln -sf /data/plugins/${file} /var/www/plugins/${file}
sleep 1
elif [ ${events} == "DELETE,ISDIR" ]; then
echo "[$(date +'%Y/%m/%d %H:%M:%S')] [watch_plugins] Folder '/data/plugins/${file}' has been removed. Disable plugin ${file}"
php /var/www/console plugin:deactivate --no-interaction ${file}
rm -f /var/www/plugins/${file}
sleep 1
fi
fi
done