#!/bin/bash

DIR="/var/www/onlyoffice/documentserver"
NGINX_ONLYOFFICE_PATH="/etc/onlyoffice/documentserver/nginx"

cd ${DIR}
# Make gziped scripts
find ./sdkjs ./web-apps ./sdkjs-plugins ./dictionaries -type f \( -name *.js -o -name *.json -o -name *.htm -o -name *.html -o -name *.css -o -name *.bin -o -name *.wasm -o -name *.dic -o -name *.aff -o -name *.svg \) -exec gzip -kf9 {} \;

# Make gziped fonts
find ./fonts -type f ! -name "*.*" -exec gzip -kf9 {} \;

# Turn on static gzip for nginx
sed 's/#*\s*\(gzip_static\).*/\1 on;/g' \
  -i ${NGINX_ONLYOFFICE_PATH}/includes/ds-docservice.conf

# Reload nginx config
[ $(pgrep -x ""systemd"" | wc -l) -gt 0 ] && systemctl reload nginx || service nginx reload
