<commit_before>#!/usr/bin/env bash

koopa::apt_add_azure_cli_repo() { # {{{1
    # """
    # Add Microsoft Azure CLI apt repo.
    # @note Updated 2020-06-30.
    # """
    local file os_codename string url
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/azure-cli.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Microsoft Azure CLI repo at '${file}'."
    koopa::apt_add_microsoft_key
    os_codename="$(koopa::os_codename)"
    url='https://packages.microsoft.com/repos/azure-cli/'
    string="deb [arch=amd64] ${url} ${os_codename} main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_docker_key() { # {{{1
    # """
    # Add the Docker key.
    # @note Updated 2020-06-30.
    # """
    local key name url
    koopa::assert_has_no_args "$#"
    name='Docker'
    url="https://download.docker.com/linux/$(koopa::os_id)/gpg"
    key='<KEY>'
    koopa::apt_key_add "$name" "$url" "$key"
    return 0
}

koopa::apt_add_docker_repo() { # {{{1
    # """
    # Add Docker apt repo.
    # @note Updated 2020-06-30.
    #
    # Ubuntu 20 (Focal Fossa) not yet supported:
    # https://download.docker.com/linux/
    # """
    local file os_codename os_id string url
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/docker.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Docker repo at '${file}'."
    koopa::apt_add_docker_key
    os_id="$(koopa::os_id)"
    os_codename="$(koopa::os_codename)"
    # Remap 20.04 LTS to 19.10.
    case "$os_codename" in
        focal)
            os_codename='eoan'
            ;;
    esac
    url="https://download.docker.com/linux/${os_id}"
    string="deb [arch=amd64] ${url} ${os_codename} stable"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_google_cloud_key() { # {{{1
    # """
    # Add the Google Cloud key.
    # @note Updated 2020-08-17.
    # """
    local file url
    koopa::assert_has_no_args "$#"
    url='https://packages.cloud.google.com/apt/doc/apt-key.gpg'
    file='/usr/share/keyrings/cloud.google.gpg'
    [[ -e "$file" ]] && return 0
    koopa::info "Adding Google Cloud keyring at '${file}'."
    curl -fsSL "$url" \
        | sudo apt-key --keyring "$file" add - \
        >/dev/null 2>&1 \
        || true
    return 0
}

koopa::apt_add_google_cloud_sdk_repo() { # {{{1
    # """
    # Add Google Cloud SDK apt repo.
    # @note Updated 2020-07-05.
    # """
    local file string
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/google-cloud-sdk.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Google Cloud SDK repo at '${file}'."
    koopa::apt_add_google_cloud_key
    string="deb [signed-by=/usr/share/keyrings/cloud.google.gpg] \
https://packages.cloud.google.com/apt cloud-sdk main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_llvm_key() { # {{{1
    # """
    # Add the LLVM key.
    # @note Updated 2020-07-05.
    # """
    local key name url
    koopa::assert_has_no_args "$#"
    name='LLVM'
    url='https://apt.llvm.org/llvm-snapshot.gpg.key'
    key='<KEY>'
    koopa::apt_key_add "$name" "$url" "$key"
    return 0
}

koopa::apt_add_llvm_repo() { # {{{1
    # """
    # Add LLVM apt repo.
    # @note Updated 2020-07-05.
    # """
    local file os_codename string version
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/llvm.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding LLVM repo at '${file}'."
    koopa::apt_add_llvm_key
    os_codename="$(koopa::os_codename)"
    version="$(koopa::variable 'llvm')"
    version="$(koopa::major_version "$version")"
    string="deb http://apt.llvm.org/${os_codename}/ \
llvm-toolchain-${os_codename}-${version} main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_microsoft_key() {  #{{{1
    # """
    # Add the Microsoft Azure CLI key.
    # @note Updated 2020-08-17.
    # """
    local file url
    koopa::assert_has_no_args "$#"
    url='https://packages.microsoft.com/keys/microsoft.asc'
    file='/etc/apt/trusted.gpg.d/microsoft.asc.gpg'
    [[ -e "$file" ]] && return 0
    koopa::info "Adding Microsoft key at '${file}'."
    curl -fsSL "$url" \
        | gpg --dearmor \
        | sudo tee "$file" \
        >/dev/null 2>&1 \
        || true
    return 0
}

