66 lines
2.3 KiB
Bash
66 lines
2.3 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
echo "This Script has to be ran as Sudo"
|
||
|
|
sudo -v
|
||
|
|
echo "Installing IP2Location Mod for Apache"
|
||
|
|
## Install Required Pkgs
|
||
|
|
sudo apt update -y && sudo apt upgrade -y
|
||
|
|
sudo apt-get install libpcre2-dev libbz2-dev unzip zlib1g-dev apache2-dev -y
|
||
|
|
|
||
|
|
## Make file structure and get C file and build
|
||
|
|
mkdir ~/IP2Location
|
||
|
|
cd ~/IP2Location
|
||
|
|
wget https://github.com/chrislim2888/IP2Location-C-Library/archive/master.zip -O "IP2Location-C-Library.zip"
|
||
|
|
unzip -o IP2Location-C-Library.zip
|
||
|
|
cd IP2Location-C-Library-master
|
||
|
|
sudo autoreconf -i -v --force
|
||
|
|
sudo ./configure
|
||
|
|
sudo make
|
||
|
|
sudo make install
|
||
|
|
|
||
|
|
## Get apache-mod files and build
|
||
|
|
cd ~/IP2Location
|
||
|
|
wget https://github.com/ip2location/ip2location-apache/archive/master.zip -O "ip2location-apache-master.zip"
|
||
|
|
unzip -o ip2location-apache-master.zip
|
||
|
|
cd ip2location-apache-master
|
||
|
|
|
||
|
|
sudo apxs2 -i -a -L ../IP2Location-C-Library-master/libIP2Location/ -I ../IP2Location-C-Library-master/libIP2Location/ -l IP2Location -c mod_ip2location.c
|
||
|
|
|
||
|
|
sudo a2enmod IP2Location
|
||
|
|
|
||
|
|
## Make DB file structure and download DB file
|
||
|
|
sudo mkdir /opt/IP2Location
|
||
|
|
sudo chown phil:www-data -R /opt/IP2Location
|
||
|
|
sudo chmod 760 -R /opt/IP2Location
|
||
|
|
wget "https://cdn-edge-r2.ncltech.com/ipdb/ip2location/IP2LOCATION-LITE-DB1.BIN" -O "/opt/IP2Location/IP2LOCATION-LITE-DB1.BIN"
|
||
|
|
|
||
|
|
## Echo "mod_ip2location.c" into apache2.conf file
|
||
|
|
sudo cat >>/etc/apache2/apache2.conf<<EOF
|
||
|
|
<IfModule mod_ip2location.c>
|
||
|
|
IP2LocationEnable On
|
||
|
|
IP2LocationDetectProxy On
|
||
|
|
IP2LocationSetmode ALL
|
||
|
|
IP2LocationDBFile /opt/IP2Location/IP2LOCATION-LITE-DB1.BIN
|
||
|
|
</IfModule>
|
||
|
|
EOF
|
||
|
|
|
||
|
|
## Create cron task to grab DB file from cdn-edge-r2.ncltech.com
|
||
|
|
sudo cat >> /etc/crontab<<EOF
|
||
|
|
0 8 * * * phil 'wget "https://cdn-edge-r2.ncltech.com/ipdb/ip2location/IP2LOCATION-LITE-DB1.BIN" -O "/opt/IP2Location/IP2LOCATION-LITE-DB1.BIN && sudo chown phil:www-data -R /opt/IP2Location && sudo chmod 760 -R /opt/IP2Location"'
|
||
|
|
EOF
|
||
|
|
|
||
|
|
## Restart Apache2
|
||
|
|
sudo ldconfig
|
||
|
|
sudo systemctl restart apache2
|
||
|
|
|
||
|
|
## Hopefully no errors
|
||
|
|
echo ""
|
||
|
|
echo "That should be that, now a .htaccess file is required to select countrys to redirect"
|
||
|
|
echo ""
|
||
|
|
echo "Example .htaccess file"
|
||
|
|
echo ""
|
||
|
|
echo "RewriteEngine On"
|
||
|
|
echo "RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^RU$"
|
||
|
|
echo "RewriteRule ^(.*)$ https://www.nato.int/cps/en/natohq/news_192401.htm [L]"
|
||
|
|
|
||
|
|
|