From c5e774ad21eb58d5c6bb8fb44c7e9aa45fc362cd Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 19 Sep 2024 20:10:31 +0200 Subject: [PATCH 1/2] Improve locate mirror script Signed-off-by: Daniel Hansson --- addons/locate_mirror.sh | 49 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/addons/locate_mirror.sh b/addons/locate_mirror.sh index 27fa5808cc..36d35b8747 100644 --- a/addons/locate_mirror.sh +++ b/addons/locate_mirror.sh @@ -3,13 +3,42 @@ # T&M Hansson IT AB © - 2024, https://www.hanssonit.se/ true -SCRIPT_NAME="Locate Mirror" +SCRIPT_NAME="Locate mirror" # shellcheck source=lib.sh source /var/scripts/fetch_lib.sh +SCRIPT_EXPLAINER="To make downloads as fast as possible when updating Ubuntu \ +you should download mirrors that are as geographically close to you as possible. + +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/vegardit/fast-apt-mirror.sh" + +# Check for errors + debug code and abort if something isn't right +# 1 = ON +# 0 = OFF +DEBUG=0 +debug_mode # Must be root root_check +# Check if Locate Mirror is already installed +if ! [ -f /usr/local/bin/fast-apt-mirror ] +then + # Ask for installing + install_popup "$SCRIPT_NAME" +else + # Ask for removal or reinstallation + reinstall_remove_menu "$SCRIPT_NAME" + # Removal + rm -f /usr/local/bin/fast-apt-mirror + rm -f /etc/apt/sources.list.backup + # Show successful uninstall if applicable + removal_popup "$SCRIPT_NAME" +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. @@ -29,9 +58,8 @@ curl_to_dir https://raw.githubusercontent.com/vegardit/fast-apt-mirror.sh/v1/ fa 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) +# Check current mirror +CURRENT_MIRROR="$(fast-apt-mirror current)" msg_box "Current mirror is $CURRENT_MIRROR" # Ask @@ -40,18 +68,25 @@ then print_text_in_color "$ICyan" "Keeping $CURRENT_MIRROR as mirror..." sleep 1 else + if [[ "$KEYBOARD_LAYOUT" =~ ,|/|_ ]] + then + msg_box "Your keymap (country code) contains more than one language, or a special character. ($KEYBOARD_LAYOUT) +This script can only handle one keymap at the time.\nThe default mirror ($CURRENT_MIRROR) will be kept." + exit 1 + fi # Find + FIND_MIRROR="$(fast-apt-mirror find -v --healthchecks 100 --speedtests 10 --country $KEYBOARD_LAYOUT)" print_text_in_color "$ICyan" "Locating the best mirrors..." - if [ "$CURRENT_MIRROR/" != "$FIND_MIRROR" ] + if [ "$CURRENT_MIRROR" != "$FIND_MIRROR" ] then 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? + if fast-apt-mirror set "$FIND_MIRROR" then - msg_box "Your Ubuntu repo was successfully changed to $FASTEST_MIRROR" + msg_box "Your Ubuntu repo was successfully changed to $FIND_MIRROR" fi fi else From 0621ac3e2bb3eb806c75fa203422649e180a66d5 Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Thu, 19 Sep 2024 20:48:06 +0200 Subject: [PATCH 2/2] Update addons/locate_mirror.sh Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Daniel Hansson --- addons/locate_mirror.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/locate_mirror.sh b/addons/locate_mirror.sh index 36d35b8747..f7966b9d73 100644 --- a/addons/locate_mirror.sh +++ b/addons/locate_mirror.sh @@ -75,7 +75,7 @@ This script can only handle one keymap at the time.\nThe default mirror ($CURREN exit 1 fi # Find - FIND_MIRROR="$(fast-apt-mirror find -v --healthchecks 100 --speedtests 10 --country $KEYBOARD_LAYOUT)" + FIND_MIRROR="$(fast-apt-mirror find -v --healthchecks 100 --speedtests 10 --country "$KEYBOARD_LAYOUT")" print_text_in_color "$ICyan" "Locating the best mirrors..." if [ "$CURRENT_MIRROR" != "$FIND_MIRROR" ] then