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