From 6db82650b3a1eb03fd4083f6125e5563e283c85e Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Fri, 8 Mar 2024 12:52:30 +0000 Subject: [PATCH] fix: add support for deb822 sources format Signed-off-by: Jakub Panek --- src/xx-apt | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/xx-apt b/src/xx-apt index bac13bb..0fc79ff 100755 --- a/src/xx-apt +++ b/src/xx-apt @@ -31,6 +31,11 @@ aptsourcesfile() { fi } +check_deb822() { + # shellcheck disable=SC2046 + [ "$(printf '%s' $(aptsourcesfile) | awk -F . '{if (NF>1) {print $NF}}')" = "sources" ] && return 0 || return 1 +} + exitnolinux() { if [ "${TARGETOS}" != "linux" ]; then echo >&2 "skipping packages installation on ${XX_OS}" @@ -88,13 +93,21 @@ fi fixubuntusources() { # fix all current sources to native arch nativearch="$(TARGETPLATFORM="" TARGETPAIR="" TARGETARCH="" TARGETOS="" xx-info arch)" - sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i "$(aptsourcesfile)" + if ! check_deb822; then + sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i "$(aptsourcesfile)" + else + sed -E "/Architectures:/! s/^(Types\: [a-z]+)/\1\nArchitectures: $nativearch/" -i "$(aptsourcesfile)" + fi if ! xx-info is-cross; then return; fi # add custom list for target debarch=$(xx-info debian-arch) - targetlist=/etc/apt/sources.list.d/xx-$debarch.list + if ! check_deb822; then + targetlist=/etc/apt/sources.list.d/xx-$debarch.list + else + targetlist=/etc/apt/sources.list.d/xx-$debarch.sources + fi if [ -f "$targetlist" ]; then return; fi mainurl=archive.ubuntu.com/ubuntu @@ -109,12 +122,30 @@ fixubuntusources() { # shellcheck disable=SC1091 ubuntuname=$(. /etc/os-release && echo "$UBUNTU_CODENAME") - cat <"$targetlist" + if ! check_deb822; then + cat <"$targetlist" deb [arch=$debarch] http://$mainurl/ $ubuntuname main restricted universe multiverse deb [arch=$debarch] http://$mainurl/ $ubuntuname-updates main restricted universe multiverse deb [arch=$debarch] http://$mainurl/ $ubuntuname-backports main restricted universe multiverse deb [arch=$debarch] http://$securityurl/ $ubuntuname-security main restricted universe multiverse eot + else + cat <"$targetlist" +Types: deb +Architectures: $debarch +URIs: http://$mainurl/ +Suites: $ubuntuname $ubuntuname-updates $ubuntuname-backports +Components: main universe restricted multiverse +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg + +Types: deb +Architectures: $debarch +URIs: http://$securityurl/ +Suites: $ubuntuname-security +Components: main universe restricted multiverse +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg +eot + fi } packages=