From e523164e8359f7129f743d4341215298a58ade70 Mon Sep 17 00:00:00 2001 From: theofficialgman <28281419+theofficialgman@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:27:24 -0500 Subject: [PATCH] api: update/correct `add_external_repo` and `rm_external_repo` to follow debian spec and pi-apps api use --- api | 62 ++++++++++++++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/api b/api index 222723d0b1a..7c5d3578319 100755 --- a/api +++ b/api @@ -369,15 +369,19 @@ app_to_pkgname() { #given an app-name, convert it to a unique, valid package-nam echo "pi-apps-$(echo "$app" | md5sum | cut -c1-8 | awk '{print $1}')" } -add_external_repo() { # add an external apt repo and its gpg key - repopath="$1" - reponame="$2" - pubkeyurl="$3" +add_external_repo() { # add an external apt repo and its gpg key. follows https://wiki.debian.org/DebianRepository/UseThirdParty specification + local repopath="$1" + local reponame="$2" + local suite="$3" + local component="$4" + local pubkeyurl="$5" # check if all needed vars are set - [ -z "$repopath" ] && error "add_external_packages: repopath not set" - [ -z "$reponame" ] && error "add_external_packages: reponame not set" - [ -z "$pubkeyurl" ] && error "add_external_packages: pubkeyurl not set" + [ -z "$repopath" ] && error "add_external_repo: repopath not set" + [ -z "$reponame" ] && error "add_external_repo: reponame not set" + [ -z "$suite" ] && error "add_external_repo: suite not set" + [ -z "$component" ] && error "add_external_repo: component not set" + [ -z "$pubkeyurl" ] && error "add_external_repo: pubkeyurl not set" # exit if reponame contains space, since apt doesn't accept .list files with spaces in filename or keyname. if [[ $reponame = *" "* ]]; then @@ -385,11 +389,11 @@ add_external_repo() { # add an external apt repo and its gpg key fi # check if links are valid - wget -q --spider "$pubkeyurl" || error "add_external_packages: pubkeyurl isn't a valid link" + wget -q --spider "$pubkeyurl" || error "add_external_repo: pubkeyurl isn't a valid link" - # make pi-apps key storage dir if it doesn't exist + # make apt keyring directory if it doesn't exist if [ ! -d /usr/share/keyrings ]; then - sudo mkdir -p /usr/share/keyrings || error "add_external_repo: failed to create pi-apps key storage dir." + sudo mkdir -p /usr/share/keyrings || error "add_external_repo: failed to create apt keyring directory." fi # check if .list file already exists @@ -398,32 +402,31 @@ add_external_repo() { # add an external apt repo and its gpg key fi # download gpg key from specified url - if [ -f /usr/share/keyrings/${reponame-keyring.gpg} ]; then - sudo rm -f /usr/share/keyrings/${reponame}-keyring.gpg + if [ -f /usr/share/keyrings/${reponame}-archive-keyring.gpg ]; then + sudo rm -f /usr/share/keyrings/${reponame}-archive-keyring.gpg fi - curl -fsSL "$pubkeyurl" | sudo gpg --dearmor -o /usr/share/keyrings/${reponame}-keyring.gpg + curl -fsSL "$pubkeyurl" | sudo gpg --dearmor -o /usr/share/keyrings/${reponame}-archive-keyring.gpg if [ $? != 0 ];then sudo rm -f /etc/apt/sources.list.d/${reponame}.list - sudo rm -f /usr/share/keyrings/${reponame}-keyring.gpg + sudo rm -f /usr/share/keyrings/${reponame}-archive-keyring.gpg error "add_external_repo: download from specified pubkeyurl failed." fi # create .list file - echo "deb $repopath" | sudo tee /etc/apt/sources.list.d/${reponame}.list >/dev/null + echo "deb [signed-by=/usr/share/keyrings/${reponame}-archive-keyring.gpg] $repopath $suite $component" | sudo tee /etc/apt/sources.list.d/${reponame}.list >/dev/null if [ $? != 0 ];then sudo rm -f /etc/apt/sources.list.d/${reponame}.list - sudo rm -f /usr/share/keyrings/${reponame}-keyring.gpg + sudo rm -f /usr/share/keyrings/${reponame}-archive-keyring.gpg error "add_external_repo: failed to create .list file" fi } rm_external_repo() { # remove an external apt repo and its gpg key, if the repo is no longer in use. (force-remove the repo with force argument) - # part of this function is modified from the`remove_repofile_if_unused` function. - reponame="$1" - force="$2" + local reponame="$1" + local force="$2" [ -z "$reponame" ] && error "rm_external_repo: reponame not provided" @@ -436,29 +439,12 @@ rm_external_repo() { # remove an external apt repo and its gpg key, if the repo [ -f "/etc/apt/sources.list.d/$reponame.list" ] || exit 0 if [ "$force" == force ]; then - rm -f /usr/share/keyrings/${reponame}-keyring.gpg || error "rm_external_repo: removal of ${reponame}-keyring.gpg failed" + rm -f /usr/share/keyrings/${reponame}-archive-keyring.gpg || error "rm_external_repo: removal of ${reponame}-archive-keyring.gpg failed" sudo rm -f /etc/apt/sources.list.d/${reponame}.list || error "rm_external_repo: removal of ${reponame}.list failed" exit 0 fi - # determine what repo-urls are in the file - local urls="$(cat "/etc/apt/sources.list.d/$reponame.list" | grep -v '^#' | tr ' ' '\n' | grep '://')" - - # there could be multiple urls in one file. Check each url and set the in_use variable to 1 if any packages are found - local IFS=$'\n' - local in_use=0 - local url - for url in $urls ; do - if anything_installed_from_repo "$url" >/dev/null; then - in_use=1 - break - fi - done - - if [ "$in_use" == 0 ]; then - status "Removing the $reponame repo as it is not being used" - sudo rm -f "/etc/apt/sources.list.d/$reponame.list" - fi + remove_repofile_if_unused /etc/apt/sources.list.d/${reponame}.list "" /usr/share/keyrings/${reponame}-archive-keyring.gpg } install_packages() { #Make some packages dependencies of the $app app. Package-names, regex, filenames, and urls are supported.