Skip to content

Commit

Permalink
Update locate_mirror (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
enoch85 authored Sep 19, 2024
1 parent 441b4ea commit 5e7d183
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions addons/locate_mirror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ source /var/scripts/fetch_lib.sh
# Must be root
root_check

# Use another method if the new one doesn't work
if [ -z "$REPO" ]
then
REPO=$(apt-get update -q4 && apt-cache policy | grep http | tail -1 | awk '{print $2}')
fi

# Check where the best mirrors are and update
msg_box "To make downloads as fast as possible when updating Ubuntu \
you should download mirrors that are as geographically close to you as possible.
Expand All @@ -24,34 +18,43 @@ Please note that there are no guarantees that the download mirrors \
this script finds will remain for the lifetime of this server.
Because of this, we don't recommend that you change the mirror unless you live far away from the default.
This is the method used: https://github.com/jblakeman/apt-select"
msg_box "Your current server repository is: $REPO"
This is the method used: https://github.com/vegardit/fast-apt-mirror.sh"

# Install
install_if_not bash
install_if_not curl
install_if_not apt-transport-https
install_if_not ca-certificates
curl_to_dir https://raw.githubusercontent.com/vegardit/fast-apt-mirror.sh/v1/ fast-apt-mirror.sh /usr/local/bin
mv /usr/local/bin/fast-apt-mirror.sh /usr/local/bin/fast-apt-mirror
chmod 755 /usr/local/bin/fast-apt-mirror

# Variables
CURRENT_MIRROR=$(fast-apt-mirror current)
FIND_MIRROR=$(fast-apt-mirror find -v --healthchecks 100)
msg_box "Current mirror is $CURRENT_MIRROR"

# Ask
if ! yesno_box_no "Do you want to try to find a better mirror?"
then
print_text_in_color "$ICyan" "Keeping $REPO as mirror..."
print_text_in_color "$ICyan" "Keeping $CURRENT_MIRROR as mirror..."
sleep 1
else
if [[ "$KEYBOARD_LAYOUT" =~ ,|/|_ ]]
then
msg_box "Your keymap contains more than one language, or a special character. ($KEYBOARD_LAYOUT)
This script can only handle one keymap at the time.\nThe default mirror ($REPO) will be kept."
exit 1
fi
# Find
print_text_in_color "$ICyan" "Locating the best mirrors..."
curl_to_dir https://bootstrap.pypa.io get-pip.py /tmp
install_if_not python3
install_if_not python3-testresources
install_if_not python3-distutils
cd /tmp && python3 get-pip.py
pip install \
--upgrade pip \
apt-select
check_command apt-select -m up-to-date -t 4 -c -C "$KEYBOARD_LAYOUT"
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
if [ -f sources.list ]
if [ "$CURRENT_MIRROR/" != "$FIND_MIRROR" ]
then
sudo mv sources.list /etc/apt/
if yesno_box_yes "Do you want to replace the $CURRENT_MIRROR with $FIND_MIRROR?"
then
# Backup
cp -f /etc/apt/sources.list /etc/apt/sources.list.backup
# Replace
if fast-apt-mirror current --apply # TODO is fast-apt-mirror.sh set better here?
then
msg_box "Your Ubuntu repo was successfully changed to $FASTEST_MIRROR"
fi
fi
else
msg_box "You already have the fastest mirror available, congrats!"
fi
msg_box "The apt-mirror was successfully changed."
fi

0 comments on commit 5e7d183

Please sign in to comment.