forked from nextcloud/vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocate_mirror.sh
58 lines (50 loc) · 2 KB
/
locate_mirror.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
# shellcheck disable=2034,2059
true
SCRIPT_NAME="Locate Mirror"
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
# Must be root
root_check
# Use another method if the new one doesn't work
if [ -z "$REPO" ]
then
REPO=$(apt 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 have download mirrors that are as close to you as possible.
Please note that there are no gurantees that the download mirrors \
this script will find are staying up for the lifetime of this server.
Because of this, we don't recommend to change the mirror, except you live far away from the default mirror.
This is the method used: https://github.com/jblakeman/apt-select"
msg_box "Your current server repository is: $REPO"
if ! yesno_box_no "Do you want to try to find a better mirror?"
then
print_text_in_color "$ICyan" "Keeping $REPO 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
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 ]
then
sudo mv sources.list /etc/apt/
fi
msg_box "The apt-mirror was successfully changed."
fi