sábado, 26 de outubro de 2019

How to recover packages to local cache - Ubuntu

A few days ago I had to "sudo apt clean" my local cache to uninstall a bad package, but I needed to recover my cache, with the installed packages, since I work often in offline places, so that I can recover from a broken system without an active Internet connection.

So to be able to recover, or better, rebuild (or re-cache) your packages to your local storage (ie HDD or SSD) that usually is located at: /var/cache/apt/archives  we have to do this:

1) get the installed package names:

dpkg -l | grep "^ii" | awk ' {print $2} ' > pkg_names.txt

2) get the installed package versions:

dpkg -l | grep "^ii" | awk ' {print $3} ' > pkg_version.txt

3) combine all package names and versions:

paste -d"=" pkg_names.txt pkg_version.txt > pkg_combine.txt

4) now download packages to cache:

cat pkg_combine.txt | xargs sudo apt-get -y install --reinstall --download-only

REF:

dpkg -l | grep "^ii"| awk ' {print $2} ' | xargs sudo apt-get -y install --reinstall --download-only

dpkg -s firefox | grep Version | awk ' {print $2} '

sudo apt-get install package=version

Todo:

Timeout each line to avoid long loops (when source is dead or pkg not available at repository)


Nenhum comentário:

Postar um comentário