Compare commits

..

No commits in common. "ee188a30d7de7a729efbd337c33ad4a69e0333c2" and "dbb756c2c6e4882a5dbbe1fdd16840c9bf435d86" have entirely different histories.

View File

@ -2,10 +2,6 @@
set -euo pipefail
function apt_update_if_stale () {
[ -z "$(find /var/lib/apt/lists -type f -mmin -30 2>/dev/null)" ] && apt-get update
}
function main () {
# check for ubuntu only
if ! grep -qi '^ID=ubuntu' /etc/os-release; then
@ -29,25 +25,15 @@ function main () {
find /etc/apt/sources.list.d/ -type f -exec \
sed -i "s|archive\.ubuntu\.com|us.ubuntu.com|g" {} +
apt_update_if_stale
apt install -y jq curl
echo "Detecting actual country..." > /dev/stderr
apt update && apt install -y curl jq
IPINFO="$(curl -s ipinfo.io)"
if [ -z "$IPINFO" ]; then
echo "Failed to get IP info" > /dev/stderr
exit 1
fi
COUNTRYCODE="$(jq .country -r <<< "$IPINFO")"
if [[ -z "$COUNTRYCODE" ]]; then
echo "Failed to get country code" > /dev/stderr
exit 1
fi
echo "IP geolocated as country: $COUNTRYCODE" > /dev/stderr
if ! grep -qE 'http(s)?://us\.archive\.ubuntu\.com/' /etc/apt/sources.list.d/*; then
@ -56,7 +42,7 @@ function main () {
fi
if [[ "$COUNTRYCODE" == "US" ]]; then
echo "Mirror already set to US, nothing to do" > /dev/stderr
echo "Mirror already set to US, nothing to do" > /dev/stderr
exit 0
fi