#!/bin/bash
###============================================================
##      Ubuntu 18.04 Brotli updater Dependencies installer
###============================================================
# 						RUN THIS ONCE
##=============================================================
##Nginx Config Example
#location /deb/brotli/{
#alias /var/www/brotli-builds/;
#autoindex on;
#}
##
##=============================================================#


#install Dependencies
apt install -y curl gnupg dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip apt-show-versions git

#add repo
curl -L https://nginx.org/keys/nginx_signing.key | apt-key add -
wget https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/master/config/apt/nginx.list -O /etc/apt/sources.list.d/nginx.list
apt update

#Checking for local version log
if [ ! -f /var/log/nginxVersion.txt ]; then
    echo 0 > /var/log/nginxVersion.txt
fi

#downloading Brotli updater scrips
wget https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/master/Brotli/update-brotli.sh -O /opt/update-brotli.sh 
sed -i "\$a0 2 * * 1 root    /bin/bash /opt/update-brotli.sh >/dev/null 2>&1" /etc/crontab


# setting webserver folder for package downloads
mkdir -p /var/www/brotli-builds
chown www-data:www-data /var/www/brotli-builds