mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-06-08 08:44:32 +02:00
218 lines
9.2 KiB
Diff
218 lines
9.2 KiB
Diff
From 8daed7419d3dafa21d8bfa5f9ba21fd50c1bfca7 Mon Sep 17 00:00:00 2001
|
|
From: Mike Crute <mike@crute.us>
|
|
Date: Sat, 10 May 2025 15:14:03 -0700
|
|
Subject: [PATCH 3/3] Support configuring file paths
|
|
|
|
Allow configuring the file paths for storing configuration and state
|
|
through cmake so that Linux distribution packagers can place their files
|
|
in FHS-friendly paths.
|
|
---
|
|
src/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++
|
|
src/api/action.c | 2 +-
|
|
src/config/config.c | 10 +++++-----
|
|
src/config/config.h | 2 +-
|
|
src/config/dnsmasq_config.h | 8 ++++----
|
|
src/dnsmasq/CMakeLists.txt | 2 +-
|
|
src/files.h | 2 +-
|
|
src/lua/CMakeLists.txt | 2 +-
|
|
src/zip/teleporter.c | 4 ++--
|
|
9 files changed, 46 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/FTL-6.1/src/CMakeLists.txt b/FTL-6.1/src/CMakeLists.txt
|
|
index f9902bec..e6b142ec 100644
|
|
--- a/FTL-6.1/src/CMakeLists.txt
|
|
+++ b/FTL-6.1/src/CMakeLists.txt
|
|
@@ -15,6 +15,36 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
|
|
endif()
|
|
endif()
|
|
|
|
+if (PIHOLE_STATE_PATH)
|
|
+ add_definitions(-DPIHOLE_STATE_PATH="${PIHOLE_STATE_PATH}")
|
|
+else()
|
|
+ add_definitions(-DPIHOLE_STATE_PATH="/etc/pihole")
|
|
+endif()
|
|
+
|
|
+if (PIHOLE_SHARE_PATH)
|
|
+ add_definitions(-DPIHOLE_SHARE_PATH="${PIHOLE_SHARE_PATH}")
|
|
+else()
|
|
+ add_definitions(-DPIHOLE_SHARE_PATH="/etc/pihole")
|
|
+endif()
|
|
+
|
|
+if (PIHOLE_BIN_PATH)
|
|
+ add_definitions(-DPIHOLE_BIN_PATH="${PIHOLE_BIN_PATH}")
|
|
+else()
|
|
+ add_definitions(-DPIHOLE_BIN_PATH="/usr/local/bin")
|
|
+endif()
|
|
+
|
|
+if (PIHOLE_WEB_PATH)
|
|
+ add_definitions(-DPIHOLE_WEB_PATH="${PIHOLE_WEB_PATH}")
|
|
+else()
|
|
+ add_definitions(-DPIHOLE_WEB_PATH="/var/www/html")
|
|
+endif()
|
|
+
|
|
+if (PIHOLE_RUN_PATH)
|
|
+ add_definitions(-DPIHOLE_RUN_PATH="${PIHOLE_RUN_PATH}")
|
|
+else()
|
|
+ add_definitions(-DPIHOLE_RUN_PATH="/run")
|
|
+endif()
|
|
+
|
|
# Do not add run time path information
|
|
# This ensures CMake does not add rpath information to the binary and
|
|
# subsequently strip it from the binary during install causing the binary
|
|
diff --git a/FTL-6.1/src/api/action.c b/FTL-6.1/src/api/action.c
|
|
index 4a55d6e5..306e91f8 100644
|
|
--- a/FTL-6.1/src/api/action.c
|
|
+++ b/FTL-6.1/src/api/action.c
|
|
@@ -117,7 +117,7 @@ static int run_and_stream_command(struct ftl_conn *api, const char *path, const
|
|
|
|
int api_action_gravity(struct ftl_conn *api)
|
|
{
|
|
- return run_and_stream_command(api, "/usr/local/bin/pihole", (const char *const []){ "pihole", "-g", NULL });
|
|
+ return run_and_stream_command(api, PIHOLE_BIN_PATH"/pihole", (const char *const []){ "pihole", "-g", NULL });
|
|
}
|
|
|
|
int api_action_restartDNS(struct ftl_conn *api)
|
|
diff --git a/FTL-6.1/src/config/config.c b/FTL-6.1/src/config/config.c
|
|
index c98add76..3d2f2f0f 100644
|
|
--- a/FTL-6.1/src/config/config.c
|
|
+++ b/FTL-6.1/src/config/config.c
|
|
@@ -1065,7 +1065,7 @@ void initConfig(struct config *conf)
|
|
conf->webserver.paths.webroot.a = cJSON_CreateStringReference("<valid path>");
|
|
conf->webserver.paths.webroot.t = CONF_STRING;
|
|
conf->webserver.paths.webroot.f = FLAG_RESTART_FTL;
|
|
- conf->webserver.paths.webroot.d.s = (char*)"/var/www/html";
|
|
+ conf->webserver.paths.webroot.d.s = (char*)PIHOLE_WEB_PATH;
|
|
conf->webserver.paths.webroot.c = validate_filepath;
|
|
|
|
conf->webserver.paths.webhome.k = "webserver.paths.webhome";
|
|
@@ -1232,14 +1232,14 @@ void initConfig(struct config *conf)
|
|
conf->files.pid.a = cJSON_CreateStringReference("<any writable file>");
|
|
conf->files.pid.t = CONF_STRING;
|
|
conf->files.pid.f = FLAG_RESTART_FTL;
|
|
- conf->files.pid.d.s = (char*)"/run/pihole-FTL.pid";
|
|
+ conf->files.pid.d.s = (char*)PIHOLE_RUN_PATH"/FTL.pid";
|
|
conf->files.pid.c = validate_filepath;
|
|
|
|
conf->files.database.k = "files.database";
|
|
conf->files.database.h = "The location of FTL's long-term database";
|
|
conf->files.database.a = cJSON_CreateStringReference("<any FTL database>");
|
|
conf->files.database.t = CONF_STRING;
|
|
- conf->files.database.d.s = (char*)"/etc/pihole/pihole-FTL.db";
|
|
+ conf->files.database.d.s = (char*)PIHOLE_STATE_PATH"/pihole-FTL.db";
|
|
conf->files.database.c = validate_filepath;
|
|
|
|
conf->files.gravity.k = "files.gravity";
|
|
@@ -1247,7 +1247,7 @@ void initConfig(struct config *conf)
|
|
conf->files.gravity.a = cJSON_CreateStringReference("<any Pi-hole gravity database>");
|
|
conf->files.gravity.t = CONF_STRING;
|
|
conf->files.gravity.f = FLAG_RESTART_FTL;
|
|
- conf->files.gravity.d.s = (char*)"/etc/pihole/gravity.db";
|
|
+ conf->files.gravity.d.s = (char*)PIHOLE_STATE_PATH"/gravity.db";
|
|
conf->files.gravity.c = validate_filepath;
|
|
|
|
conf->files.gravity_tmp.k = "files.gravity_tmp";
|
|
@@ -1262,7 +1262,7 @@ void initConfig(struct config *conf)
|
|
conf->files.macvendor.h = "The database containing MAC -> Vendor information for the network table";
|
|
conf->files.macvendor.a = cJSON_CreateStringReference("<any Pi-hole macvendor database>");
|
|
conf->files.macvendor.t = CONF_STRING;
|
|
- conf->files.macvendor.d.s = (char*)"/etc/pihole/macvendor.db";
|
|
+ conf->files.macvendor.d.s = (char*)PIHOLE_SHARE_PATH"/macvendor.db";
|
|
conf->files.macvendor.c = validate_filepath;
|
|
|
|
conf->files.setupVars.k = "files.setupVars";
|
|
diff --git a/FTL-6.1/src/config/config.h b/FTL-6.1/src/config/config.h
|
|
index 780793a2..5e399752 100644
|
|
--- a/FTL-6.1/src/config/config.h
|
|
+++ b/FTL-6.1/src/config/config.h
|
|
@@ -40,7 +40,7 @@
|
|
#define GLOBALCONFFILE_LEGACY "/etc/pihole/pihole-FTL.conf"
|
|
|
|
// Migration target for the legacy (pre-v6.0) config file
|
|
-#define MIGRATION_TARGET_V6 "/etc/pihole/migration_backup_v6"
|
|
+#define MIGRATION_TARGET_V6 PIHOLE_STATE_PATH"/migration_backup_v6"
|
|
|
|
union conf_value {
|
|
bool b; // boolean value
|
|
diff --git a/FTL-6.1/src/config/dnsmasq_config.h b/FTL-6.1/src/config/dnsmasq_config.h
|
|
index 92175ec9..fa05f39c 100644
|
|
--- a/FTL-6.1/src/config/dnsmasq_config.h
|
|
+++ b/FTL-6.1/src/config/dnsmasq_config.h
|
|
@@ -22,14 +22,14 @@ bool read_legacy_cnames_config(void);
|
|
bool read_legacy_custom_hosts_config(void);
|
|
bool write_custom_list(void);
|
|
|
|
-#define DNSMASQ_PH_CONFIG "/etc/pihole/dnsmasq.conf"
|
|
-#define DNSMASQ_TEMP_CONF "/etc/pihole/dnsmasq.conf.temp"
|
|
+#define DNSMASQ_PH_CONFIG PIHOLE_STATE_PATH"/dnsmasq.conf"
|
|
+#define DNSMASQ_TEMP_CONF PIHOLE_STATE_PATH"/dnsmasq.conf.temp"
|
|
#define DNSMASQ_STATIC_LEASES MIGRATION_TARGET_V6"/04-pihole-static-dhcp.conf"
|
|
#define DNSMASQ_CNAMES MIGRATION_TARGET_V6"/05-pihole-custom-cname.conf"
|
|
-#define DNSMASQ_HOSTSDIR "/etc/pihole/hosts"
|
|
+#define DNSMASQ_HOSTSDIR PIHOLE_STATE_PATH"/hosts"
|
|
#define DNSMASQ_CUSTOM_LIST DNSMASQ_HOSTSDIR"/custom.list"
|
|
#define DNSMASQ_CUSTOM_LIST_LEGACY "/etc/pihole/custom.list"
|
|
#define DNSMASQ_CUSTOM_LIST_LEGACY_TARGET MIGRATION_TARGET_V6"/custom.list"
|
|
-#define DHCPLEASESFILE "/etc/pihole/dhcp.leases"
|
|
+#define DHCPLEASESFILE PIHOLE_STATE_PATH"/dhcp.leases"
|
|
|
|
#endif //DNSMASQ_CONFIG_H
|
|
diff --git a/FTL-6.1/src/dnsmasq/CMakeLists.txt b/FTL-6.1/src/dnsmasq/CMakeLists.txt
|
|
index 81e8ac50..ffdab563 100644
|
|
--- a/FTL-6.1/src/dnsmasq/CMakeLists.txt
|
|
+++ b/FTL-6.1/src/dnsmasq/CMakeLists.txt
|
|
@@ -63,7 +63,7 @@ set(sources
|
|
|
|
add_library(dnsmasq OBJECT ${sources})
|
|
target_compile_definitions(dnsmasq PRIVATE VERSION=\"${DNSMASQ_VERSION}\")
|
|
-target_compile_definitions(dnsmasq PRIVATE CONFFILE=\"/etc/pihole/dnsmasq.conf\")
|
|
+target_compile_definitions(dnsmasq PRIVATE CONFFILE=\"/var/lib/pihole/dnsmasq.conf\")
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized -Wno-sign-compare)
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
diff --git a/FTL-6.1/src/files.h b/FTL-6.1/src/files.h
|
|
index b5f16019..5478d9bf 100644
|
|
--- a/FTL-6.1/src/files.h
|
|
+++ b/FTL-6.1/src/files.h
|
|
@@ -20,7 +20,7 @@
|
|
#include <pwd.h>
|
|
|
|
#define MAX_ROTATIONS 15
|
|
-#define BACKUP_DIR "/etc/pihole/config_backups"
|
|
+#define BACKUP_DIR PIHOLE_STATE_PATH"/config_backups"
|
|
|
|
bool chmod_file(const char *filename, const mode_t mode);
|
|
bool file_exists(const char *filename);
|
|
diff --git a/FTL-6.1/src/lua/CMakeLists.txt b/FTL-6.1/src/lua/CMakeLists.txt
|
|
index 90ddda91..b62f24c6 100644
|
|
--- a/FTL-6.1/src/lua/CMakeLists.txt
|
|
+++ b/FTL-6.1/src/lua/CMakeLists.txt
|
|
@@ -80,7 +80,7 @@ endif()
|
|
target_compile_definitions(lua PRIVATE LUA_USE_POSIX)
|
|
|
|
# Set the default path that Lua uses to look for Lua libraries.
|
|
-target_compile_definitions(lua PRIVATE LUA_PATH_DEFAULT="/opt/pihole/libs/?.lua")
|
|
+target_compile_definitions(lua PRIVATE LUA_PATH_DEFAULT="/usr/share/pihole/lua-libs/?.lua")
|
|
|
|
if(LUA_DL STREQUAL "true")
|
|
target_compile_definitions(lua PRIVATE LUA_USE_DLOPEN)
|
|
diff --git a/FTL-6.1/src/zip/teleporter.c b/FTL-6.1/src/zip/teleporter.c
|
|
index eb6b5012..f249aa3c 100644
|
|
--- a/FTL-6.1/src/zip/teleporter.c
|
|
+++ b/FTL-6.1/src/zip/teleporter.c
|
|
@@ -184,11 +184,11 @@ const char *generate_teleporter_zip(mz_zip_archive *zip, char filename[128], voi
|
|
|
|
// Add /etc/pihole/dhcp.lease to the ZIP archive if it exists
|
|
file_comment = "DHCP leases file";
|
|
- file_path = "/etc/pihole/dhcp.leases";
|
|
+ file_path = PIHOLE_STATE_PATH"/dhcp.leases";
|
|
if(file_exists(file_path) && !mz_zip_writer_add_file(zip, file_path+1, file_path, file_comment, (uint16_t)strlen(file_comment), MZ_BEST_COMPRESSION))
|
|
{
|
|
mz_zip_writer_end(zip);
|
|
- return "Failed to add /etc/pihole/dhcp.leases to heap ZIP archive!";
|
|
+ return "Failed to add " PIHOLE_STATE_PATH "/dhcp.leases to heap ZIP archive!";
|
|
}
|
|
|
|
const char *directory = "/etc/dnsmasq.d";
|
|
--
|
|
2.45.2
|
|
|