You are not logged in.

#1 2018-06-13 16:26:18

ar124official
Member
From: Pakistan
Registered: 2018-06-13
Posts: 5
Website

Updating packages saved in cache but not installed

Is there any way to upgrade packages uninstalled but kept in pacman cache directory. So when reinstalling, it would not require to download new packages.


Linux is simple, Arch Linux is simplest

Offline

#2 2018-06-13 16:34:16

Haller
Member
Registered: 2018-04-08
Posts: 23

Re: Updating packages saved in cache but not installed

To avoid downloading you could copy /var/cache/pacman/pkg.

Offline

#3 2018-06-13 16:42:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,332
Website

Re: Updating packages saved in cache but not installed

The question is ambiguously phrased.  You cannot upgrade something that isn't even installed.  Are you asking if there is a way you can reinstall a package you previously had removed that is still in your cache?  If so, certainly:

pacman -U /path/to/cached/package.pkg.tar.xz

Of course the following will do the same in most cases:

pacman -S package

The only time that this would not do the same thing is if there was a newer version of 'package' in the repos that is in your package cache - in such cases, you'd really not want to reinstall the one from your cache anyways (as that'd be equivalent to a downgrade/partial-upgrade).

EDIT: oops, I just reread your question and now I understand it differently.  If you just want to keep up to date versions of some packages in your cache without needing to install them, that's also possible with the 'w' flag for pacman.  I'm curious though why you would want this option.  How many packages do you intend to do this with, and why?

Last edited by Trilby (2018-06-13 16:44:27)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2018-06-13 17:06:54

ar124official
Member
From: Pakistan
Registered: 2018-06-13
Posts: 5
Website

Re: Updating packages saved in cache but not installed

Trilby wrote:

The question is ambiguously phrased.  You cannot upgrade something that isn't even installed.  Are you asking if there is a way you can reinstall a package you previously had removed that is still in your cache?  If so, certainly:

pacman -U /path/to/cached/package.pkg.tar.xz

Of course the following will do the same in most cases:

pacman -S package

The only time that this would not do the same thing is if there was a newer version of 'package' in the repos that is in your package cache - in such cases, you'd really not want to reinstall the one from your cache anyways (as that'd be equivalent to a downgrade/partial-upgrade).

EDIT: oops, I just reread your question and now I understand it differently.  If you just want to keep up to date versions of some packages in your cache without needing to install them, that's also possible with the 'w' flag for pacman.  I'm curious though why you would want this option.  How many packages do you intend to do this with, and why?

Thanks for respone. I would like to clear that i asked about If there any way to update packages which were previously installed using pacman but then uninstalled. That mean they are still in cache but they are not currently installed. Can I upgrade them using pacman, even when not installed, so I would not need to download them when I next time install. As normal, pacman checks repos first then looks in cache and if the latest version is't in cache, it would download latest version.


Linux is simple, Arch Linux is simplest

Offline

#5 2018-06-13 17:14:32

parsingelf
Member
From: United Kingdom
Registered: 2018-05-31
Posts: 1

Re: Updating packages saved in cache but not installed

We understood the question as of ar124official use the first command

Offline

#6 2018-06-13 21:55:57

Allan
Supreme Leader
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,725
Website

Re: Updating packages saved in cache but not installed

$(ls /var/cache pacman | some parsing stuff) | pacman -Sw -

Offline

#7 2018-06-13 22:15:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,332
Website

Re: Updating packages saved in cache but not installed

