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 <E.Burkov@AdGuard.COM>
Date:   Thu Feb 16 17:46:33 2023 +0300

    Merge branch 'master' into 5431-sudo-install

commit 29b3d8e27b5eddfb6e512c210d70041993079caf
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 16 17:31:43 2023 +0300

    scripts: fix code

commit 4354e2089396df3a2e63bcad499dc60975048a77
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 16 17:11:48 2023 +0300

    scripts: imp code

commit 4953b76abaddfb1870c3391f6da2c8a899dd596e
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 16 16:50:16 2023 +0300

    scripts: add sudo to freebsd service install
This commit is contained in:
Eugene Burkov 2023-02-16 18:57:44 +03:00
parent be43ce1760
commit 6f6ced33c1
2 changed files with 27 additions and 1 deletions

View File

@ -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
<!--
NOTE: Add new changes ABOVE THIS COMMENT.
-->

View File

@ -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