deb-get icon indicating copy to clipboard operation
deb-get copied to clipboard

A more concise `apt update` on each package installation

Open Flashwalker opened this issue 1 year ago • 4 comments

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

Flashwalker avatar Aug 07 '22 21:08 Flashwalker

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.

github-actions[bot] avatar Aug 07 '22 21:08 github-actions[bot]

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
...

Flashwalker avatar Aug 08 '22 10:08 Flashwalker

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

natanjunges avatar Aug 08 '22 15:08 natanjunges

ok, maybe tomorow

Flashwalker avatar Aug 08 '22 18:08 Flashwalker