From 0952537397a732d4ea639e85a25505c886800f38 Mon Sep 17 00:00:00 2001 From: theofficialgman <28281419+theofficialgman@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:25:41 -0400 Subject: [PATCH] api: optimize `is_supported_system`, correctly filter only `deb`, and add Ubuntu sources.list requirements --- api | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/api b/api index 4562dfdd72..f0243368b9 100755 --- a/api +++ b/api @@ -650,7 +650,7 @@ ubuntu_ppa_installer() { #setup a PPA on an Ubuntu distro. Arguments: ppa_name [ -z "$1" ] && error "ubuntu_ppa_installer(): This function is used to add a ppa to a ubuntu based install but a required input argument was missing." local ppa_grep="$ppa_name" [[ "${ppa_name}" != */ ]] && local ppa_grep="${ppa_name}/" - local ppa_added=$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE)' | sort -u | awk 'NF==2 {print}' | grep "$ppa_grep" | wc -l) + local ppa_added=$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE) $(TARGET_OF)' | sort -u | awk '{if ($3=="deb") print $1" "$2 }' | grep "$ppa_grep" | wc -l) if [[ $ppa_added -eq "1" ]]; then status "Skipping $ppa_name PPA, already added" else @@ -678,7 +678,7 @@ debian_ppa_installer() { #setup a PPA on a Debian distro. Arguments: ppa_name di [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] && error "debian_ppa_installer(): This function is used to add a ppa to a debian based install but a required input argument was missing." local ppa_grep="$ppa_name" [[ "${ppa_name}" != */ ]] && local ppa_grep="${ppa_name}/ubuntu ${ppa_dist}" - local ppa_added=$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE)' | sort -u | awk 'NF==2 {print}' | grep "$ppa_grep" | wc -l) + local ppa_added=$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE) $(TARGET_OF)' | sort -u | awk '{if ($3=="deb") print $1" "$2 }' | grep "$ppa_grep" | wc -l) if [[ $ppa_added -eq "1" ]]; then status "Skipping $ppa_name PPA, already added" else @@ -2523,6 +2523,12 @@ files_match() { #$1 and $2 are paths to files is_supported_system() { #return 0 if system is supported, otherwise return 1 PRETTY_NAME="$(cat /etc/os-release | grep PRETTY_NAME | tr -d '"' | awk -F= '{print $2}')" + local DEFAULT_REPOS="$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE) $(TARGET_OF)' | sort -u | awk '{if ($3=="deb") print $1" "$2 }' | grep "raspbian.raspberrypi.org/raspbian\|archive.raspberrypi.org/debian\|\ +debian.org/debian\|security.debian.org/\|\ +ports.ubuntu.com\|esm.ubuntu.com/apps/ubuntu\|esm.ubuntu.com/infra/ubuntu\|\ +repo.huaweicloud.com/debian\|repo.huaweicloud.com/ubuntu-ports\|\ +apt.pop-os.org\|\ +apt.armbian.com")" if uname -m | grep -qi 'x86\|i686\|i386'; then echo "Pi-Apps is not supported on x86 processors. Nearly all apps will fail. Consider switching to this x86 port of Pi-Apps: https://github.com/MCRaspRBX/pi-apps-x86" return 1 @@ -2547,12 +2553,7 @@ is_supported_system() { #return 0 if system is supported, otherwise return 1 elif [ "$(id -u)" == 0 ]; then echo "Pi-Apps is not designed to be run as root user." return 1 - elif local frankendebian="$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE)' | sort -u | awk 'NF==2 {print}' | grep "raspbian.raspberrypi.org/raspbian\|archive.raspberrypi.org/debian\|\ -debian.org/debian\|security.debian.org/\|\ -ports.ubuntu.com\|esm.ubuntu.com/apps/ubuntu\|esm.ubuntu.com/infra/ubuntu\|\ -repo.huaweicloud.com/debian\|repo.huaweicloud.com/ubuntu-ports\|\ -apt.pop-os.org\|\ -apt.armbian.com" | grep -v $__os_codename)" && [ ! -z "$frankendebian" ];then + elif local frankendebian="$(echo "$DEFAULT_REPOS" | grep -v $__os_codename)" && [ ! -z "$frankendebian" ];then echo "Congratulations, Linux tinkerer, you broke your system. You have made your system a FrankenDebian. This website explains your mistake in more detail: https://wiki.debian.org/DontBreakDebian Your current reported release (${__os_codename^}) should not be combined with other releases. @@ -2569,10 +2570,17 @@ Specifically, the issue is $(wc -l <<<"$frankendebian" | grep -q 1 && echo 'this echo "Congratulations, Linux tinkerer, you broke your system. The init package can not be found, which means you have removed the default debian sources from your system. All apt based application installs will fail. Unless you have a backup of your /etc/apt/sources.list /etc/apt/sources.list.d you will need to reinstall your OS." return 1 - elif [ -z "$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE)' | sort -u | awk 'NF==2 {print}')" ];then + elif [ -z "$(apt-get indextargets --no-release-info --format '$(SITE) $(RELEASE) $(TARGET_OF)' | sort -u | awk '{if ($3=="deb") print $1" "$2 }')" ];then echo "Congratulations, Linux tinkerer, you broke your system. You have removed ALL debian sources from your system. All apt based application installs will fail. Unless you have a backup of your /etc/apt/sources.list /etc/apt/sources.list.d you will need to reinstall your OS." return 1 + elif [ "$__os_id" == "Ubuntu" ] && ! ( echo "$DEFAULT_REPOS" | grep -q $__os_codename && \ + echo "$DEFAULT_REPOS" | grep -q $__os_codename-updates && \ + echo "$DEFAULT_REPOS" | grep -q $__os_codename-security ); then + echo "MISSING Default Ubuntu Repositories! +Pi-Apps does NOT support systems without ALL of $__os_codename, $__os_codename-updates, and $__os_codename-security dists present in the sources.list +Please refer to the default sources.list for Ubuntu and restore all required dists." + return 1 elif [ "$(df -a / -B 1 --output=avail | tail -1 | tr -d ' ')" -lt $((500*1024*1024)) ];then echo "Your system drive has less than 500MB of free space. Watch out for "\""disk full"\"" errors." return 1