Compare commits
No commits in common. "ee188a30d7de7a729efbd337c33ad4a69e0333c2" and "dbb756c2c6e4882a5dbbe1fdd16840c9bf435d86" have entirely different histories.
ee188a30d7
...
dbb756c2c6
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
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 () {
|
function main () {
|
||||||
# check for ubuntu only
|
# check for ubuntu only
|
||||||
if ! grep -qi '^ID=ubuntu' /etc/os-release; then
|
if ! grep -qi '^ID=ubuntu' /etc/os-release; then
|
||||||
@ -29,25 +25,15 @@ function main () {
|
|||||||
find /etc/apt/sources.list.d/ -type f -exec \
|
find /etc/apt/sources.list.d/ -type f -exec \
|
||||||
sed -i "s|archive\.ubuntu\.com|us.ubuntu.com|g" {} +
|
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
|
echo "Detecting actual country..." > /dev/stderr
|
||||||
|
|
||||||
|
apt update && apt install -y curl jq
|
||||||
IPINFO="$(curl -s ipinfo.io)"
|
IPINFO="$(curl -s ipinfo.io)"
|
||||||
|
|
||||||
if [ -z "$IPINFO" ]; then
|
if [ -z "$IPINFO" ]; then
|
||||||
echo "Failed to get IP info" > /dev/stderr
|
echo "Failed to get IP info" > /dev/stderr
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COUNTRYCODE="$(jq .country -r <<< "$IPINFO")"
|
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
|
echo "IP geolocated as country: $COUNTRYCODE" > /dev/stderr
|
||||||
|
|
||||||
if ! grep -qE 'http(s)?://us\.archive\.ubuntu\.com/' /etc/apt/sources.list.d/*; then
|
if ! grep -qE 'http(s)?://us\.archive\.ubuntu\.com/' /etc/apt/sources.list.d/*; then
|
||||||
@ -56,7 +42,7 @@ function main () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$COUNTRYCODE" == "US" ]]; then
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user