Francesco Pretto <[email protected]> writes:

> Hi all, newbie here.
>
> What I'm trying to accomplish is offline updating packages lists in
> /var/lib/apt/lists. As far as I know, there's no supported way of
> doing this with apt tools, so I'm trying to do so with a bash script.
> Assuming that no synaptic, aptitude, apt-get, etc. process is running,
> doing the following will just works (assuming you have saved
> /var/lib/apt/lists folder in lists.tar.bz2):
>
> rm -r /var/lib/apt/lists
> tar xvjpf lists.tar.bz2 -C /var/lib/apt
>
> I realize this is ugly and unsafe, so I'd like to write the same in a
> cleaner way, taking the lock on /var/lib/apt/lists/lock first,
> similarly to what apt-get update and other tools do. Surprisingly, it
> wasn't so easy as I tough, and the following bash script doesn't work
> as I expected:
>
> --------------------------------------
> #!/bin/bash
> set -e
> (
>     flock --exclusive --nonblock 200
>     # do something inside /var/lib/apt/lists
>     sleep 50 # Taking some time to test if the lock works
> ) 200>/var/lib/apt/lists/lock
> --------------------------------------
>
> It doesn't work in the sense that trying to launch apt-get update
> during the sleep time will simply works, like no lock was set. What am
> I doing wrong?
>
> I hope apt-get is not actually checking which process is taking the
> lock and failing just if the lock was taken by apt-get: I think it
> would not be a good design and would mean that my task, offline
> updating apt packages lists with a provided archive, can't be safely
> implemented.
>
> Any idea, workaround? Thanks a lot.
>
> Greetings,
> Francesco

Not tested and off the top of my head:

apt-get --no-download -o APT::Update::Pre-Invoke::="find /var/lib/apt/lists 
-type f -a ! -name lock && tar xvjpf lists.tar.bz2 -C /var/lib/apt" update


- Invoking apt-get takes the lock so that is out of the way.

- --no-download prevents apt-get from going online and downloading Index files.

- APT::Update::Pre-Invoke is run before updating the index
  files. Although since you download nothing Post-Invoke would work
  too. But maybe something else wants to run then already.

MfG
        Goswin

PS: Why delete files prior to unpacking? Just unpack the new ones and
let apt clean up any extra files like it already does. That also allows for 
partial updates.


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to