diff --git a/src/ucaresystem-core b/src/ucaresystem-core index 2882825..64dad83 100755 --- a/src/ucaresystem-core +++ b/src/ucaresystem-core @@ -21,6 +21,9 @@ set -e SECONDS=0 ## Script starts here +# Global flag for skipping ppa.launchpad +SKIP_PPA_LAUNCHPAD=0 + # Color Variables GREEN="\e[32m" CYAN="\e[36m" @@ -320,6 +323,78 @@ function PREUPDATE_PREFLIGHT { return 0 } +# Function to perform apt update with optional PPA skipping +function APT_UPDATE_WITH_SKIP { + echo -e "${GREEN}▸ Updating package lists ${ENDCOLOR}" + echo + + if [ "$SKIP_PPA_LAUNCHPAD" -eq 1 ]; then + echo -e "${YELLOW}⚠ Skipping ppa.launchpad.net repositories due to --skip-ppa-launchpad flag${ENDCOLOR}" + echo -e "${YELLOW} (Useful when Launchpad is under attack or experiencing issues)${ENDCOLOR}" + echo + + # Run apt update but exclude ppa.launchpad.net by temporarily moving .list files + local temp_dir=$(mktemp -d) + + # Find and move PPA files that contain launchpad + echo -e "${YELLOW}▸ Temporarily disabling Launchpad PPAs...${ENDCOLOR}" + find /etc/apt/sources.list.d/ -name "*launchpad*" -type f 2>/dev/null | while read ppa_file; do + if [ -f "$ppa_file" ]; then + sudo mv "$ppa_file" "$temp_dir/" 2>/dev/null && echo " • Disabled: $(basename "$ppa_file")" + fi + done + + # Also check sources.list for launchpad entries (less common but possible) + if grep -q "launchpad" /etc/apt/sources.list 2>/dev/null; then + sudo cp /etc/apt/sources.list "$temp_dir/sources.list.backup" + sudo sed -i '/launchpad/d' /etc/apt/sources.list + echo " • Disabled launchpad entries in sources.list" + fi + + echo + echo -e "${YELLOW}▸ Running apt update with Launchpad PPAs disabled...${ENDCOLOR}" + + # Run apt update + sudo apt update 2> >(grep -v "^WARNING" >&2) | + while IFS= read -r line; do + printf '%-*s\r' "$(tput cols)" "$line" + done + + echo + echo -e "${YELLOW}▸ Restoring disabled Launchpad PPAs...${ENDCOLOR}" + + # Restore moved PPA files + if [ -d "$temp_dir" ] && [ -n "$(ls -A "$temp_dir" 2>/dev/null)" ]; then + sudo mv "$temp_dir"/* /etc/apt/sources.list.d/ 2>/dev/null + echo " • Restored all Launchpad PPAs" + fi + + # Restore sources.list if modified + if [ -f "$temp_dir/sources.list.backup" ]; then + sudo mv "$temp_dir/sources.list.backup" /etc/apt/sources.list + echo " • Restored sources.list" + fi + + # Clean up temp directory + rm -rf "$temp_dir" + + echo + echo -e "${YELLOW}⚠ Note: ppa.launchpad.net repositories were temporarily skipped${ENDCOLOR}" + echo -e "${YELLOW} They have been restored and will be used in future runs${ENDCOLOR}" + else + # Normal apt update + sudo apt update 2> >(grep -v "^WARNING" >&2) | + while IFS= read -r line; do + printf '%-*s\r' "$(tput cols)" "$line" + done + fi + + echo + echo -e "${CYAN}✓ Finished updating package lists ${ENDCOLOR}" + sleep 1 + echo +} + # Function to handle kernel cleanup function CLEANUP_OLD_KERNELS { local keep_count=${1:-2} # Default to keeping 2 kernels if not specified @@ -400,20 +475,9 @@ function MAINTENANCE { echo fi fi - ## Updates package lists - echo -e "${GREEN}▸ Updating package lists ${ENDCOLOR}" - echo - # Update package lists and filter out warnings - sudo apt update 2> >(grep -v "^WARNING" >&2) | - # Print each line with padding to fit the terminal width - while IFS= read -r line; do - printf '%-*s\r' "$(tput cols)" "$line" - done - echo - echo - echo -e "${CYAN}✓ Finished updating package lists ${ENDCOLOR}" - sleep 1 - echo + + ## Updates package lists (using enhanced function) + APT_UPDATE_WITH_SKIP ## Updates packages and libraries echo -e "${GREEN}▸ Installing system package upgrades...${ENDCOLOR}" @@ -641,8 +705,7 @@ function UPGRADE_EOL_TO_NEXT { if [ ! -f /etc/os-release ]; then echo -e "${RED}✗ Cannot detect distribution${ENDCOLOR}" return 1 - fi - + fi # shellcheck disable=SC1091 . /etc/os-release @@ -911,6 +974,10 @@ function SHOW_HELP { -x --debug Enable debug mode (shell tracing) + --skip-ppa-launchpad + Skip ppa.launchpad.net repositories during apt update + (Useful when Launchpad is under attack or experiencing issues) + -u --upgrade Upgrade to the next Ubuntu release. Note: If you use a regular release it will upgrade to the next one. If you are on a LTS version, it will upgrade ONLY to @@ -1008,6 +1075,10 @@ while [ "$1" != "" ]; do shift continue ;; + --skip-ppa-launchpad ) SKIP_PPA_LAUNCHPAD=1 + shift + continue + ;; -u | --upgrade ) ENABLE_DEBUG && WELCOME_SCREEN && PREUPDATE_PREFLIGHT && MAINTENANCE && UPGRADE_TO_NEXT_RELEASE exit ;;