Bug 268890 - www/adguardhome: adguardhome writes files to /usr/local/bin/
Summary: www/adguardhome: adguardhome writes files to /usr/local/bin/
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Yuri Victorovich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-11 17:30 UTC by Tobias Bölz
Modified: 2023-01-21 17:51 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (yuri)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Bölz 2023-01-11 17:30:26 UTC
When starting the adguardhome service after installing the port or package, it writes an AdGuardHome.yaml config file, a data directory, and possibly other files to /usr/local/bin/. This is because AdGuard Home defaults to the directory of the binary for both its config file and working directory.

Here is a patch that adds variables with reasonable defaults for adguardhome’s config and work-dir arguments to the rc.d script:

```
diff --git a/www/adguardhome/Makefile b/www/adguardhome/Makefile
index aa0996e711ef..b329ee41c71b 100644
--- a/www/adguardhome/Makefile
+++ b/www/adguardhome/Makefile
@@ -27,7 +27,8 @@ GO_BUILDFLAGS=  -ldflags="-s -w -X github.com/AdguardTeam/AdGuardHome/internal/v
 DEV_UPDATE_MODE=	no
 
 USER=		root # it has to run as root because it listens on the privileged DNS port
-SUB_LIST=	USER=${USER}
+GROUP=      wheel
+SUB_LIST=	USER=${USER} GROUP=${GROUP}
 USE_RC_SUBR=	${PORTNAME}
 
 CPE_VENDOR=	adguard
diff --git a/www/adguardhome/files/adguardhome.in b/www/adguardhome/files/adguardhome.in
index 902745da6a35..6a9fd0fb6532 100644
--- a/www/adguardhome/files/adguardhome.in
+++ b/www/adguardhome/files/adguardhome.in
@@ -14,12 +14,26 @@ rcvar=adguardhome_enable
 
 load_rc_config $name
 
-adguardhome_enable=${adguardhome_enable:-"NO"}
+: ${adguardhome_enable:=NO}
+: ${adguardhome_config:=/usr/local/etc/AdGuardHome.yaml}
+: ${adguardhome_user:=%%USER%%}
+: ${adguardhome_group:=%%GROUP%%}
+: ${adguardhome_work_dir:=/var/db/adguardhome}
 
 logfile="/var/log/${name}.log"
 
 procname=%%PREFIX%%/bin/adguardhome
 command="/usr/sbin/daemon"
-command_args="-u %%USER%% -o ${logfile} -t ${name} %%PREFIX%%/bin/adguardhome"
+command_args="-u ${adguardhome_user} -o ${logfile} -t ${name} %%PREFIX%%/bin/adguardhome -c ${adguardhome_config} -w ${adguardhome_work_dir}"
+
+start_precmd="${name}_prestart"
+
+adguardhome_prestart()
+{
+    if [ ! -d ${adguardhome_work_dir} ]; then
+        install -d -m 0750 -o ${adguardhome_user} -g ${adguardhome_group} \
+            ${adguardhome_work_dir}
+    fi
+}
 
 run_rc_command "$1"
```
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2023-01-13 07:19:18 UTC
Committed, thanks!
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-01-13 07:19:44 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=95bf6629820c81523de4693a7c6299ed62c7e1f6

commit 95bf6629820c81523de4693a7c6299ed62c7e1f6
Author:     Tobias Bölz <freebsd-bugs@boelz.eu>
AuthorDate: 2023-01-13 07:16:44 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-01-13 07:19:27 +0000

    www/adguardhome: Make AdGuardHome to write files into a dedicated directory

    PR:             268890

 www/adguardhome/Makefile             |  4 +++-
 www/adguardhome/files/adguardhome.in | 18 ++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)
Comment 3 Jony Hudson 2023-01-21 17:51:35 UTC
Just noting that this breaks existing installations, details here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269083