Files
Boris Rybalkin b12d2c51ff config: make the install/config directory a compile-time option (PIHOLE_INSTALL_DIR)
All of Pi-hole's configuration and state currently lives under a hardcoded
/etc/pihole. Packagers that install FTL into a different prefix (snaps, /opt
installs, read-only-root images, ...) have to patch the sources.

Introduce a single compile-time base directory, PIHOLE_INSTALL_DIR, defaulting
to /etc/pihole so behaviour is unchanged, and route the /etc/pihole paths
through it: the hardcoded config/state defines (pihole.toml, the legacy config,
dnsmasq.conf, hosts, custom.list, dhcp.leases, backups, cli_pw, versions, the
inotify watch dir), the embedded dnsmasq CONFFILE, and the /etc/pihole defaults
of the runtime-settable config options (files.database, files.tmp_db,
files.gravity, files.macvendor, webserver.tls.cert). Packagers can now relocate
the tree with

    cmake -DPIHOLE_INSTALL_DIR=/opt/pihole/etc ...

This is a build-time knob only and deliberately does not add a runtime override
(files.pid stays fixed per GHSA-6w8x-p785-6pm4). The /var/log/pihole log
defaults are left untouched as they are a different base directory.

Teleporter archives stay portable across installs, so the archive entry names
are pinned to their canonical etc/pihole/... values regardless of where the
files live on disk - only the on-disk source path is relocated. Export
previously derived every name from the absolute path minus its leading slash,
which would have made a relocated build write opt/pihole/etc/... while the
import side matched fixed names, silently skipping the affected files. That
applied to pihole.toml and dhcp.leases via PIHOLE_INSTALL_DIR, and to the
gravity and FTL databases via the runtime files.gravity/files.database values -
the latter reachable even without relocation, for anyone who moves gravity.db.
All four now go through ZIPNAME_TOML/ZIPNAME_DHCPLEASES/ZIPNAME_GRAVITY/
ZIPNAME_FTLDB, shared by export and import, and a test exports an archive and
asserts the names. Import targets are unchanged: gravity is still imported
table-wise into whatever files.gravity points at.

The embedded OpenAPI specs are run through configure_file() so the five
relocatable defaults they document (cert, database, tmp_db, gravity, macvendor)
and the two adlists.list mentions in lists.yaml follow the configured value
instead of documenting paths a relocated install does not use. The two help
strings naming the directory (webserver.api.cli_pw, debug.inotify) follow it as
well, as they are rendered into pihole.toml and served in the API docs.

CMake rejects a relative or trailing-slash PIHOLE_INSTALL_DIR, as the teleporter
strips the leading slash by offset, and one containing a percent sign, as the
value reaches printf format strings by concatenation in existing log messages
(e.g. main.c "Parsed config file "GLOBALTOMLPATH" successfully"). The check
carries a comment naming those call sites so it is not relaxed without
converting them first. The --gen-x509 and --read-x509 usage examples pass the
directory as an argument rather than concatenating it, matching
write_config_header().

Signed-off-by: Boris Rybalkin <ribalkin@gmail.com>
2026-08-30 17:28:06 +03:00
..
…
…