koopa::apt_add_r_key() { # {{{1
    # """
    # Add the R key.
    # @note Updated 2020-09-18.
    #
    # @seealso
    # - https://cran.r-project.org/bin/linux/debian/
    # - https://cran.r-project.org/bin/linux/ubuntu/
    # """
    local keys keyserver
    koopa::assert_has_no_args "$#"
    if koopa::is_ubuntu
    then
        # Release is signed by <NAME> <<EMAIL>>.
        keys=(
            '<KEY>'
        )
        keyserver='keyserver.ubuntu.com'
    else
        # Release is signed by <NAME> <<EMAIL>>.
        keys=(
            'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
            '<KEY>'
        )
        # > keyserver='keys.gnupg.net'
        keyserver='keyserver.ubuntu.com'
    fi
    koopa::apt_is_key_imported "$key" && return 0
    koopa::info 'Adding R key.'
    sudo apt-key adv \
        --keyserver "$keyserver" \
        --recv-keys "${keys[@]}" \
        >/dev/null 2>&1 \
        || true
    return 0
}

koopa::apt_add_r_repo() { # {{{1
    # """
    # Add R apt repo.
    # @note Updated 2020-07-05.
    # """
    local file os_codename os_id repo string version
    koopa::assert_has_args_le "$#" 1
    version="${1:-}"
    if [[ -z "$version" ]]
    then
        version="$(koopa::variable 'r')"<commit_msg>Enable import of multiple keys<commit_after>#!/usr/bin/env bash

koopa::apt_add_azure_cli_repo() { # {{{1
    # """
    # Add Microsoft Azure CLI apt repo.
    # @note Updated 2020-06-30.
    # """
    local file os_codename string url
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/azure-cli.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Microsoft Azure CLI repo at '${file}'."
    koopa::apt_add_microsoft_key
    os_codename="$(koopa::os_codename)"
    url='https://packages.microsoft.com/repos/azure-cli/'
    string="deb [arch=amd64] ${url} ${os_codename} main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_docker_key() { # {{{1
    # """
    # Add the Docker key.
    # @note Updated 2020-06-30.
    # """
    local key name url
    koopa::assert_has_no_args "$#"
    name='Docker'
    url="https://download.docker.com/linux/$(koopa::os_id)/gpg"
    key='<KEY>'
    koopa::apt_key_add "$name" "$url" "$key"
    return 0
}

koopa::apt_add_docker_repo() { # {{{1
    # """
    # Add Docker apt repo.
    # @note Updated 2020-06-30.
    #
    # Ubuntu 20 (Focal Fossa) not yet supported:
    # https://download.docker.com/linux/
    # """
    local file os_codename os_id string url
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/docker.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Docker repo at '${file}'."
    koopa::apt_add_docker_key
    os_id="$(koopa::os_id)"
    os_codename="$(koopa::os_codename)"
    # Remap 20.04 LTS to 19.10.
    case "$os_codename" in
        focal)
            os_codename='eoan'
            ;;
    esac
    url="https://download.docker.com/linux/${os_id}"
    string="deb [arch=amd64] ${url} ${os_codename} stable"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_google_cloud_key() { # {{{1
    # """
    # Add the Google Cloud key.
    # @note Updated 2020-08-17.
    # """
    local file url
    koopa::assert_has_no_args "$#"
    url='https://packages.cloud.google.com/apt/doc/apt-key.gpg'
    file='/usr/share/keyrings/cloud.google.gpg'
    [[ -e "$file" ]] && return 0
    koopa::info "Adding Google Cloud keyring at '${file}'."
    curl -fsSL "$url" \
        | sudo apt-key --keyring "$file" add - \
        >/dev/null 2>&1 \
        || true
    return 0
}

koopa::apt_add_google_cloud_sdk_repo() { # {{{1
    # """
    # Add Google Cloud SDK apt repo.
    # @note Updated 2020-07-05.
    # """
    local file string
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/google-cloud-sdk.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding Google Cloud SDK repo at '${file}'."
    koopa::apt_add_google_cloud_key
    string="deb [signed-by=/usr/share/keyrings/cloud.google.gpg] \
https://packages.cloud.google.com/apt cloud-sdk main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_llvm_key() { # {{{1
    # """
    # Add the LLVM key.
    # @note Updated 2020-07-05.
    # """
    local key name url
    koopa::assert_has_no_args "$#"
    name='LLVM'
    url='https://apt.llvm.org/llvm-snapshot.gpg.key'
    key='<KEY>'
    koopa::apt_key_add "$name" "$url" "$key"
    return 0
}

koopa::apt_add_llvm_repo() { # {{{1
    # """
    # Add LLVM apt repo.
    # @note Updated 2020-07-05.
    # """
    local file os_codename string version
    koopa::assert_has_no_args "$#"
    file='/etc/apt/sources.list.d/llvm.list'
    [[ -f "$file" ]] && return 0
    koopa::info "Adding LLVM repo at '${file}'."
    koopa::apt_add_llvm_key
    os_codename="$(koopa::os_codename)"
    version="$(koopa::variable 'llvm')"
    version="$(koopa::major_version "$version")"
    string="deb http://apt.llvm.org/${os_codename}/ \
llvm-toolchain-${os_codename}-${version} main"
    koopa::sudo_write_string "$string" "$file"
    return 0
}

koopa::apt_add_microsoft_key() {  #{{{1
    # """
    # Add the Microsoft Azure CLI key.
    # @note Updated 2020-08-17.
    # """
    local file url
    koopa::assert_has_no_args "$#"
    url='https://packages.microsoft.com/keys/microsoft.asc'
    file='/etc/apt/trusted.gpg.d/microsoft.asc.gpg'
    [[ -e "$file" ]] && return 0
    koopa::info "Adding Microsoft key at '${file}'."
    curl -fsSL "$url" \
        | gpg --dearmor \
        | sudo tee "$file" \
        >/dev/null 2>&1 \
        || true
    return 0
}

koopa::apt_add_r_key() { # {{{1
    # """
    # Add the R key.
    # @note Updated 2020-09-18.
    #
    # @seealso
    # - https://cran.r-project.org/bin/linux/debian/
    # - https://cran.r-project.org/bin/linux/ubuntu/
    # """
    local key keys keyserver
    koopa::assert_has_no_args "$#"
    if koopa::is_ubuntu
    then
        # Release is signed by <NAME> <<EMAIL>>.
        keys=(
            '<KEY>'
        )
        keyserver='keyserver.ubuntu.com'
    else
        # Release is signed by <NAME> <<EMAIL>>.
        keys=(
            'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
            '<KEY>'
        )
        # > keyserver='keys.gnupg.net'
        keyserver='keyserver.ubuntu.com'
    fi
    for key in "${keys[@]}"
    do
        koopa::apt_is_key_imported "$key" && continue
        koopa::info "Adding R key '${key}'."
        sudo apt-key adv \
            --keyserver "$keyserver" \
            --recv-key "${keys[@]}" \
            >/dev/null 2>&1 \
            || true
    done
    return 0
}

koopa::apt_add_r_repo() { # {{{1
    # """
    # Add R apt repo.
    # @note Updated 2020-07-05.
    # """
    local file os_codename os_id repo string version
    koopa::assert_has_args_le "$#" 1
    version="${1:-}"
    if [[ -z "$version" ]]
    then
        version="$(koopa::variable 'r')"
{'fraction_non_alphanumeric': 0.1768352076507571, 'fraction_numerical': 0.02718498184716196, 'mean_word_length': 2.47935921133703, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2540909', 'n_tokens_mistral': 4572, 'n_tokens_neox': 4148, 'n_words': 804}