2020-10-07 18:01:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-12-30 15:26:25 +00:00
|
|
|
# AdGuard Home Installation Script
|
2021-05-17 12:24:05 +00:00
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
# Exit the script if a pipeline fails (-e), prevent accidental filename
|
|
|
|
# expansion (-f), and consider undefined variables as errors (-u).
|
|
|
|
set -e -f -u
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function log is an echo wrapper that writes to stderr if the caller
|
|
|
|
# requested verbosity level greater than 0. Otherwise, it does nothing.
|
|
|
|
log() {
|
|
|
|
if [ "$verbose" -gt '0' ]
|
|
|
|
then
|
|
|
|
echo "$1" 1>&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function error_exit is an echo wrapper that writes to stderr and stops the
|
|
|
|
# script execution with code 1.
|
|
|
|
error_exit() {
|
|
|
|
echo "$1" 1>&2
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function usage prints the note about how to use the script.
|
2020-10-07 18:01:30 +00:00
|
|
|
#
|
2021-05-17 12:24:05 +00:00
|
|
|
# TODO(e.burkov): Document each option.
|
|
|
|
usage() {
|
|
|
|
echo 'install.sh: usage: [-c channel] [-C cpu_type] [-h] [-O os] [-o output_dir]'\
|
|
|
|
'[-r|-R] [-u|-U] [-v|-V]' 1>&2
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
exit 2
|
|
|
|
}
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function is_command checks if the command exists on the machine.
|
|
|
|
is_command() {
|
|
|
|
command -v "$1" >/dev/null 2>&1
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function is_little_endian checks if the CPU is little-endian.
|
|
|
|
is_little_endian() {
|
|
|
|
[ "$( head -c 6 /bin/sh | tail -c 1 )" = "$( printf '\001' )" ]
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function check_required checks if the required software is available on the
|
|
|
|
# machine. The required software:
|
|
|
|
#
|
2021-09-21 11:45:59 +00:00
|
|
|
# unzip (macOS) / tar (other unixes)
|
2021-05-17 12:24:05 +00:00
|
|
|
#
|
2022-02-09 16:51:26 +00:00
|
|
|
# curl/wget are checked in function configure.
|
2021-05-17 12:24:05 +00:00
|
|
|
check_required() {
|
2021-05-19 17:31:20 +00:00
|
|
|
required_darwin="unzip"
|
|
|
|
required_unix="tar"
|
|
|
|
readonly required_darwin required_unix
|
2021-05-17 12:24:05 +00:00
|
|
|
|
2021-06-01 13:04:22 +00:00
|
|
|
case "$os"
|
|
|
|
in
|
2021-06-03 18:04:13 +00:00
|
|
|
('freebsd'|'linux'|'openbsd')
|
2022-02-09 16:51:26 +00:00
|
|
|
required="$required_unix"
|
2021-06-01 13:04:22 +00:00
|
|
|
;;
|
|
|
|
('darwin')
|
2022-02-09 16:51:26 +00:00
|
|
|
required="$required_darwin"
|
2021-06-01 13:04:22 +00:00
|
|
|
;;
|
|
|
|
(*)
|
2022-02-09 16:51:26 +00:00
|
|
|
# Generally shouldn't happen, since the OS has already been validated.
|
2021-06-03 18:04:13 +00:00
|
|
|
error_exit "unsupported operating system: '$os'"
|
2021-06-01 13:04:22 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-02-09 16:51:26 +00:00
|
|
|
readonly required
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Don't use quotes to get word splitting.
|
2022-02-09 16:51:26 +00:00
|
|
|
for cmd in $required
|
2021-05-17 12:24:05 +00:00
|
|
|
do
|
2021-06-02 11:51:56 +00:00
|
|
|
log "checking $cmd"
|
2021-05-17 12:24:05 +00:00
|
|
|
if ! is_command "$cmd"
|
|
|
|
then
|
|
|
|
log "the full list of required software: [$required]"
|
|
|
|
|
|
|
|
error_exit "$cmd is required to install AdGuard Home via this script"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function check_out_dir requires the output directory to be set and exist.
|
|
|
|
check_out_dir() {
|
|
|
|
if [ "$out_dir" = '' ]
|
|
|
|
then
|
|
|
|
error_exit 'output directory should be presented'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -d "$out_dir" ]
|
|
|
|
then
|
|
|
|
log "$out_dir directory will be created"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function parse_opts parses the options list and validates it's combinations.
|
|
|
|
parse_opts() {
|
2021-06-01 13:04:22 +00:00
|
|
|
while getopts "C:c:hO:o:rRuUvV" opt "$@"
|
2021-05-17 12:24:05 +00:00
|
|
|
do
|
|
|
|
case "$opt"
|
|
|
|
in
|
|
|
|
(C)
|
|
|
|
cpu="$OPTARG"
|
|
|
|
;;
|
|
|
|
(c)
|
|
|
|
channel="$OPTARG"
|
|
|
|
;;
|
|
|
|
(h)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
(O)
|
|
|
|
os="$OPTARG"
|
|
|
|
;;
|
|
|
|
(o)
|
|
|
|
out_dir="$OPTARG"
|
|
|
|
;;
|
|
|
|
(R)
|
|
|
|
reinstall='0'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
(U)
|
|
|
|
uninstall='0'
|
|
|
|
;;
|
|
|
|
(r)
|
|
|
|
reinstall='1'
|
|
|
|
;;
|
|
|
|
(u)
|
|
|
|
uninstall='1'
|
|
|
|
;;
|
|
|
|
(V)
|
|
|
|
verbose='0'
|
|
|
|
;;
|
|
|
|
(v)
|
|
|
|
verbose='1'
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
log "bad option $OPTARG"
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
usage
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
esac
|
|
|
|
done
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$uninstall" -eq '1' ] && [ "$reinstall" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
error_exit 'the -r and -u options are mutually exclusive'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function set_channel sets the channel if needed and validates the value.
|
|
|
|
set_channel() {
|
|
|
|
# Validate.
|
|
|
|
case "$channel"
|
|
|
|
in
|
|
|
|
('development'|'edge'|'beta'|'release')
|
|
|
|
# All is well, go on.
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
error_exit \
|
|
|
|
"invalid channel '$channel'
|
|
|
|
supported values are 'development', 'edge', 'beta', and 'release'"
|
|
|
|
;;
|
2020-10-07 18:01:30 +00:00
|
|
|
esac
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Log.
|
|
|
|
log "channel: $channel"
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function set_os sets the os if needed and validates the value.
|
|
|
|
set_os() {
|
|
|
|
# Set if needed.
|
|
|
|
if [ "$os" = '' ]
|
|
|
|
then
|
|
|
|
os="$( uname -s )"
|
|
|
|
case "$os"
|
|
|
|
in
|
2021-06-03 18:04:13 +00:00
|
|
|
('Darwin')
|
|
|
|
os='darwin'
|
2021-05-17 12:24:05 +00:00
|
|
|
;;
|
|
|
|
('FreeBSD')
|
|
|
|
os='freebsd'
|
|
|
|
;;
|
2021-06-03 18:04:13 +00:00
|
|
|
('Linux')
|
|
|
|
os='linux'
|
|
|
|
;;
|
|
|
|
('OpenBSD')
|
|
|
|
os='openbsd'
|
2021-05-17 12:24:05 +00:00
|
|
|
;;
|
2022-02-09 16:51:26 +00:00
|
|
|
(*)
|
|
|
|
error_exit "unsupported operating system: '$os'"
|
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
esac
|
2020-10-07 18:01:30 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Validate.
|
|
|
|
case "$os"
|
|
|
|
in
|
2021-06-03 18:04:13 +00:00
|
|
|
('darwin'|'freebsd'|'linux'|'openbsd')
|
2021-05-17 12:24:05 +00:00
|
|
|
# All right, go on.
|
|
|
|
;;
|
|
|
|
(*)
|
2021-06-01 13:04:22 +00:00
|
|
|
error_exit "unsupported operating system: '$os'"
|
2021-05-17 12:24:05 +00:00
|
|
|
;;
|
|
|
|
esac
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Log.
|
|
|
|
log "operating system: $os"
|
|
|
|
}
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function set_cpu sets the cpu if needed and validates the value.
|
|
|
|
set_cpu() {
|
|
|
|
# Set if needed.
|
|
|
|
if [ "$cpu" = '' ]
|
|
|
|
then
|
|
|
|
cpu="$( uname -m )"
|
|
|
|
case "$cpu"
|
|
|
|
in
|
|
|
|
('x86_64'|'x86-64'|'x64'|'amd64')
|
|
|
|
cpu='amd64'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('i386'|'i486'|'i686'|'i786'|'x86')
|
|
|
|
cpu='386'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('armv5l')
|
|
|
|
cpu='armv5'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('armv6l')
|
|
|
|
cpu='armv6'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('armv7l' | 'armv8l')
|
|
|
|
cpu='armv7'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('aarch64'|'arm64')
|
|
|
|
cpu='arm64'
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
('mips'|'mips64')
|
|
|
|
if is_little_endian
|
|
|
|
then
|
|
|
|
cpu="${cpu}le"
|
|
|
|
fi
|
|
|
|
cpu="${cpu}_softfloat"
|
2020-10-07 18:01:30 +00:00
|
|
|
;;
|
2022-02-09 16:51:26 +00:00
|
|
|
(*)
|
|
|
|
error_exit "unsupported cpu type: $cpu"
|
|
|
|
;;
|
2021-05-17 12:24:05 +00:00
|
|
|
esac
|
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Validate.
|
|
|
|
case "$cpu"
|
|
|
|
in
|
|
|
|
('amd64'|'386'|'armv5'|'armv6'|'armv7'|'arm64')
|
|
|
|
# All right, go on.
|
|
|
|
;;
|
|
|
|
('mips64le_softfloat'|'mips64_softfloat'|'mipsle_softfloat'|'mips_softfloat')
|
|
|
|
# That's right too.
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
error_exit "unsupported cpu type: $cpu"
|
|
|
|
;;
|
2020-10-07 18:01:30 +00:00
|
|
|
esac
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Log.
|
|
|
|
log "cpu type: $cpu"
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 13:04:22 +00:00
|
|
|
# Function fix_darwin performs some configuration changes for macOS if needed.
|
|
|
|
#
|
|
|
|
# TODO(a.garipov): Remove after the final v0.107.0 release.
|
|
|
|
#
|
|
|
|
# See https://github.com/AdguardTeam/AdGuardHome/issues/2443.
|
2021-05-17 12:24:05 +00:00
|
|
|
fix_darwin() {
|
2021-06-01 13:04:22 +00:00
|
|
|
if [ "$os" != 'darwin' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
2020-10-07 18:01:30 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
# Set the package extension.
|
|
|
|
pkg_ext='zip'
|
|
|
|
|
2022-01-11 18:33:14 +00:00
|
|
|
# It is important to install AdGuard Home into the /Applications directory
|
|
|
|
# on macOS. Otherwise, it may grant not enough privileges to the AdGuard
|
|
|
|
# Home.
|
2021-05-17 12:24:05 +00:00
|
|
|
out_dir='/Applications'
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function fix_freebsd performs some fixes to make it work on FreeBSD.
|
|
|
|
fix_freebsd() {
|
|
|
|
if ! [ "$os" = 'freebsd' ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
rcd='/usr/local/etc/rc.d'
|
|
|
|
readonly rcd
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
if ! [ -d "$rcd" ]
|
|
|
|
then
|
|
|
|
mkdir "$rcd"
|
2020-10-07 18:01:30 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-02-09 16:51:26 +00:00
|
|
|
# download_curl uses curl(1) to download a file. The first argument is the URL.
|
|
|
|
# The second argument is optional and is the output file.
|
|
|
|
download_curl() {
|
|
|
|
curl_output="${2:-}"
|
|
|
|
if [ "$curl_output" = '' ]
|
|
|
|
then
|
|
|
|
curl -L -S -s "$1"
|
|
|
|
else
|
|
|
|
curl -L -S -o "$curl_output" -s "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# download_wget uses wget(1) to download a file. The first argument is the URL.
|
|
|
|
# The second argument is optional and is the output file.
|
|
|
|
download_wget() {
|
|
|
|
wget_output="${2:--}"
|
|
|
|
|
|
|
|
wget --no-verbose -O "$wget_output" "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function set_download_func sets the appropriate function for downloading
|
|
|
|
# files.
|
|
|
|
set_download_func() {
|
|
|
|
if is_command 'curl'
|
|
|
|
then
|
|
|
|
# Go on and use the default, download_curl.
|
|
|
|
return 0
|
|
|
|
elif is_command 'wget'
|
|
|
|
then
|
|
|
|
download_func='download_wget'
|
|
|
|
else
|
|
|
|
error_exit "either curl or wget is required to install AdGuard Home via this script"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
# Function set_sudo_cmd sets the appropriate command to run a command under
|
|
|
|
# superuser privileges.
|
|
|
|
set_sudo_cmd() {
|
|
|
|
case "$os"
|
|
|
|
in
|
|
|
|
('openbsd')
|
|
|
|
sudo_cmd='doas'
|
|
|
|
;;
|
|
|
|
('darwin'|'freebsd'|'linux')
|
|
|
|
# Go on and use the default, sudo.
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
error_exit "unsupported operating system: '$os'"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function configure sets the script's configuration.
|
|
|
|
configure() {
|
|
|
|
set_channel
|
|
|
|
set_os
|
|
|
|
set_cpu
|
|
|
|
fix_darwin
|
2022-02-09 16:51:26 +00:00
|
|
|
set_download_func
|
2021-06-03 18:04:13 +00:00
|
|
|
set_sudo_cmd
|
2021-05-17 12:24:05 +00:00
|
|
|
check_out_dir
|
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
pkg_name="AdGuardHome_${os}_${cpu}.${pkg_ext}"
|
|
|
|
url="https://static.adguard.com/adguardhome/${channel}/${pkg_name}"
|
|
|
|
agh_dir="${out_dir}/AdGuardHome"
|
|
|
|
readonly pkg_name url agh_dir
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
log "AdGuard Home will be installed into $agh_dir"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function is_root checks for root privileges to be granted.
|
|
|
|
is_root() {
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$( id -u )" -eq '0' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
log 'script is executed with root privileges'
|
|
|
|
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
if is_command "$sudo_cmd"
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
log 'note that AdGuard Home requires root privileges to install using this script'
|
|
|
|
|
2020-10-07 18:01:30 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
error_exit \
|
|
|
|
'root privileges are required to install AdGuard Home using this script
|
|
|
|
please, restart it with root privileges'
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 11:51:56 +00:00
|
|
|
# Function rerun_with_root downloads the script, runs it with root privileges,
|
|
|
|
# and exits the current script. It passes the necessary configuration of the
|
|
|
|
# current script to the child script.
|
2021-05-17 12:24:05 +00:00
|
|
|
#
|
|
|
|
# TODO(e.burkov): Try to avoid restarting.
|
|
|
|
rerun_with_root() {
|
2021-05-19 17:31:20 +00:00
|
|
|
script_url=\
|
2021-05-17 12:24:05 +00:00
|
|
|
'https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh'
|
2021-05-19 17:31:20 +00:00
|
|
|
readonly script_url
|
2021-05-17 12:24:05 +00:00
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
r='-R'
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$reinstall" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
2021-06-03 18:04:13 +00:00
|
|
|
r='-r'
|
2021-05-17 12:24:05 +00:00
|
|
|
fi
|
2021-06-02 11:51:56 +00:00
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
u='-U'
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$uninstall" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
2021-06-03 18:04:13 +00:00
|
|
|
u='-u'
|
2021-05-17 12:24:05 +00:00
|
|
|
fi
|
2021-06-02 11:51:56 +00:00
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
v='-V'
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$verbose" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
2021-06-03 18:04:13 +00:00
|
|
|
v='-v'
|
2021-05-17 12:24:05 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
readonly r u v
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
log 'restarting with root privileges'
|
|
|
|
|
2022-02-09 16:51:26 +00:00
|
|
|
# Group curl/wget together with an echo, so that if the former fails before
|
|
|
|
# producing any output, the latter prints an exit command for the following
|
|
|
|
# shell to execute to prevent it from getting an empty input and exiting
|
|
|
|
# with a zero code in that case.
|
|
|
|
{ "$download_func" "$script_url" || echo 'exit 1'; }\
|
2021-06-03 18:04:13 +00:00
|
|
|
| $sudo_cmd sh -s -- -c "$channel" -C "$cpu" -O "$os" -o "$out_dir" "$r" "$u" "$v"
|
2021-06-02 11:51:56 +00:00
|
|
|
|
2022-01-26 16:19:16 +00:00
|
|
|
# Exit the script. Since if the code of the previous pipeline is non-zero,
|
|
|
|
# the execution won't reach this point thanks to set -e, exit with zero.
|
2021-06-02 11:51:56 +00:00
|
|
|
exit 0
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function download downloads the file from the URL and saves it to the
|
|
|
|
# specified filepath.
|
|
|
|
download() {
|
|
|
|
log "downloading package from $url -> $pkg_name"
|
|
|
|
|
2022-02-09 16:51:26 +00:00
|
|
|
if ! "$download_func" "$url" "$pkg_name"
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
error_exit "cannot download the package from $url into $pkg_name"
|
|
|
|
fi
|
2021-09-21 11:45:59 +00:00
|
|
|
|
|
|
|
log "successfully downloaded $pkg_name"
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function unpack unpacks the passed archive depending on it's extension.
|
|
|
|
unpack() {
|
|
|
|
log "unpacking package from $pkg_name into $out_dir"
|
|
|
|
if ! mkdir -p "$out_dir"
|
|
|
|
then
|
2021-09-21 11:45:59 +00:00
|
|
|
error_exit "cannot create directory $out_dir"
|
2021-05-17 12:24:05 +00:00
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
case "$pkg_ext"
|
|
|
|
in
|
|
|
|
('zip')
|
|
|
|
unzip "$pkg_name" -d "$out_dir"
|
|
|
|
;;
|
|
|
|
('tar.gz')
|
|
|
|
tar -C "$out_dir" -f "$pkg_name" -x -z
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
error_exit "unexpected package extension: '$pkg_ext'"
|
|
|
|
;;
|
|
|
|
esac
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-09-22 15:18:23 +00:00
|
|
|
log "successfully unpacked, contents: $( echo; ls -l -A "$agh_dir" )"
|
2021-09-21 11:45:59 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
rm "$pkg_name"
|
|
|
|
}
|
2021-01-31 21:49:04 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Function handle_existing detects the existing AGH installation and takes care
|
|
|
|
# of removing it if needed.
|
|
|
|
handle_existing() {
|
|
|
|
if ! [ -d "$agh_dir" ]
|
|
|
|
then
|
|
|
|
log 'no need to uninstall'
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$uninstall" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
fi
|
2021-01-31 21:14:47 +00:00
|
|
|
|
2022-02-09 16:51:26 +00:00
|
|
|
if [ "$( ls -1 -A "$agh_dir" )" != '' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
log 'the existing AdGuard Home installation is detected'
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-06-01 13:04:22 +00:00
|
|
|
if [ "$reinstall" -ne '1' ] && [ "$uninstall" -ne '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
error_exit \
|
2021-08-16 16:22:09 +00:00
|
|
|
"to reinstall/uninstall the AdGuard Home using this script specify one of the '-r' or '-u' flags"
|
2021-05-17 12:24:05 +00:00
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-12-27 16:12:40 +00:00
|
|
|
# TODO(e.burkov): Remove the stop once v0.107.1 released.
|
2021-08-16 16:22:09 +00:00
|
|
|
if ( cd "$agh_dir" && ! ./AdGuardHome -s stop || ! ./AdGuardHome -s uninstall )
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
# It doesn't terminate the script since it is possible
|
|
|
|
# that AGH just not installed as service but appearing
|
|
|
|
# in the directory.
|
|
|
|
log "cannot uninstall AdGuard Home from $agh_dir"
|
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
rm -r "$agh_dir"
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
log 'AdGuard Home was successfully uninstalled'
|
|
|
|
fi
|
|
|
|
|
2021-05-19 17:31:20 +00:00
|
|
|
if [ "$uninstall" -eq '1' ]
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function install_service tries to install AGH as service.
|
|
|
|
install_service() {
|
2022-01-26 16:19:16 +00:00
|
|
|
if ( cd "$agh_dir" && ./AdGuardHome -s install )
|
2021-05-17 12:24:05 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-09-21 11:45:59 +00:00
|
|
|
log "installation failed, removing $agh_dir"
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
rm -r "$agh_dir"
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
# Some devices detected to have armv7 CPU face the compatibility
|
|
|
|
# issues with actual armv7 builds. We should try to install the
|
|
|
|
# armv5 binary instead.
|
|
|
|
#
|
|
|
|
# See https://github.com/AdguardTeam/AdGuardHome/issues/2542.
|
|
|
|
if [ "$cpu" = 'armv7' ]
|
|
|
|
then
|
|
|
|
cpu='armv5'
|
|
|
|
reinstall='1'
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
log "trying to use $cpu cpu"
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
rerun_with_root
|
|
|
|
fi
|
2020-10-07 18:01:30 +00:00
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
error_exit 'cannot install AdGuardHome as a service'
|
2020-10-07 18:01:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Entrypoint
|
|
|
|
|
|
|
|
# Set default values of configuration variables.
|
|
|
|
channel='release'
|
|
|
|
reinstall='0'
|
|
|
|
uninstall='0'
|
|
|
|
verbose='0'
|
|
|
|
cpu=''
|
|
|
|
os=''
|
|
|
|
out_dir='/opt'
|
|
|
|
pkg_ext='tar.gz'
|
2022-02-09 16:51:26 +00:00
|
|
|
download_func='download_curl'
|
2021-06-03 18:04:13 +00:00
|
|
|
sudo_cmd='sudo'
|
|
|
|
|
2021-06-01 13:04:22 +00:00
|
|
|
parse_opts "$@"
|
2021-05-17 12:24:05 +00:00
|
|
|
|
|
|
|
echo 'starting AdGuard Home installation script'
|
|
|
|
|
|
|
|
configure
|
|
|
|
check_required
|
|
|
|
|
|
|
|
if ! is_root
|
|
|
|
then
|
|
|
|
rerun_with_root
|
|
|
|
fi
|
|
|
|
# Needs rights.
|
|
|
|
fix_freebsd
|
|
|
|
|
|
|
|
handle_existing
|
|
|
|
|
|
|
|
download
|
|
|
|
unpack
|
|
|
|
|
|
|
|
install_service
|
|
|
|
|
|
|
|
echo "\
|
|
|
|
AdGuard Home is now installed and running
|
|
|
|
you can control the service status with the following commands:
|
2021-06-03 18:04:13 +00:00
|
|
|
$sudo_cmd ${agh_dir}/AdGuardHome -s start|stop|restart|status|install|uninstall"
|