From 261b157c8cb47ac6f88164bb2e24350d368b337d Mon Sep 17 00:00:00 2001
From: theofficialgman <28281419+theofficialgman@users.noreply.github.com>
Date: Sun, 31 Dec 2023 17:03:16 -0500
Subject: [PATCH] Box86 and Box64: switch to `add_external_repo` and
 `rm_external_repo`

---
 apps/Box64/install-64 | 17 +++++------------
 apps/Box64/uninstall  |  5 +++--
 apps/Box86/install-32 | 17 +++++------------
 apps/Box86/install-64 | 17 +++++------------
 apps/Box86/uninstall  |  5 +++--
 5 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/apps/Box64/install-64 b/apps/Box64/install-64
index 2f140311eb2..9e376cb5354 100755
--- a/apps/Box64/install-64
+++ b/apps/Box64/install-64
@@ -4,19 +4,12 @@ if dpkg -l box64 &>/dev/null ;then
   sudo apt purge -y --allow-change-held-packages box64*
 fi
 
-sudo wget https://pi-apps-coders.github.io/box64-debs/box64.list -O /etc/apt/sources.list.d/box64.list
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box64.list
-  error "Failed to add box64.list file!"
-fi
-
-sudo rm -f /usr/share/keyrings/box64-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg
-sudo mkdir -p /etc/apt/trusted.gpg.d
-wget -qO- https://pi-apps-coders.github.io/box64-debs/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg > /dev/null
+add_external_repo "box64" "https://Pi-Apps-Coders.github.io/box64-debs/debian ./" "https://pi-apps-coders.github.io/box64-debs/KEY.gpg" || exit 1
 
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box64.list
-  error "Failed to add KEY.gpg to APT keyring!"
+apt_update
+if [ $? != 0 ]; then
+  rm_external_repo "box64"
+  error "Failed to perform apt update after adding box64 repository."
 fi
 
 # obtain SOC_ID
diff --git a/apps/Box64/uninstall b/apps/Box64/uninstall
index baab8631c0c..f32fe595282 100755
--- a/apps/Box64/uninstall
+++ b/apps/Box64/uninstall
@@ -1,6 +1,7 @@
 #!/bin/bash
 purge_packages || exit 1
 
-sudo rm -f /etc/apt/sources.list.d/box64.list || error "Failed to remove repo!"
+# remove deprecated key locations
+sudo rm -f /usr/share/keyrings/box64-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg
 
-sudo rm -f /usr/share/keyrings/box64-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg || error "Failed to remove GPG key!"
+rm_external_repo "box64"
diff --git a/apps/Box86/install-32 b/apps/Box86/install-32
index f4fdfbc40ad..a61df6bb38e 100755
--- a/apps/Box86/install-32
+++ b/apps/Box86/install-32
@@ -9,19 +9,12 @@ if dpkg -l box86 &>/dev/null ;then
   sudo apt purge -y --allow-change-held-packages box86*
 fi
 
-sudo wget https://pi-apps-coders.github.io/box86-debs/box86.list -O /etc/apt/sources.list.d/box86.list
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box86.list
-  error "Failed to add box86.list file!"
-fi
-
-sudo rm -f /usr/share/keyrings/box86-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg
-sudo mkdir -p /etc/apt/trusted.gpg.d
-wget -qO- https://pi-apps-coders.github.io/box86-debs/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg > /dev/null
+add_external_repo "box86" "https://Pi-Apps-Coders.github.io/box86-debs/debian ./" "https://pi-apps-coders.github.io/box86-debs/KEY.gpg" || exit 1
 
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box86.list
-  error "Failed to add KEY.gpg to APT keyring!"
+apt_update
+if [ $? != 0 ]; then
+  rm_external_repo "box86"
+  error "Failed to perform apt update after adding box86 repository."
 fi
 
 # obtain SOC_ID
diff --git a/apps/Box86/install-64 b/apps/Box86/install-64
index a5fb58b7bb2..2cedbc091ac 100755
--- a/apps/Box86/install-64
+++ b/apps/Box86/install-64
@@ -80,19 +80,12 @@ install_packages libc6:armhf libstdc++6:armhf \
   libgssapi-krb5-2:armhf libkrb5-3:armhf \
   $rpi_arm_userspace $mesa_va_drivers libegl1:armhf libglx-mesa0:armhf libgl1:armhf libgles2:armhf
 
-sudo wget https://pi-apps-coders.github.io/box86-debs/box86.list -O /etc/apt/sources.list.d/box86.list
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box86.list
-  error "Failed to add box86.list file!"
-fi
-
-sudo rm -f /usr/share/keyrings/box86-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg
-sudo mkdir -p /etc/apt/trusted.gpg.d
-wget -qO- https://pi-apps-coders.github.io/box86-debs/KEY.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg > /dev/null
+add_external_repo "box86" "https://Pi-Apps-Coders.github.io/box86-debs/debian ./" "https://pi-apps-coders.github.io/box86-debs/KEY.gpg" || exit 1
 
-if [ $? != 0 ];then
-  sudo rm -f /etc/apt/sources.list.d/box86.list
-  error "Failed to add KEY.gpg to APT keyring!"
+apt_update
+if [ $? != 0 ]; then
+  rm_external_repo "box86"
+  error "Failed to perform apt update after adding box86 repository."
 fi
 
 # obtain SOC_ID
diff --git a/apps/Box86/uninstall b/apps/Box86/uninstall
index 7e90e7cc556..6f87376498a 100755
--- a/apps/Box86/uninstall
+++ b/apps/Box86/uninstall
@@ -9,9 +9,10 @@ function check-armhf() {
 
 purge_packages || exit 1
 
-sudo rm -f /etc/apt/sources.list.d/box86.list || error "Failed to remove repo!"
+# remove deprecated key locations
+sudo rm -f /usr/share/keyrings/box86-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg
 
-sudo rm -f /usr/share/keyrings/box86-debs-archive-keyring.gpg /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg || error "Failed to remove GPG key!"
+rm_external_repo "box86"
 
 if [ "$arch" == 64 ]; then
   # remove armhf architecture if no packages from it are currently installed