I think Allan is drunk posting: replacing a / with a " " in the path, leaving of the last element of the path, enclosing two parts of a pipeline in $() for no reason (and neglecting the "echo" or similar that would be required in order to do so ...

I want some of what he's having.

ls /var/cache/pacman/pkg/ | awk -F- '{ printf $1; for (i = 2; i < NF - 2; i++) printf "-%s", $i; printf "\n"; }' | pacman -Sw

Just don't tell Eschwartz I did that.  You could use find instead of ls if you either have gnu find or can do even more parsing in the middle of the pipeline.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2018-06-13 22:25:34

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,334
Website

Re: Updating packages saved in cache but not installed

Allan wrote:

$(ls /var/cache pacman | some parsing stuff) | pacman -Sw -

e.g.

ls /var/cache/pacman/pkg/*.pkg.* | sed 's@^.*/\(.\+\)\(-[^-]\+\)\{3\}$@\1@' | uniq | pacman -Sw -

Explanation:

  • ls /var/cache/pacman/pkg/*.pkg.*: List all existing packages in the cache.

  • sed 's@^.*/\(.\+\)\(-[^-]\+\)\{3\}$@\1@': strip the parent directories and everything after the third-to-last hyphen, which precedes the version.

  • uniq: remove duplicates due to multiple versions of the same package (the versions are stripped in the previous command).

  • pacman -Sw -: Download all packages passed via the pipe to the cache directory.

If you want to use a separate cache directory for these packages, you can change /var/cache/pacman/pkg to another path and add --cachedir <path> to the pacman command, where <path> is the other path.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#9 2018-06-13 22:33:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,332
Website

Re: Updating packages saved in cache but not installed

There's no need for uniq, pacman will ignore the duplicates anyways.  But if you are stripping paths in the second step anyways, then you should definitely use find.  Find to awk:

find /var/cache/pacman/pkg/ -name '*pkg.tar.xz' | awk -F[/-] '{ printf $6; for (i = 7; i < NF - 2; i++) printf "-%s", $i; printf "\n"; }' | pacman -Sw

Last edited by Trilby (2018-06-13 22:37:46)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2018-06-13 22:46:47

Allan
Supreme Leader
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,725
Website

Re: Updating packages saved in cache but not installed

Trilby wrote:

I think Allan is drunk posting: replacing a / with a " " in the path, leaving of the last element of the path, enclosing two parts of a pipeline in $() for no reason (and neglecting the "echo" or similar that would be required in order to do so ...

It was 8am...  and I decided to use the pipe into pacman rather than $() the arguments but forgot to remove stuff.

Offline

#11 2018-06-13 22:52:35

progandy
Member
Registered: 2012-05-17
Posts: 2,883

Re: Updating packages saved in cache but not installed

Why use so many tools when bash is perfectly capable to do the job with builtin commands big_smile

(cd /var/cache/pacman/pkg; prev=""; for pkg in *; do pkg="${pkg%-*-*-*}"; [[ $pkg = $prev ]] || echo -E "$pkg" ; prev="$pkg"; done) | pacman -Sw -

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#12 2018-06-13 22:54:35

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 25,056
Website

Re: Updating packages saved in cache but not installed

Allan wrote:
Trilby wrote:

I think Allan is drunk posting...

It was 8am...

Doesn't read like a denial to me. tongue


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#13 2018-06-13 23:34:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,332
Website

Re: Updating packages saved in cache but not installed

Progandy, despite using just builtins, the for loop is over 20 times slower than the pipeline here.

EDIT: I had to double check that it wasn't this thread that I recently argued against needless pipeline elements being a resource drain (subshells, new processes) - when I did, I almost included a note that pipelines are great, but should be avoided when practical, like for loops are great but should be avoided sometimes when it's not even practical.

There is a reason the symbol for infinity is just two loops.

Last edited by Trilby (2018-06-13 23:37:40)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2018-06-14 00:54:28

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,334
Website

Re: Updating packages saved in cache but not installed

Trilby wrote:

But if you are stripping paths in the second step anyways, then you should definitely use find.

Why? ls will preserve the path of the glob pattern so the same strings are piped in both cases.

There's a "-" missing after -Sw in that pacman command btw.

More fun with find and awk:

find /var/cache/pacman/pkg/ -name '*.pkg.*' -printf '%P\n' | awk -F- 'sub(FS $(NF-2) FS $(NF-1) FS $NF,x)' | pacman -Sw -

ls and awk:

pushd /var/cache/pacman/pkg/; ls  *.pkg.* | awk -F- 'sub(FS $(NF-2) FS $(NF-1) FS $NF,x)' | pacman -Sw -; popd

find and sed:

find /var/cache/pacman/pkg/ -name '*.pkg.*' -printf '%P\n' | sed 's@\(-[^-]*\)\{3\}$@@' | pacman -Sw

ls and sed:

pushd /var/cache/pacman/pkg/; ls  *.pkg.* | sed 's@\(-[^-]*\)\{3\}$@@' | pacman -Sw -; popd

using bash built-ins

(cd /var/cache/pacman/pkg; for x in *.pkg.*;do printf '%q\n' "${x%-*-*-*}"; done) | pacman -Sw -

with echo instead of print and no pipe to make it shorter:

pacman -Sw $(cd /var/cache/pacman/pkg; for x in *.pkg.*;do echo ${x%-*-*-*}; done)

without loops or external commands

(cd /var/cache/pacman/pkg;x=(*.pkg.*);pacman -Sw "${x[@]%-*-*-*}")

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#15 2018-06-14 02:09:57

Eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 1,960

Re: Updating packages saved in cache but not installed

For loops are slow.

pushd /var/cache/pacman/pkg
pkgs=(*.pkg.tar.xz)
pacman -Sw "${pkgs[@]%-*-*-*}"
popd

Bonus points using find just because:

mapfile -td '' pkgs < <(find /var/cache/pacman/pkg/ -name '*.pkg.tar.xz' -printf '%P\0')
pacman -Sw "${pkgs[@]%-*-*-*}"

Last edited by Eschwartz (2018-06-14 02:10:52)

Offline

#16 2018-06-14 17:47:37

ar124official
Member
From: Pakistan
Registered: 2018-06-13
Posts: 5
Website

Re: Updating packages saved in cache but not installed

OMG, Arch community is very responsive. Thanks Archy Brothers. But I could not understood  machanism very well. Infact I'm not familiar with commands like awk. At all I got to point of using -Sw , and I am sure that after a few days I would be able to understand it well as I am currently learning bash and other Command Line utilities like (g)awk and grep. After getting a touch with them I'm sure I would do.

Last edited by ar124official (2018-06-14 17:51:00)


Linux is simple, Arch Linux is simplest

Offline

#17 2018-06-14 17:49:44

ar124official
Member
From: Pakistan
Registered: 2018-06-13
Posts: 5
Website

Re: Updating packages saved in cache but not installed

I started using Arch Linux for the sake of Linux learning, and It is well forcing me to do so.


Linux is simple, Arch Linux is simplest

Offline

#18 2018-06-14 18:41:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 19,332
Website

Re: Updating packages saved in cache but not installed

If there is a predetermined list of packages you want kept up to date in your cache, then there is no need for awk or any of the other craziness above.  Just maintain that list of package names in a file and periodically run:

pacman -Sw - < /path/to/package_list.txt

All the awk and related scripting in the thread was just to generate a list of package names from what is in the cache (as filenames in the cache include pkgver, pkgrel, arch, and filetype suffixes).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#19 2018-06-15 08:29:08

ar124official
Member
From: Pakistan
Registered: 2018-06-13
Posts: 5
Website

Re: Updating packages saved in cache but not installed

Trilby wrote:

If there is a predetermined list of packages you want kept up to date in your cache, then there is no need for awk or any of the other craziness above.  Just maintain that list of package names in a file and periodically run:

pacman -Sw - < /path/to/package_list.txt

All the awk and related scripting in the thread was just to generate a list of package names from what is in the cache (as filenames in the cache include pkgver, pkgrel, arch, and filetype suffixes).

Trilby, you have advised a better solution. Now I've got idea to write a script to record name of package before asking pacman to install and another which pass these records to  pacman with -Sw same as you stated. I'm happy with this solution.

Last edited by ar124official (2018-06-15 08:32:05)


Linux is simple, Arch Linux is simplest

Offline

#20 2018-06-15 08:44:50

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 25,056
Website

Re: Updating packages saved in cache but not installed

Please remember to mark your thread as [Solved] by editing your first post and prepending it to the title.


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB