Add --url option to download/extract adguard archive

This commit is contained in:
gardouille 2022-01-27 13:46:40 +01:00
parent 42356201ca
commit 15589b0a0c
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 49 additions and 3 deletions

View File

@ -49,6 +49,9 @@ EXAMPLE:
- Specify the path to AdGuardHome binary
check.adguard.update --bin /home/adguard/AdGuardHome/AdGuardHome
- Download ARMv7 version if it's a newer version
check.adguard.update --url "https://static.adguard.com/adguardhome/release/AdGuardHome_linux_armv7.tar.gz"
OPTIONS:
-b,--bin
Specify the path of AdGuard Home's binary
@ -58,6 +61,11 @@ OPTIONS:
Set the path to the temp file that will be create and
that should be monitored (default: ${ADGUARD_NEW_VERSION_FILE_DEFAULT}).
-u,--url
Set the URL to use to download the last version of AdGuard Home (default: empty).
See the list of possible URLs on :
https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started
-d,--debug
Enable debug messages.
@ -116,6 +124,23 @@ Test var: ${1}."
}
# }}}
is_var_nonempty() { # {{{
local_var_nonempty="${1}"
## Return False by default
return_var_nonempty="1"
debug_message "is_var_nonempty \
Test var: ${1}."
### Test if var lenght is nonzero and set return value to True
[ -n "${local_var_nonempty}" ] && return_var_nonempty="0"
unset local_var_nonempty
return "${return_var_nonempty}"
}
# }}}
define_vars() { # {{{
## If adguard_bin wasn't defined (argument,...) {{{
@ -146,26 +171,41 @@ main() { # {{{
## Define all vars according to selected options
define_vars
## Test adguard_current_version
## Test adguard_current_version {{{
## AND exit with error 2
is_var_empty "${adguard_current_version}" \
&& error_message "adguard_current_version seems empty (${adguard_current_version})." 2
## }}}
## Test adguard_new_version
## Test adguard_new_version {{{
## AND exit with error 3
is_var_empty "${adguard_new_version}" \
&& error_message "adguard_new_version seems empty (${adguard_new_version}), exit without error." 3
## }}}
## Check if the current version is the last one {{{
if [ "${adguard_current_version}" != "${adguard_new_version}" ]; then
debug_message "Test AdGuard Home version \
Current version (${adguard_current_version}) and new one (${adguard_new_version}) seems to be different."
## Create a temp file to monitor
## Create a temp file to monitor {{{
debug_message "Test AdGuard Home version \
Create ${adguard_new_version_file} temp file to monitore."
touch -- "${adguard_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for AdGuard Home (current: ${adguard_current_version}): ${adguard_new_version}." >> "${adguard_new_version_file}"
## }}}
## If an URL was set {{{
if is_var_nonempty "${adguard_new_version_url}"; then
debug_message "Download AdGuard Home new version \
Download new archive from ${adguard_new_version_url} and extract to /tmp/ ."
#wget --quiet "${adguard_new_version_url}" -O - | tar xz --transform="s/AdGuardHome/AdGuardHome.to.upgrade/g" --strip-components 2
wget --quiet "${adguard_new_version_url}" -O - | tar --extract --gzip --directory=/tmp --strip-components 2 ./AdGuardHome
#mv AdGuardHome.to.upgrade "${adguard_bin}.to.upgrade"
mv --force /tmp/AdGuardHome "${adguard_bin}.to.upgrade" \
|| error_message "Can't move /tmp/AdGuardHome to ${adguard_bin}.to.upgrade ." 4
fi
## }}}
else
debug_message "Test AdGuard Home version \
@ -215,6 +255,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Define adguard_new_version_file
adguard_new_version_file="${1}"
;;
-u|--url ) ## Set new version URL
## Move to the next argument
shift
## Define adguard_new_version_url
adguard_new_version_url="${1}"
;;
-- ) ## End of options list
## End the while loop
break