Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

A more concise apt update on each package installation #428

Closed
Flashwalker opened this issue Aug 7, 2022 · 4 comments
Closed

A more concise apt update on each package installation #428

Flashwalker opened this issue Aug 7, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@Flashwalker
Copy link
Contributor

Requesting a new feature πŸ§‘β€πŸ’»

Call apt update for every package installation is really unnecessary traffic and time consumption.
i suggest to use these functions for more concise update the only specific ppa/repo:

updateppa() {
    ubver="$(lsb_release -cs)"
    array="$(for i in "${@}"; do echo "${i}" | sed -r 's#(ppa):((\w|[[:digit:]]|-|_|\.)+?)/((\w|[[:digit:]]|-)+?)#\2-ubuntu-\4-'$ubver'#g; s#\.#_#g'; done)"
    echo "${array[@]}" | while read source; do
        echo -e Upating: "\e[0;34m/etc/apt/sources.list.d/${source}.list\e[0m"
        sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}.list" \
        -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"    
    done
}
updaterepo() {
    for source in "${@}"; do
        echo -e Upating: "\e[0;34m/etc/apt/sources.list.d/${source}.list\e[0m"
        sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}.list" \
            -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
    done
}

Call them like this:

for the ppa pattern ppa:audio-recorder/ppa:

updateppa ppa:audio-recorder/ppa

for the .list file /etc/apt/sources.list.d/audio-recorder-ubuntu-ppa-jammy.list:

updaterepo audio-recorder-ubuntu-ppa-jammy
@github-actions
Copy link

github-actions bot commented Aug 7, 2022

Hello there πŸ‘‹
Thanks for submitting your first issue to the deb-get project πŸ› We'll try and take a look at your issue soon ⏲

In the meantime you might want to join the Wimpys World Discord πŸ—£ where we have a large community of Linux 🐧 enthusiasts and passionate open source developers πŸ§‘β€πŸ’»

You might also be interested in following Wimpys World Twitch πŸ“‘ channel where Wimpy streams let's code video, including this project, several times a week. A back catalog of past live stream and other Linux related content is available on Wimpys World YouTube πŸ“Ί channel.

@Flashwalker
Copy link
Contributor Author

in case of deb-get it should be:

function update_apt() {
    ${ELEVATE} apt-get -q -o Dpkg::Progress-Fancy="1" -y update
}

function upgrade_apt() {
    ${ELEVATE} apt-get -q -o Dpkg::Progress-Fancy="1" -y upgrade
}
+
+update_repo() {
+   for source in "${@}"; do
+       echo -e Upating: "\e[0;34m/etc/apt/sources.list.d/${source}.list\e[0m"
+       sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}.list" \
+           -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
+   done
+}
+
+update_ppa() {
+   ubver="$(lsb_release -cs)"
+   array="$(for i in "${@}"; do echo "${i}" | sed -r 's#(ppa):((\w|[[:digit:]]|-|_|\.)+?)/((\w|[[:digit:]]|-)+?)#\2-ubuntu-\4-'$ubver'#g; s#\.#_#g'; done)"
+   echo "${array[@]}" | while read source; do
+       echo -e Upating: "\e[0;34m/etc/apt/sources.list.d/${source}.list\e[0m"
+       sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}.list" \
+       -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"    
+   done
+}
...
function install_apt() {
    let "PACKAGE_INSTALLATION_TRIES+=1"
    if [ -n "${APT_KEY_URL}" ]; then
        ${ELEVATE} wget -q "${APT_KEY_URL}" -O "/etc/apt/trusted.gpg.d/${APT_LIST_NAME}.asc"
    fi

    if [ -n "${GPG_KEY_URL}" ]; then
        if [ ! -d /usr/share/keyrings ]; then
            ${ELEVATE} mkdir -p /usr/share/keyrings 2>/dev/null
        fi
        ${ELEVATE} wget -q "${GPG_KEY_URL}" -O "/usr/share/keyrings/${APT_LIST_NAME}-archive-keyring.gpg"
    fi

    #TODO: https://superuser.com/questions/1641291/gpg-only-download-a-key-from-a-keyserver

    echo -e "${APT_REPO_URL}" | ${ELEVATE} tee "/etc/apt/sources.list.d/${APT_LIST_NAME}.list"
-   update_apt
+   update_repo "${APT_LIST_NAME}"
...
...
function install_ppa() {
    let "PACKAGE_INSTALLATION_TRIES+=1"
    local AAR_PARAMS="-y"
    if [ "$(dpkg -S "$(command -v apt-add-repository)" | cut -d':' -f1)" == "software-properties-common" ]; then
        AAR_PARAMS+=" --no-update"
    fi
    if ${ELEVATE} apt-add-repository ${AAR_PARAMS} "${PPA}"; then
-       update_apt
+       update_ppa "${PPA}"
        if ! package_is_installed "${APP}"; then
...

@natanjunges
Copy link
Contributor

This looks very promising. Can you open a Pull Request?

@Flashwalker
Copy link
Contributor Author

ok, maybe tomorow

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants