From 6f6ced33c10e2a8f5e2ca6402adb159f02a77f9b Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Thu, 16 Feb 2023 18:57:44 +0300 Subject: [PATCH] Pull request: 5431 Privileged install Merge in DNS/adguard-home from 5431-sudo-install to master Updates #5431. Squashed commit of the following: commit 4dc9d8d9e2a7f588b1367dcb42ea2df71ccdcbb7 Merge: 29b3d8e2 be43ce17 Author: Eugene Burkov Date: Thu Feb 16 17:46:33 2023 +0300 Merge branch 'master' into 5431-sudo-install commit 29b3d8e27b5eddfb6e512c210d70041993079caf Author: Eugene Burkov Date: Thu Feb 16 17:31:43 2023 +0300 scripts: fix code commit 4354e2089396df3a2e63bcad499dc60975048a77 Author: Eugene Burkov Date: Thu Feb 16 17:11:48 2023 +0300 scripts: imp code commit 4953b76abaddfb1870c3391f6da2c8a899dd596e Author: Eugene Burkov Date: Thu Feb 16 16:50:16 2023 +0300 scripts: add sudo to freebsd service install --- CHANGELOG.md | 6 ++++++ scripts/install.sh | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5789eb38..8b817450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,12 @@ See also the [v0.107.25 GitHub milestone][ms-v0.107.25]. NOTE: Add new changes BELOW THIS COMMENT. --> +### Fixed + +- Failing service installation via script on FreeBSD ([#5431]). + +[#5431]: https://github.com/AdguardTeam/AdGuardHome/issues/5431 + diff --git a/scripts/install.sh b/scripts/install.sh index 58fd37fe..8c30268d 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -33,6 +33,19 @@ usage() { exit 2 } +# Function maybe_sudo runs passed command with root privileges if use_sudo isn't +# equal to 0. +# +# TODO(e.burkov): Use everywhere the sudo_cmd isn't quoted. +maybe_sudo() { + if [ "$use_sudo" -eq 0 ] + then + "$@" + else + "$sudo_cmd" "$@" + fi +} + # Function is_command checks if the command exists on the machine. is_command() { command -v "$1" >/dev/null 2>&1 @@ -554,7 +567,14 @@ handle_existing() { # Function install_service tries to install AGH as service. install_service() { - if ( cd "$agh_dir" && ./AdGuardHome -s install ) + # Installing the service as root is required at least on FreeBSD. + use_sudo='0' + if [ "$os" = 'freebsd' ] + then + use_sudo='1' + fi + + if ( cd "$agh_dir" && maybe_sudo ./AdGuardHome -s install ) then return 0 fi