Skip to content

Commit

Permalink
Pull request: 5431 Privileged install
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 5431-sudo-install to master

Updates AdguardTeam#5431.

Squashed commit of the following:

commit 4dc9d8d
Merge: 29b3d8e be43ce1
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 16 17:46:33 2023 +0300

    Merge branch 'master' into 5431-sudo-install

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

    scripts: fix code

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

    scripts: imp code

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

    scripts: add sudo to freebsd service install
  • Loading branch information
EugeneOne1 committed Feb 16, 2023
1 parent be43ce1 commit 6f6ced3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-->
Expand Down
22 changes: 21 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f6ced3

Please sign in to comment.