Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further failsafe check for available APT packages #3537

Merged
merged 1 commit into from
Jan 7, 2021
Merged

Further failsafe check for available APT packages #3537

merged 1 commit into from
Jan 7, 2021

Conversation

MichaIng
Copy link
Contributor

@MichaIng MichaIng commented Jul 7, 2020

By submitting this pull request, I confirm the following:

  • I have read and understood the contributors guide, as well as this entire template.
  • I have made only one major change in my proposed changes.
  • I have commented my proposed changes within the code.
  • I have tested my proposed changes, and have included unit tests where possible.
  • I am willing to help maintain this change if there are issues with it later.
  • I give this submission freely and claim no ownership.
  • It is compatible with the EUPL 1.2 license
  • I have squashed any insignificant commits. (git rebase)

Signed-off-by: MichaIng micha@dietpi.com


What does this PR aim to accomplish?:

  • "apt-cache show package" succeeds as well if package is only listed as (optional) dependency or conflict by another installed package, while it may not be actually present in any repository, hence this is no 100% reliable check.
  • There is no command which explicitly checks if a package/name can be effectively selected by apt-get for install. An install simulation/dry-run is possible as it was before Pi-hole v5.1, or the whole package cache can be scraped, which is still the less time consuming solution.

How does this PR accomplish the above?:

  • Scrape apt-cache dumpavail for effectively available packages.
  • As well allow to succeed if another package "provides" it, like "php7.3-apcu" is provided by "php-apcu" or "awk" is provided by "mawk" and "gawk", in which case the actual (non-virtual) package is selected automatically by apt-get.

For reference: MichaIng/DietPi@066b89f

What documentation changes (if any) are needed to support this PR?:

  • None

@MichaIng
Copy link
Contributor Author

After quite some time of research and tests I found this to be the fastest 100% reliable solution, meaning as reliable as a dry-run install as it lets pass the same two cases. The chances that apt-cache show leads to a wrong result is marginal and zero on any officially supported APT-based distro anyway, so all this has minor importance (as of v5.1 release). Most importantly an empty APT cache does not lead to wrong packages being attempted to install anymore but a clear error messages, which is the case already now. This can be achieved with the dry-run install as well, if you prefer to stay with the method that worked until including Pi-hole v5.0, let me know.

Also probably it is nicer to move this in a separate function like is_package()? Just let me know.

@DL6ER
Copy link
Member

DL6ER commented Dec 10, 2020

apt-cache dumpavail

gives quite some output. How about storing this in an intermediate variable, like:

available_packages="$(apt-cache dumpavail | grep -E "^P(ackage|rovides):.*")"

and then do the individual greps (no need for a complicated regex here) on this reduced amount of data?


And yes, I agree on factoring this out into two functions:

  • get_package_list() like
    available_packages="$(apt-cache dumpavail | grep -E "^P(ackage|rovides):.*")"
  • is_package() like
     grep -E "iproute2(,|$)" <<< "${available_packages}"

What do you think?

@MichaIng
Copy link
Contributor Author

MichaIng commented Dec 10, 2020

Good idea to create the list once, to reduce overhead. It can be combined with the check function:

apt_package_list=
is_apt_package(){
    # Get list of available packages only once
    [[ $apt_package_list ]] || apt_package_list=$(apt-cache dumpavail | grep -E '^P(ackage|rovides):')
    if grep -qE " $1(,|$)" <<< "$available_packages"; then
        return 0
    fi
    return 1
}

The variable/function name is a bid long, but probably worth it to allow something similar for yum and dnf in the future? It could be merged into a single function for all package managers, but I personally don't see a benefit of it as it only requires more checks (about which package manager is used).

@MichaIng
Copy link
Contributor Author

@DL6ER
I made a function of it which obtains the available packages list only once. Please have a look.

@DL6ER DL6ER requested review from DL6ER and dschaper December 18, 2020 20:59
@@ -179,6 +179,18 @@ is_command() {
command -v "${check_command}" >/dev/null 2>&1
}

apt_package_list=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is meant to be a global variable then it should be declare up with the rest of the variables, starting on line 28. And the name should be in all caps if it's intended to be global.

If not then it should be declared local inside the function.

Copy link
Contributor Author

@MichaIng MichaIng Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of an edge case. It is only used in the below function, but it needs to be global to survive for subsequent calls of this function.

I find it easier to read the code when in this case it is declared aside of the function, but I can move it to the other global functions and make it upper case, if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd prefer all the variables to be in one place if they are not inside a function. Keeps from having to hunt down where they are. We already have the vars declared in one central place so this would become an outlier and I want to avoid things like that.

The function works from a quick test but we'd like to be more verbose with things. Use ifs and no || or &&s. It helps with our userbase to understand.

is_apt_package(){
    # Checks whether a package, or one that provides it, is available in
    # the installed APT repository lists.
    local check_package=$1

    # Obtain the list of available packages once
    if [ -z "$apt_package_list" ]; then
      apt_package_list=$(apt-cache dumpavail | grep -E '^P(ackage|rovides):')
    fi

    grep -qE " $check_package(,|$)" <<< "$apt_package_list"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay done.

- "apt-cache show package" succeeds as well if package is listed as (optional) dependency or conflict by another package, hence is not a 100% reliable measure.
- There is no command which explicitly checks which package/name can be selected by apt-get for install. An install simulation/dry-run is possible as it was before Pi-hole v5.1, or the whole package cache can be scraped, which is still the less time consuming solution.
- Allow to succeed if another package "provides" it, like "php7.3-apcu" provided by "php-apcu" or "awk" provided by "mawk" and "gawk", in which case the non-virtual package is selected automatically by apt-get.

For reference: MichaIng/DietPi@066b89f

Signed-off-by: MichaIng <micha@dietpi.com>
@dschaper dschaper self-assigned this Dec 19, 2020
@dschaper dschaper added Enhancement PR: Approval Required Open Pull Request, needs approval PR: Code Review Required Open Pull Request, needs code reviewd labels Dec 19, 2020
Copy link
Member

@DL6ER DL6ER left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this all looks very good. I'm currently unable to test as I'm in the middle of moving to a new place and my development (=testing) Pi-hole hasn't moved to the new place, yet. It will definitely happen before the new year, though.

@MichaIng
Copy link
Contributor Author

It is not urgent anyway, just makes that package detection a bit more robust, so take your time. Good luck with your moving, we just have that finished this spring 😛.

@DL6ER DL6ER merged commit c5ed8f8 into pi-hole:development Jan 7, 2021
@DL6ER DL6ER added PR: Approved Open Pull Request, Approved by required number of reviewers and removed PR: Approval Required Open Pull Request, needs approval PR: Code Review Required Open Pull Request, needs code reviewd labels Jan 7, 2021
@MichaIng MichaIng deleted the patch-2 branch January 7, 2021 11:36
@dschaper dschaper mentioned this pull request Jan 13, 2021
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-core-v5-2-3-web-v5-3-and-ftl-v5-4-released/43009/1

@jfb-pihole
Copy link
Sponsor Member

jfb-pihole commented Jan 16, 2021

@littleneutrino
Copy link

littleneutrino commented Jan 16, 2021

This may be causing problems for a user:

https://www.reddit.com/r/pihole/comments/kyme7b/help_pihole_up_failed_iproute2_and_iproute/

@MichaIng

When attempting to update to FTL 5.4 I receive the following error.
[✗] Aborting installation: iproute2 and iproute packages were not found in APT repository.
We also ran a confirmation that it was cached and installed
sudo apt-cache policy iproute2
iproute2:
Installed: 4.20.0-2
Candidate: 4.20.0-2
Version table:
*** 4.20.0-2 100
100 /var/lib/dpkg/status

@PromoFaux
Copy link
Member

One thing I will note, is that this change has realllly upped the verbosity of a bash -x run

@MichaIng
Copy link
Contributor Author

I guess the whole APT_PACKAGE_LIST variable is dumped once when using -x, when it's created, or even when it's processed by grep? 🤔

@littleneutrino
Could you paste the output of the following command, so we can check how the iproute2-related output looks in your case:

apt-cache dumpavail | grep -E '^P(ackage|rovides):.*iproute'

This is the output in my case, where the second-last does match the check, and this should be the case in all supported Debian and Ubuntu versions:

Package: libghc-iproute-dev
Provides: libghc-iproute-dev-1.7.9-ae4be
Package: libghc-iproute-doc
Package: libghc-iproute-prof
Provides: libghc-iproute-prof-1.7.9-ae4be
Package: iproute2
Package: iproute2-doc

Actually, considering the supported Debian and Ubuntu versions, iproute2, php7.X-sqlite3 and php are available on all of them, so the current uses of that check are actually not required anymore and it could hence be removed. But it might be worth to keep it and in case find a way it does not dump everything to the bash -x output, for possible future use cases, e.g. if Debian Bullseye ships PHP8.0 (not sure if it will or stays at PHP7.4) before PH7 integration into Pi-hole has finished.

@eist76

This comment has been minimized.

@dschaper

This comment has been minimized.

@MichaIng

This comment has been minimized.

@PromoFaux
Copy link
Member

For the docker container, please see this issue thread:

pi-hole/docker-pi-hole#762

@littleneutrino, what is the contents of /etc/resolv.conf on your Pi-hole machine please?

@dschaper
Copy link
Member

dschaper commented Jan 18, 2021

And try apt-cache --generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'

Edit: And it's converse apt-cache --no-generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'

@stevenepalmer
Copy link

stevenepalmer commented Jan 18, 2021

pi@raspberrypi:~ $ apt-cache dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $ apt-cache --generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $ apt-cache --no-generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $

@MichaIng
Copy link
Contributor Author

MichaIng commented Jan 18, 2021

Strange, apt-cache dumpavail shows nothing at all, even after a fresh apt-get update?

https://manpages.debian.org/buster/apt/apt-cache.8.en.html#OPTIONS

  • According to the man page, --generate is the default, but actually I'm not sure what it's supposed to do since the cache is not touched (/var/cache/apt/) by this command, as well not when specifying --generate/-g explicitly. The lists are not touched as well.

  • Ah:

    gencaches
    gencaches creates APT's package cache. This is done implicitly by all commands needing this cache if it is missing or outdated.

    "if it is missing or outdated" and indeed if I remove the /var/cache/apt/pkgcache.bin, it takes much longer, and re-creates the cache. If I use --no-generate, the cache is not created and the command fails (no output).

  • apt-get update however includes cache creation, if it succeeds and --generate is the default, even if it does not succeed. So that part should be irrelevant.

@stevenepalmer
Copy link

pi@raspberrypi:~ $ apt-cache dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $ apt-cache --generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $ apt-cache --no-generate dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $
pi@raspberrypi:~ $ sudo apt-get update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Reading package lists... Done
pi@raspberrypi:~ $ apt-cache dumpavail | grep -E '^P(ackage|rovides):.* iproute2(,|$)'
pi@raspberrypi:~ $

@dschaper
Copy link
Member

Just for fun:

apt-cache policy iproute2

@stevenepalmer
Copy link

pi@raspberrypi:~ $
pi@raspberrypi:~ $ apt-cache policy iproute2
iproute2:
Installed: 4.20.0-2
Candidate: 4.20.0-2
Version table:
*** 4.20.0-2 100
100 /var/lib/dpkg/status
pi@raspberrypi:~ $

@dschaper
Copy link
Member

Do you have archive.raspberrypi.org blocked?

dig archive.raspberrypi.org
dig raspbian.raspberrypi.org

@dschaper
Copy link
Member

Try seeing if you can actually view that page:

curl -IL http://archive.raspberrypi.org
curl -L http://archive.raspberrypi.org

@stevenepalmer
Copy link

stevenepalmer commented Jan 19, 2021

pi@raspberrypi:~ $ dig archive.rasberrypi.org

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> archive.rasberrypi.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43481
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;archive.rasberrypi.org.                IN      A

;; ANSWER SECTION:
archive.rasberrypi.org. 3600    IN      A       199.59.242.153

;; Query time: 209 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jan 18 18:33:08 PST 2021
;; MSG SIZE  rcvd: 89

pi@raspberrypi:~ $ dig archive.rasberrypi.org @127.0.0.1 -p 5053

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> archive.rasberrypi.org @127.0.0.1 -p 5053
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46231
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 55d8c4bd0848a7ba (echoed)
;; QUESTION SECTION:
;archive.rasberrypi.org.                IN      A

;; ANSWER SECTION:
archive.rasberrypi.org. 3580    IN      A       199.59.242.153

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5053(127.0.0.1)
;; WHEN: Mon Jan 18 18:33:28 PST 2021
;; MSG SIZE  rcvd: 101

@dschaper
Copy link
Member

dig raspbian.raspberrypi.org

@dschaper
Copy link
Member

dan@raspberrypi:~ $ dig archive.raspberrypi.org

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> archive.raspberrypi.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55834
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;archive.raspberrypi.org.       IN      A

;; ANSWER SECTION:
archive.raspberrypi.org. 129    IN      CNAME   lb.raspberrypi.org.
lb.raspberrypi.org.     129     IN      A       93.93.135.117
lb.raspberrypi.org.     129     IN      A       46.235.227.39
lb.raspberrypi.org.     129     IN      A       46.235.231.145
lb.raspberrypi.org.     129     IN      A       176.126.240.167
lb.raspberrypi.org.     129     IN      A       176.126.240.84
lb.raspberrypi.org.     129     IN      A       176.126.240.86
lb.raspberrypi.org.     129     IN      A       93.93.135.141
lb.raspberrypi.org.     129     IN      A       46.235.231.111
lb.raspberrypi.org.     129     IN      A       46.235.230.122
lb.raspberrypi.org.     129     IN      A       46.235.231.151
lb.raspberrypi.org.     129     IN      A       93.93.135.118
lb.raspberrypi.org.     129     IN      A       93.93.130.212

;; Query time: 9 msec
;; SERVER: 192.168.88.2#53(192.168.88.2)
;; WHEN: Mon Jan 18 18:35:45 PST 2021
;; MSG SIZE  rcvd: 276
dan@raspberrypi:~ $ dig raspbian.raspberrypi.org

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> raspbian.raspberrypi.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40123
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;raspbian.raspberrypi.org.      IN      A

;; ANSWER SECTION:
raspbian.raspberrypi.org. 300   IN      CNAME   mirrordirector.raspbian.org.
mirrordirector.raspbian.org. 600 IN     A       93.93.128.193

;; Query time: 785 msec
;; SERVER: 192.168.88.2#53(192.168.88.2)
;; WHEN: Mon Jan 18 18:31:49 PST 2021
;; MSG SIZE  rcvd: 107

Something is intercepting your DNS lookups.

@stevenepalmer
Copy link

stevenepalmer commented Jan 19, 2021

pi@raspberrypi:~ $ curl -IL http://archive.raspberrypi.org
HTTP/1.1 200 OK
Date: Tue, 19 Jan 2021 02:35:03 GMT
Server: Apache
Content-Type: text/html;charset=UTF-8

pi@raspberrypi:~ $ curl -L http://archive.raspberrypi.org
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 </head>
 <body>
<h1>Index of /</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="debian/">debian/</a></td><td align="right">2015-07-06 15:40  </td><td align="right">  - </td><td>&nbsp;</td></tr>
<tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="html/">html/</a></td><td align="right">2018-10-16 06:37  </td><td align="right">  - </td><td>&nbsp;</td></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
pi@raspberrypi:~ $
pi@raspberrypi:~ $ dig raspbian.raspberrypi.org

; <<>> DiG 9.11.5-P4-5.1+deb10u2-Raspbian <<>> raspbian.raspberrypi.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30532
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;raspbian.raspberrypi.org.      IN      A

;; ANSWER SECTION:
raspbian.raspberrypi.org. 300   IN      CNAME   mirrordirector.raspbian.org.
mirrordirector.raspbian.org. 300 IN     A       93.93.128.193

;; Query time: 175 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jan 18 18:38:37 PST 2021
;; MSG SIZE  rcvd: 161

@dschaper
Copy link
Member

dig rasbian.raspberrypi.org is not dig raspbian.raspberrypi.org

You need to be really careful with your typing.

@dschaper
Copy link
Member

Also, run ls -la /var/cache/apt/

@dschaper
Copy link
Member

Something is keeping you from seeing the remotes.

A good apt-cache policy should list the remote:

dan@raspberrypi:~ $ apt-cache policy iproute2
iproute2:
  Installed: 4.20.0-2
  Candidate: 4.20.0-2
  Version table:
 *** 4.20.0-2 500
        500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
        100 /var/lib/dpkg/status

@stevenepalmer
Copy link

pi@raspberrypi:~ $ ls -la /var/cache/apt/
total 3412
drwxr-xr-x 3 root root 4096 Jan 18 17:13 .
drwxr-xr-x 16 root root 4096 Feb 15 2020 ..
drwxr-xr-x 3 root root 139264 Jan 12 06:36 archives
-rw-r--r-- 1 root root 2111237 Jan 18 17:13 pkgcache.bin
-rw-r--r-- 1 root root 1228141 Jan 18 17:13 srcpkgcache.bin
pi@raspberrypi:~ $

@dschaper
Copy link
Member

Your pkgcache.bin is a lot smaller than mine.

Let's try removing it and doing a manual update to compare:

sudo rm /var/cache/apt/pkgcache.bin
sudo rm /var/cache/apt/srcpkgcache.bin

Then try sudo apt update and post that output.

Lastly, post the results of

apt-cache policy iproute2
ls -la /var/cache/apt/

@stevenepalmer
Copy link

stevenepalmer commented Jan 19, 2021

pi@raspberrypi:/var/cache/apt/archives $
pi@raspberrypi:/var/cache/apt/archives $ sudo rm /var/cache/apt/srcpkgcache.bin
pi@raspberrypi:/var/cache/apt/archives $ sudo apt update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
5 packages can be upgraded. Run 'apt list --upgradable' to see them.
pi@raspberrypi:/var/cache/apt/archives $ sudo apt list --upgradeable
Listing... Done
bluej/testing 4.2.1 all [upgradable from: 3.1.7b]
greenfoot/testing 3.6.0 all [upgradable from: 2.4.2a]
lxinput/testing 0.3.5-1+rpi9 armhf [upgradable from: 0.3.5-1]
piclone/testing 0.17 armhf [upgradable from: 0.4]
sense-emu-tools/testing 1.1.2 all [upgradable from: 1.0]
pi@raspberrypi:/var/cache/apt/archives $ apt-cache policy iproute2
iproute2:
  Installed: 4.20.0-2
  Candidate: 4.20.0-2
  Version table:
 *** 4.20.0-2 100
        100 /var/lib/dpkg/status
pi@raspberrypi:/var/cache/apt/archives $ ls -la /var/cache/apt
total 3412
drwxr-xr-x  3 root root    4096 Jan 18 18:46 .
drwxr-xr-x 16 root root    4096 Feb 15  2020 ..
drwxr-xr-x  3 root root  139264 Jan 12 06:36 archives
-rw-r--r--  1 root root 2111237 Jan 18 18:46 pkgcache.bin
-rw-r--r--  1 root root 1228141 Jan 18 18:46 srcpkgcache.bin
pi@raspberrypi:/var/cache/apt/archives $

I imagine I will be rebuilding this from scratch at some point but if you have more things you want ran feel free to ask.

@dschaper
Copy link
Member

You didn't do what I asked you to do.

(Or you didn't show the rm /var/cache/apt/pkgcache.bin)

I don't think we're going to find what we need here.

@stevenepalmer
Copy link

I did. I pasted in the commands MobaXterm just didnt keep the first line for whatever reason.

pi@raspberrypi:/var/cache/apt/archives $
pi@raspberrypi:/var/cache/apt/archives $ sudo rm /var/cache/apt/pkgcache.bin
pi@raspberrypi:/var/cache/apt/archives $ sudo rm /var/cache/apt/srcpkgcache.bin
pi@raspberrypi:/var/cache/apt/archives $ sudo apt update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
5 packages can be upgraded. Run 'apt list --upgradable' to see them.
pi@raspberrypi:/var/cache/apt/archives $ apt-cache policy iproute2
iproute2:
Installed: 4.20.0-2
Candidate: 4.20.0-2
Version table:
*** 4.20.0-2 100
100 /var/lib/dpkg/status
pi@raspberrypi:/var/cache/apt/archives $ ls -la /var/cache/apt/
total 3412
drwxr-xr-x 3 root root 4096 Jan 18 18:53 .
drwxr-xr-x 16 root root 4096 Feb 15 2020 ..
drwxr-xr-x 3 root root 139264 Jan 12 06:36 archives
-rw-r--r-- 1 root root 2111237 Jan 18 18:53 pkgcache.bin
-rw-r--r-- 1 root root 1228141 Jan 18 18:53 srcpkgcache.bin
pi@raspberrypi:/var/cache/apt/archives $

@dschaper
Copy link
Member

I still don't know why your pkgcache.bin is smaller than mine.

sudo rm /var/cache/apt/pkgcache.bin
ls -la /var/cache/apt/

@Kyrth
Copy link

Kyrth commented Jan 19, 2021

The TL;DR on this is somehow /etc/apt/sources.list got blanked out hence apt update was only doing other repo's
On update, my /var/lib/apt/lists was missing the main files and since 'apt-cache dumpavail' basically cat's those files, it will never find anything in the main repo's (iproute, php, you name it!)

If you look at @eLKosmonaut apt update there seems to only be debian buster InRelease listed, but for me iproute2 was in the backports repo (see debugging notes) and I was missing it!

$ sudo apt update
Hit:2 https://deb.debian.org/debian buster InRelease
Hit:3 https://download.mono-project.com/repo/debian buster InRelease
Hit:1 https://armbian.tnahosting.net/apt buster InRelease
Hit:4 https://deb.debian.org/debian buster-updates InRelease
Hit:5 https://deb.debian.org/debian-security buster/updates InRelease
Hit:6 https://deb.debian.org/debian buster-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

The main bit that was telling to me was 'apt-cache showpkg' listing the "default" dpkg of /var/lib/dpkg (since apt has no idea about them), where as apt controlled files correctly show /var/lib/apt/lists/....

I guess the changes could be to check sources make sense, or at least perhaps use dpkg to check if the command exists ? I'm not sure all embedded systems will use apt (but again, I get this is straying from the default Pi installation base)

My debugging notes:
"Broken" machine:

$ sudo apt-cache showpkg iproute2
Package: iproute2
Versions:
4.20.0-2 (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/dpkg/status
                  MD5: d10cc46ca4a9e5489b7d2c879fcfba17

Working machine:

$ sudo  apt-cache showpkg iproute2
Package: iproute2
Versions:
5.9.0-1~bpo10+1 (/var/lib/apt/lists/deb.debian.org_debian_dists_buster-backports_main_binary-arm64_Packages)

This then leads to /var/lib/apt/lists not having the right .xz cache list for apt-chache dumpavail to search.

"Broken" machine is missing main_binary (of any sorts, modern or backport!)

dpkg however still works fine (on both machines)

dpkg-query -f '${Package}\n' -W | grep 'iproute' #-W == --show
iproute2

@Kyrth
Copy link

Kyrth commented Jan 19, 2021

I should add that update worked fine after fixing my sources.list

@PromoFaux
Copy link
Member

I think, to be honest, I'd like to go ahead with a revert on this PR (#3997) until we can nail down exactly what is going on, and how to mitigate it with (near) 100% success.

Overall I like the idea of the apt-cache check - but something is proving to be incompatible with some systems. It's interesting that it is solved differently in bare metal vs docker.

@DL6ER
Copy link
Member

DL6ER commented Jan 19, 2021

I want to point out as well that reverting is only a band-aid fix and we should get this back in once we understand it better. At the same time, I agree we should maybe instead investigate further if we can remove some or maybe even all of the checks altogether (as suggested by @dschaper and @MichaIng)

@MichaIng
Copy link
Contributor Author

MichaIng commented Jan 19, 2021

@eLKosmonaut

$ sudo apt update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Reading package lists... Done

Wait, the RPi firmware list is the only one you use? Where is the Raspbian list http://raspbian.raspberrypi.org/raspbian/ ? The RPi list contains mostly kernel, firmware and special GPU-accelerated GUI software builds but none of the Debian base packages, it is no full repository 😉.

EDIT: Ah would fit the case of Kyrth. Okay so then it seems the ckeck is doing and succeeding (compared to apt-get show) in what it aims: checking if a package is available in the installed APT lists/sources or not. I mean technically if the package is installed already, it wouldn't matter, but any other base package install would fail then.

But indeed, from all I can see, the check is obsolete for currently supported distros. But the code should be kept at least commented, in case required in the future, with a link to this discussion 😉.

@PromoFaux
Copy link
Member

@eLKosmonaut / @littleneutrino, you should be able to switch back to master now (pihole checkout core master) to update to v5.2.4 (may need to run pihole -up after switching back)

@littleneutrino
Copy link

@eLKosmonaut / @littleneutrino, you should be able to switch back to master now (pihole checkout core master) to update to v5.2.4 (may need to run pihole -up after switching back)

Just ran the update after going back to Core Master and its updated no errors. thanks!

@stevenepalmer
Copy link

stevenepalmer commented Jan 19, 2021

@eLKosmonaut

$ sudo apt update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Reading package lists... Done

Wait, the RPi firmware list is the only one you use? Where is the Raspbian list http://raspbian.raspberrypi.org/raspbian/ ? The RPi list contains mostly kernel, firmware and special GPU-accelerated GUI software builds but none of the Debian base packages, it is no full repository 😉.

That was the case so that lead to the confusion.

@eLKosmonaut / @littleneutrino, you should be able to switch back to master now (pihole checkout core master) to update to v5.2.4 (may need to run pihole -up after switching back)

Ran the checkout back to core master and the installer stepped through smoothly.

Thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement PR: Approved Open Pull Request, Approved by required number of reviewers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants