Skip to content

Conversation

yubiuser
Copy link
Member

@yubiuser yubiuser commented Jun 5, 2025

What does this PR aim to accomplish?:

Only update the package cache once on fresh installs, not on checkouts/updates. Addresses #6272


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

@yubiuser
Copy link
Member Author

yubiuser commented Jun 5, 2025

The seconds commit should fix the tests. Not sure why we had fresh_install=false in a test that should test a fresh installation.

@darkexplosiveqwx
Copy link
Contributor

I think we should still update the package cache when the meta package is updated, so all new dependencies are up to date.

@yubiuser
Copy link
Member Author

yubiuser commented Jun 5, 2025

This would be possible too. We would only need to signal package_manager_detect that we are invoking from the update script or not.

@dschaper
Copy link
Member

dschaper commented Jun 5, 2025

How does this compare to #6274 ?

@yubiuser
Copy link
Member Author

yubiuser commented Jun 5, 2025

In the current implementation or the one suggestion by @darkexplosiveqwx ?

#6274 removes also the building and installing of the dependency package before doing an update - which might fails because some 'installer dependency' is not installed.

@dschaper
Copy link
Member

dschaper commented Jun 5, 2025

Ah, okay. Maybe something like apt cache policy <dependency package> | grep version and compare that to the /etc/.pihole/ <package metadata version> and "do things" if the proposed updated metadata is higher than the installed package version?

Copy link
Member

@dschaper dschaper left a comment

Choose a reason for hiding this comment

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

This was changed in https://github.com/pi-hole/pi-hole/pull/6034/files#diff-d47c0707deb6f9f41a6a35ba455245c05e2297b4d408551721dda75b1c1be394L92

@PromoFaux Do you know why the lines were changed here
image

I'm a little hesitant to remove the lines completely when we don't know why they were there in the first place.

@PromoFaux
Copy link
Member

fresh_install was introduced as a replacement for useUpdateVars, but the logic was "reversed" to make the names make sense.

Replaces the variable useUpdateVars with fresh_install and flips the logic around. useUpdateVars used to make sense as a name when a user could seed a setupVars.conf file, but this is no longer the case and the naming is not so clear.

So I just changed them in the tests, too.

@yubiuser
Copy link
Member Author

yubiuser commented Jun 8, 2025

It was added in the first place with this commit
cedd1a2

Back then, the test added configuration to setupVars.conf to automatically install the web interace and the web server. This is no longer needed.

