#!/bin/bash # Define the new mirror URL NEW_MIRROR="http://ubuntu.mobinhost.com" echo "Starting to update Ubuntu repositories..." # 1. Handle classic .list files (Standard for versions < 24.04) # Including /etc/apt/sources.list and any files in sources.list.d FILES_LIST=$(find /etc/apt/ -name "*.list" -type f) for file in $FILES_LIST; do echo "Processing $file..." sed -i.bak "s|http[s]\?://[a-zA-Z0-9.-]*\.archive\.ubuntu\.com|$NEW_MIRROR|g" "$file" sed -i "s|http[s]\?://security\.ubuntu\.com|$NEW_MIRROR|g" "$file" done # 2. Handle new .sources files (DEB822 format used in 24.04+) FILES_SOURCES=$(find /etc/apt/sources.list.d/ -name "*.sources" -type f 2>/dev/null) # Also check the main sources file in 24.04 if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then FILES_SOURCES="$FILES_SOURCES /etc/apt/sources.list.d/ubuntu.sources" fi for file in $FILES_SOURCES; do echo "Processing $file (DEB822 format)..." sed -i.bak "s|http[s]\?://[a-zA-Z0-9.-]*\.archive\.ubuntu\.com|$NEW_MIRROR|g" "$file" sed -i "s|http[s]\?://security\.ubuntu\.com|$NEW_MIRROR|g" "$file" done echo "Update complete. Running apt update..." apt update