Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Improved update-repo for apt

I've updated my update-repo command for Debian-based distros, to display the available packages to update from the targetted repository. Also, I've adjusted the autocomplete to handle colons in the filenames, e.g., /etc/apt/sources.list.d/file:name.list. It will need to escape a colon with a slash, but accomplish what you want.

I updated this because my update-repo for rpm-based distros already shows the available updates.

# File: /usr/share/bgscripts/bashrc.d/debian.bashrc
# update-repo command for apt-get update just one repository
update-repo() {
   for source in "$@"; do
      sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}.list" \
         -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
      sudo apt-get -u upgrade -V --assume-no -o Dir::Etc::sourcelist="sources.list.d/${source}.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" | sed -n -r -e "/=>/s#^#${source}: #p;"
   done
}
# autocomplete for update-repo
_ppa_lists() {
   local cur
   _init_completion || return
   COMPREPLY=( $( find /etc/apt/sources.list.d/ -name "*${cur}*.list" \
      -exec basename {} \; 2>/dev/null | sed -r -e 's!\.list$!!;' -e 's/:/\\:/g;' 2>/dev/null ) )
   return 0
} &&
complete -F _ppa_lists update-repo

References

Weblinks

  1. package management - apt-get update only for a specific repository - Ask Ubuntu

Comments