# create configuration file
setup_var_file = 'cat <<EOF> /etc/pihole/setupVars.conf\n'
for k, v in SETUPVARS.items():
setup_var_file += "{}={}\n".format(k, v)
setup_var_file += "INSTALL_WEB_SERVER=true\n"
setup_var_file += "INSTALL_WEB_INTERFACE=true\n"
setup_var_file += "EOF\n"
Pihole.run(setup_var_file)
install = Pihole.run('''
export TERM=xterm
export DEBIAN_FRONTEND=noninteractive
umask 0027
runUnattended=true
useUpdateVars=true
source /opt/pihole/basic-install.sh > /dev/null
runUnattended=true
useUpdateVars=true

@mwoolweaver
Copy link
Contributor

mwoolweaver commented Jun 8, 2025

Would #6292 #6298 be a more graceful solution?

@yubiuser
Copy link
Member Author

yubiuser commented Jun 8, 2025

I'm not sure if this is the way to go. While it addresses the suggestions from above, it adds 100 lines of code. I'm not sure if this is worth it, considering 'normal' users will only benefit from it during an update which is not happening that often.


I would go another way as a middle ground: only update the cache before we install the meta package initiated by the install script, but not from the updater.


ADD
I only noticed now, that we do the cache update only on apt based systems, reducing the necessarity to do it at all even more from my view.

@yubiuser
Copy link
Member Author

yubiuser commented Jun 8, 2025

The last two changes allow to update the cache when building/installing the meta package from the installer script, but don't do when building/installing from the update script.
I intentionally did not squash to allow easy reverting to a previous state depending on how we decide the functions should work.

@yubiuser yubiuser requested review from dschaper and a team June 8, 2025 19:33
@mwoolweaver
Copy link
Contributor

mwoolweaver commented Jun 8, 2025

While it addresses the suggestions from above, it adds 100 lines of code.

But it saves about 160 lines with each pihole -up that contains no meta data changes and saves SD activity caused by installing the same version of the package again. (when no Pi-hole updates available)

If there is an update to core repo with NO meta packages changes or just an FTL update it would save double the lines and double the SD activity. Currently all package management steps are done twice is these two scenarios, once at the beginning of update.sh and again during basic-install.sh. see here

and would also ensure that

we had users who removed e.g. git which were left with a broken update.1

does not happen as well.

@dschaper
Copy link
Member

I'd like to go for this PR for now as it improves the situation. The massive change in #6298 needs some very thorough review and testing and that's going to take time.

Considering this is a QOL fix and not a bug fix, I'm good with what Yubi has written.

@dschaper
Copy link
Member

@mwoolweaver:

But it saves about 160 lines with each pihole -up that contains no meta data changes

Where do you see these 160 lines?

This is the output that I see with this branch code:

root@pihole:/etc/.pihole# pihole -up
  [✓] Building dependency package pihole-meta.deb
  [✓] Installing Pi-hole dependency package

  [i] Checking for updates...
  [i] Pi-hole Core:     up to date
  [i] Web Interface:    up to date
  [i] FTL:              up to date

  [✓] Everything is up to date!

I think I like the idea of always creating/updating the dependency package. It gives us a guarantee that the update will function because it will add the packages that we know we need to run the update. This accounts for the case where a user removes a package that we need from the system, and it's really a light process to run. I don't see it generating a lot of writes to any drive or storage media.

Here's a verbose run of the update code:

+ build_dependency_package
+ rm -rf '/tmp/pihole-meta_*'
+ local tempdir
++ mktemp --directory /tmp/pihole-meta_XXXXX
+ tempdir=/tmp/pihole-meta_JaZox
+ chmod 0755 /tmp/pihole-meta_JaZox
+ is_command apt-get
+ local check_command=apt-get
+ command -v apt-get
+ pushd /tmp
+ rm -f /tmp/pihole-meta.deb
+ mkdir -p /tmp/pihole-meta_JaZox/DEBIAN
+ chmod 0755 /tmp/pihole-meta_JaZox/DEBIAN
+ touch /tmp/pihole-meta_JaZox/DEBIAN/control
+ echo 'Package: pihole-meta
Version: 0.4
Maintainer: Pi-hole team <[email protected]>
Architecture: all
Description: Pi-hole dependency meta package
Depends: awk,bash-completion,binutils,ca-certificates,cron|cron-daemon,curl,dialog,dnsutils,dns-root-data,git,grep,iproute2,iputils-ping,jq,libcap2,libcap2-bin,lshw,netcat-openbsd,procps,psmisc,sudo,unzip
Section: contrib/metapackages
Priority: optional'
+ local 'str=Building dependency package pihole-meta.deb'
+ printf '  %b %s...' '[i]' 'Building dependency package pihole-meta.deb'
  [i] Building dependency package pihole-meta.deb...+ dpkg-deb --build --root-owner-group /tmp/pihole-meta_JaZox pihole-meta.deb
+ printf '%b  %b %s\n' '\r' '[✓]' 'Building dependency package pihole-meta.deb'
  [✓] Building dependency package pihole-meta.deb
+ popd
+ rm -rf /tmp/pihole-meta_JaZox
+ install_dependent_packages
+ local 'str=Installing Pi-hole dependency package'
+ printf '  %b %s...' '[i]' 'Installing Pi-hole dependency package'
  [i] Installing Pi-hole dependency package...+ is_command apt-get
+ local check_command=apt-get
+ command -v apt-get
+ '[' -f /tmp/pihole-meta.deb ']'
+ eval 'apt-get -qq --no-install-recommends install' /tmp/pihole-meta.deb
+ printf '%b  %b %s\n' '\r' '[✓]' 'Installing Pi-hole dependency package'
  [✓] Installing Pi-hole dependency package
+ rm /tmp/pihole-meta.deb
+ printf '\n'

@dschaper dschaper merged commit 3d75ea6 into development Jul 10, 2025
16 checks passed
@dschaper dschaper deleted the no_cache_update branch July 10, 2025 18:20
@dschaper dschaper added this to the v6.1.3 milestone Jul 12, 2025
@dschaper dschaper mentioned this pull request Jul 14, 2025
@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-v6-1-3-released/81168/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants