Last active
April 22, 2020 13:11
-
-
Save danhper/cec8298ab95e45b94c60c968fe27c352 to your computer and use it in GitHub Desktop.
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 | |
version="7.0.7" | |
fallback_mirror="http://us1.php.net/get/php-$version.tar.bz2/from/this/mirror" | |
mirrors=$(curl -s https://secure.php.net/get/php-$version.tar.bz2/from/a/mirror | grep -Eo 'http://.+/from/this/mirror') | |
country=$(curl -s ipinfo.io | sed -n 's/\s*"country": "\(.\+\)",/\1/p' | tr '[:upper:]' '[:lower:]') | |
user_mirror="" | |
for mirror in $mirrors; do | |
if [ "$country" = ${mirror:7:2} ]; then | |
user_mirror=$mirror | |
break | |
fi | |
done | |
if [ -z "$user_mirror" ]; then | |
user_mirror=$fallback_mirror | |
fi | |
curl -#L $user_mirror > php-$version.tar.bz2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment