Skip to content

Commit 5e7d183

Browse files
authored
Update locate_mirror (#2678)
1 parent 441b4ea commit 5e7d183

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

addons/locate_mirror.sh

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ source /var/scripts/fetch_lib.sh
1010
# Must be root
1111
root_check
1212

13-
# Use another method if the new one doesn't work
14-
if [ -z "$REPO" ]
15-
then
16-
REPO=$(apt-get update -q4 && apt-cache policy | grep http | tail -1 | awk '{print $2}')
17-
fi
18-
1913
# Check where the best mirrors are and update
2014
msg_box "To make downloads as fast as possible when updating Ubuntu \
2115
you should download mirrors that are as geographically close to you as possible.
@@ -24,34 +18,43 @@ Please note that there are no guarantees that the download mirrors \
2418
this script finds will remain for the lifetime of this server.
2519
Because of this, we don't recommend that you change the mirror unless you live far away from the default.
2620
27-
This is the method used: https://github.com/jblakeman/apt-select"
28-
msg_box "Your current server repository is: $REPO"
21+
This is the method used: https://github.com/vegardit/fast-apt-mirror.sh"
22+
23+
# Install
24+
install_if_not bash
25+
install_if_not curl
26+
install_if_not apt-transport-https
27+
install_if_not ca-certificates
28+
curl_to_dir https://raw.githubusercontent.com/vegardit/fast-apt-mirror.sh/v1/ fast-apt-mirror.sh /usr/local/bin
29+
mv /usr/local/bin/fast-apt-mirror.sh /usr/local/bin/fast-apt-mirror
30+
chmod 755 /usr/local/bin/fast-apt-mirror
2931

32+
# Variables
33+
CURRENT_MIRROR=$(fast-apt-mirror current)
34+
FIND_MIRROR=$(fast-apt-mirror find -v --healthchecks 100)
35+
msg_box "Current mirror is $CURRENT_MIRROR"
36+
37+
# Ask
3038
if ! yesno_box_no "Do you want to try to find a better mirror?"
3139
then
32-
print_text_in_color "$ICyan" "Keeping $REPO as mirror..."
40+
print_text_in_color "$ICyan" "Keeping $CURRENT_MIRROR as mirror..."
3341
sleep 1
3442
else
35-
if [[ "$KEYBOARD_LAYOUT" =~ ,|/|_ ]]
36-
then
37-
msg_box "Your keymap contains more than one language, or a special character. ($KEYBOARD_LAYOUT)
38-
This script can only handle one keymap at the time.\nThe default mirror ($REPO) will be kept."
39-
exit 1
40-
fi
43+
# Find
4144
print_text_in_color "$ICyan" "Locating the best mirrors..."
42-
curl_to_dir https://bootstrap.pypa.io get-pip.py /tmp
43-
install_if_not python3
44-
install_if_not python3-testresources
45-
install_if_not python3-distutils
46-
cd /tmp && python3 get-pip.py
47-
pip install \
48-
--upgrade pip \
49-
apt-select
50-
check_command apt-select -m up-to-date -t 4 -c -C "$KEYBOARD_LAYOUT"
51-
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
52-
if [ -f sources.list ]
45+
if [ "$CURRENT_MIRROR/" != "$FIND_MIRROR" ]
5346
then
54-
sudo mv sources.list /etc/apt/
47+
if yesno_box_yes "Do you want to replace the $CURRENT_MIRROR with $FIND_MIRROR?"
48+
then
49+
# Backup
50+
cp -f /etc/apt/sources.list /etc/apt/sources.list.backup
51+
# Replace
52+
if fast-apt-mirror current --apply # TODO is fast-apt-mirror.sh set better here?
53+
then
54+
msg_box "Your Ubuntu repo was successfully changed to $FASTEST_MIRROR"
55+
fi
56+
fi
57+
else
58+
msg_box "You already have the fastest mirror available, congrats!"
5559
fi
56-
msg_box "The apt-mirror was successfully changed."
5760
fi

0 commit comments

Comments
 (0)