Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to new better apt select script #90

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 59 additions & 32 deletions addons/locate_mirror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,84 @@

# T&M Hansson IT AB © - 2024, https://www.hanssonit.se/

# shellcheck disable=2034,2059
true
SCRIPT_NAME="Locate Mirror"
SCRIPT_NAME="Locate mirror"
# shellcheck source=lib.sh
source /var/scripts/fetch_lib.sh || source <(curl -sL https://raw.githubusercontent.com/techandme/wordpress-vm/master/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

# Use another method if the new one doesn't work
if [ -z "$REPO" ]
# Check if Locate Mirror is already installed
if ! [ -f /usr/local/bin/fast-apt-mirror ]
then
REPO=$(apt update -q4 && apt-cache policy | grep http | tail -1 | awk '{print $2}')
# 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 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.
# 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

This is the method used: https://github.com/jblakeman/apt-select"
msg_box "Your current server repository is: $REPO"
# Check current mirror
CURRENT_MIRROR="$(fast-apt-mirror current)"
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" =~ ,|/|_ ]]
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."
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..."
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 set "$FIND_MIRROR"
then
msg_box "Your Ubuntu repo was successfully changed to $FIND_MIRROR"
fi
fi
else
msg_box "You already have the fastest mirror available, congrats!"
fi
msg_box "The apt-mirror was successfully changed."
fi
11 changes: 2 additions & 9 deletions menu/startup_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,8 @@ the server will be rebooted. After the reboot, please login as usual and run thi
;;&
*"Locate Mirror"*)
SUBTITLE="apt-mirror"
msg_box "Current apt-mirror is $REPO" "$SUBTITLE"
if ! yesno_box_yes "Do you want to change the apt-mirror?" "$SUBTITLE"
then
print_text_in_color "$ICyan" "Not changing the apt-mirror..."
sleep 1
else
print_text_in_color "$ICyan" "Downloading the Locate Mirror script..."
run_script ADDONS locate_mirror
fi
print_text_in_color "$ICyan" "Downloading the Locate Mirror script..."
run_script ADDONS locate_mirror
;;&
*)
;;
Expand Down
Loading