-
-
Save thiagozs/6513109 to your computer and use it in GitHub Desktop.
Download from apache with check geo targeting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# author: André Kelpe <efeshunderelf at googlemail.com> | |
# licencse: Apache v2 | |
GRRR_WGET_OPTIONS="--user-agent grrr/1.0" | |
# find out our region and yes, you can get this as csv file. How cool is that? | |
GEOIP_REGION=$(wget -qO- freegeoip.net/csv/ | tr '[A-Z]' '[a-z]' | tr -d '"'| awk -F, '{print $2}') | |
# classic confusion between geoip db and apache mirror list | |
if [ $GEOIP_REGION == "gb" ]; then | |
GEOIP_REGION=uk | |
fi | |
MIRRORLIST_FILE_NAME=$(mktemp) | |
# download the latest mirror list from apache. we ignore the last | |
# sync times and hope for the best... | |
wget -qO- http://www.apache.org/mirrors/mirrors.list | grep -v '^$' \ | |
| grep http | grep -v ' 0$' | grep -v '^#' > $MIRRORLIST_FILE_NAME | |
# use US as the default region. apache does the same in their scripts... | |
REGION=us | |
# check if there is a mirror in our region | |
if grep -q " $GEOIP_REGION " $MIRRORLIST_FILE_NAME; then | |
REGION=$GEOIP_REGION | |
fi | |
# finally download it all | |
wget $GRRR_WGET_OPTIONS $(grep " $REGION " $MIRRORLIST_FILE_NAME | shuf | head -1 | awk '{print $3}')/$* | |
retval=$? | |
# clean up after ourselves. | |
rm $MIRRORLIST_FILE_NAME | |
exit $retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment