From bb25c6b15db5802a2f592a3b07955a4e6166e845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 9 Jul 2024 23:46:07 +0200 Subject: [PATCH] Fix: support repositories without component --- helpers/helpers.v1.d/apt | 20 +++++++++++--------- helpers/helpers.v2.1.d/apt | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/helpers/helpers.v1.d/apt b/helpers/helpers.v1.d/apt index c3fd9aa07..34d933018 100644 --- a/helpers/helpers.v1.d/apt +++ b/helpers/helpers.v1.d/apt @@ -469,18 +469,20 @@ ynh_install_extra_repo() { wget_append="tee" fi - # Split the repository into uri, suite and components. + IFS=', ' read -r -a repo_parts <<< "$repo" + index=0 + # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" + if [[ "${repo_parts[0]}" == "deb" ]]; then + index=1 + fi + uri="${repo_parts[$index]}" ; index=$((index+1)) + suite="${repo_parts[$index]}" ; index=$((index+1)) # Get the components - local component="${repo##$uri $suite }" + if (( "${#repo_parts[@]}" > 0 )); then + component="${repo_parts[*]:$index}" + fi # Add the repository into sources.list.d ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append diff --git a/helpers/helpers.v2.1.d/apt b/helpers/helpers.v2.1.d/apt index 3930f5e9c..3b875f0fe 100644 --- a/helpers/helpers.v2.1.d/apt +++ b/helpers/helpers.v2.1.d/apt @@ -196,10 +196,20 @@ ynh_apt_install_dependencies_from_extra_repository() { # =========================================== # Split the repository into uri, suite and components. - repo="${repo#deb }" - local uri="$(echo "$repo" | awk '{ print $1 }')" - local suite="$(echo "$repo" | awk '{ print $2 }')" - local component="${repo##$uri $suite }" + IFS=', ' read -r -a repo_parts <<< "$repo" + index=0 + + # Remove "deb " at the beginning of the repo. + if [[ "${repo_parts[0]}" == "deb" ]]; then + index=1 + fi + uri="${repo_parts[$index]}" ; index=$((index+1)) + suite="${repo_parts[$index]}" ; index=$((index+1)) + + # Get the components + if (( "${#repo_parts[@]}" > 0 )); then + component="${repo_parts[*]:$index}" + fi # Add the new repo in sources.list.d mkdir --parents "/etc/apt/sources.list.d"