mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-21 20:45:33 +03:00
Pull request: all: imp scripts
Merge in DNS/adguard-home from imp-sh to master Squashed commit of the following: commit 477832e11eca2ef7ac0071b5da938dacb2ed617d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 19 20:24:34 2021 +0300 scripts: rm dbg commit dbb4b8c783f607781b980dcd57d78085c9022e72 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 19 20:21:20 2021 +0300 all: imp code, compat, docs commit e6e4375d67ad1c213efb04411e3ba0bc6293f936 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 19 19:33:48 2021 +0300 all: imp scripts
This commit is contained in:
parent
b3d28408cd
commit
6f7fd33afd
17 changed files with 473 additions and 321 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -46,7 +46,7 @@
|
||||||
'restore-keys': '${{ runner.os }}-go-'
|
'restore-keys': '${{ runner.os }}-go-'
|
||||||
- 'name': 'Get npm cache directory'
|
- 'name': 'Get npm cache directory'
|
||||||
'id': 'npm-cache'
|
'id': 'npm-cache'
|
||||||
'run': 'echo "::set-output name=dir::$(npm config get cache)"'
|
'run': 'echo "::set-output name=dir::$( npm config get cache )"'
|
||||||
- 'name': 'Set up npm cache'
|
- 'name': 'Set up npm cache'
|
||||||
'uses': 'actions/cache@v2'
|
'uses': 'actions/cache@v2'
|
||||||
'with':
|
'with':
|
||||||
|
|
54
HACKING.md
54
HACKING.md
|
@ -1,9 +1,9 @@
|
||||||
# AdGuard Home Developer Guidelines
|
# AdGuard Home Developer Guidelines
|
||||||
|
|
||||||
As of **March 2021**, following this document is obligatory for all new code.
|
Following this document is obligatory for all new code. Some of the rules
|
||||||
Some of the rules aren't enforced as thoroughly or remain broken in old code,
|
aren't enforced as thoroughly or remain broken in old code, but this is still
|
||||||
but this is still the place to find out about what we **want** our code to look
|
the place to find out about what we **want** our code to look like and how to
|
||||||
like and how to improve it.
|
improve it.
|
||||||
|
|
||||||
The rules are mostly sorted in the alphabetical order.
|
The rules are mostly sorted in the alphabetical order.
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ The rules are mostly sorted in the alphabetical order.
|
||||||
* [Recommended Reading](#recommended-reading)
|
* [Recommended Reading](#recommended-reading)
|
||||||
* [Markdown](#markdown)
|
* [Markdown](#markdown)
|
||||||
* [Shell Scripting](#shell-scripting)
|
* [Shell Scripting](#shell-scripting)
|
||||||
|
* [Shell Conditionals](#shell-cond)
|
||||||
* [Text, Including Comments](#text-including-comments)
|
* [Text, Including Comments](#text-including-comments)
|
||||||
* [YAML](#yaml)
|
* [YAML](#yaml)
|
||||||
|
|
||||||
|
@ -315,6 +316,26 @@ on GitHub and most other Markdown renderers. -->
|
||||||
|
|
||||||
* Avoid spaces between patterns of the same `case` condition.
|
* Avoid spaces between patterns of the same `case` condition.
|
||||||
|
|
||||||
|
* `export` and `readonly` should be used separately from variable assignment,
|
||||||
|
because otherwise failures in command substitutions won't stop the script.
|
||||||
|
That is, do this:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
X="$( echo 42 )"
|
||||||
|
export X
|
||||||
|
```
|
||||||
|
|
||||||
|
And **not** this:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Bad!
|
||||||
|
export X="$( echo 42 )"
|
||||||
|
```
|
||||||
|
|
||||||
|
* If a binary value is needed, use `0` for `false`, and `1` for `true`.
|
||||||
|
|
||||||
|
* Mark every variable that shouldn't change later as `readonly`.
|
||||||
|
|
||||||
* Prefer `'raw strings'` to `"double quoted strings"` whenever possible.
|
* Prefer `'raw strings'` to `"double quoted strings"` whenever possible.
|
||||||
|
|
||||||
* Put spaces within `$( cmd )`, `$(( expr ))`, and `{ cmd; }`.
|
* Put spaces within `$( cmd )`, `$(( expr ))`, and `{ cmd; }`.
|
||||||
|
@ -330,8 +351,6 @@ on GitHub and most other Markdown renderers. -->
|
||||||
* UPPERCASE names for external exported variables, lowercase for local,
|
* UPPERCASE names for external exported variables, lowercase for local,
|
||||||
unexported ones.
|
unexported ones.
|
||||||
|
|
||||||
* Use `readonly` liberally.
|
|
||||||
|
|
||||||
* Use `set -e -f -u` and also `set -x` in verbose mode.
|
* Use `set -e -f -u` and also `set -x` in verbose mode.
|
||||||
|
|
||||||
* Use the `"$var"` form instead of the `$var` form, unless word splitting is
|
* Use the `"$var"` form instead of the `$var` form, unless word splitting is
|
||||||
|
@ -355,14 +374,23 @@ on GitHub and most other Markdown renderers. -->
|
||||||
dir="${TOP_DIR}"/sub
|
dir="${TOP_DIR}"/sub
|
||||||
```
|
```
|
||||||
|
|
||||||
* When using `test` (aka `[`), spell compound conditions with `&&`, `||`, and
|
### <a id="shell-cond" href="#shell-cond">Shell Conditionals</a>
|
||||||
`!` **outside** of `test` instead of `-a`, `-o`, and `!` inside of `test`
|
|
||||||
correspondingly. The latter ones are pretty much deprecated in POSIX.
|
Guidelines and agreements for using command `test`, also known as `[`:
|
||||||
Also, prefer `!= ''` form instead of `-n` to check if string is empty.
|
|
||||||
|
* Prefer the `!= ''` form instead of using `-n` to check if string is empty.
|
||||||
|
|
||||||
|
* Spell compound conditions with `&&`, `||`, and `!` **outside** of `test`
|
||||||
|
instead of `-a`, `-o`, and `!` **inside** of `test` correspondingly. The
|
||||||
|
latter ones are pretty much deprecated in POSIX.
|
||||||
|
|
||||||
|
See also: “[Problems With the `test` Builtin: What Does `-a` Mean?][test]”.
|
||||||
|
|
||||||
|
* Use `=` for strings and `-eq` for numbers to catch typing errors.
|
||||||
|
|
||||||
|
[test]: https://www.oilshell.org/blog/2017/08/31.html
|
||||||
|
|
||||||
See also: “[Problems With the `test` Builtin: What Does `-a` Mean?]”.
|
|
||||||
|
|
||||||
[Problems With the `test` Builtin: What Does `-a` Mean?]: https://www.oilshell.org/blog/2017/08/31.html
|
|
||||||
|
|
||||||
## <a id="text-including-comments" href="#text-including-comments">Text, Including Comments</a>
|
## <a id="text-including-comments" href="#text-including-comments">Text, Including Comments</a>
|
||||||
|
|
||||||
|
@ -400,6 +428,8 @@ on GitHub and most other Markdown renderers. -->
|
||||||
// TODO(usr1, usr2): Fix the frobulation issue.
|
// TODO(usr1, usr2): Fix the frobulation issue.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## <a id="yaml" href="#yaml">YAML</a>
|
## <a id="yaml" href="#yaml">YAML</a>
|
||||||
|
|
||||||
* **TODO(a.garipov):** Define naming conventions for schema names in our
|
* **TODO(a.garipov):** Define naming conventions for schema names in our
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -106,3 +106,5 @@ go-os-check:
|
||||||
|
|
||||||
openapi-lint: ; cd ./openapi/ && $(YARN) test
|
openapi-lint: ; cd ./openapi/ && $(YARN) test
|
||||||
openapi-show: ; cd ./openapi/ && $(YARN) start
|
openapi-show: ; cd ./openapi/ && $(YARN) start
|
||||||
|
|
||||||
|
txt-lint: ; $(ENV) "$(SHELL)" ./scripts/make/txt-lint.sh
|
||||||
|
|
|
@ -152,7 +152,9 @@
|
||||||
|
|
||||||
cd ./dist/
|
cd ./dist/
|
||||||
|
|
||||||
export CHANNEL="${bamboo.channel}"
|
CHANNEL="${bamboo.channel}"
|
||||||
|
export CHANNEL
|
||||||
|
|
||||||
../bamboo-deploy-publisher/deploy.sh adguard-home-"$CHANNEL"
|
../bamboo-deploy-publisher/deploy.sh adguard-home-"$CHANNEL"
|
||||||
'final-tasks':
|
'final-tasks':
|
||||||
- 'clean'
|
- 'clean'
|
||||||
|
|
|
@ -2,22 +2,27 @@
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
if [ "$(git diff --cached --name-only -- 'client/*.js')" ]
|
if [ "$( git diff --cached --name-only -- 'client/*.js' )" ]
|
||||||
then
|
then
|
||||||
make js-lint js-test
|
make js-lint js-test
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(git diff --cached --name-only -- 'client2/*.js' 'client2/*.ts' 'client2/*.tsx')" ]
|
if [ "$( git diff --cached --name-only -- 'client2/*.js' 'client2/*.ts' 'client2/*.tsx' )" ]
|
||||||
then
|
then
|
||||||
make js-beta-lint js-beta-test
|
make js-beta-lint js-beta-test
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(git diff --cached --name-only -- '*.go' 'go.mod')" ]
|
if [ "$( git diff --cached --name-only -- '*.go' '*.mod' '*.sh' 'Makefile' )" ]
|
||||||
then
|
then
|
||||||
make go-os-check go-lint go-test
|
make go-os-check go-lint go-test
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(git diff --cached --name-only -- './openapi/openapi.yaml')" ]
|
if [ "$( git diff --cached --name-only -- '*.md' '*.yaml' '*.yml' )" ]
|
||||||
|
then
|
||||||
|
make txt-lint
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$( git diff --cached --name-only -- './openapi/openapi.yaml' )" ]
|
||||||
then
|
then
|
||||||
make openapi-lint
|
make openapi-lint
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -46,8 +46,9 @@ is_little_endian() {
|
||||||
# unzip (macOS) / tar (other unices)
|
# unzip (macOS) / tar (other unices)
|
||||||
#
|
#
|
||||||
check_required() {
|
check_required() {
|
||||||
readonly required_darwin="unzip"
|
required_darwin="unzip"
|
||||||
readonly required_unix="tar"
|
required_unix="tar"
|
||||||
|
readonly required_darwin required_unix
|
||||||
|
|
||||||
# Split with space.
|
# Split with space.
|
||||||
required="curl"
|
required="curl"
|
||||||
|
@ -132,7 +133,7 @@ parse_opts() {
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$uninstall" = '1' ] && [ "$reinstall" = '1' ]
|
if [ "$uninstall" -eq '1' ] && [ "$reinstall" -eq '1' ]
|
||||||
then
|
then
|
||||||
error_exit 'the -r and -u options are mutually exclusive'
|
error_exit 'the -r and -u options are mutually exclusive'
|
||||||
fi
|
fi
|
||||||
|
@ -277,7 +278,9 @@ fix_freebsd() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly rcd='/usr/local/etc/rc.d'
|
rcd='/usr/local/etc/rc.d'
|
||||||
|
readonly rcd
|
||||||
|
|
||||||
if ! [ -d "$rcd" ]
|
if ! [ -d "$rcd" ]
|
||||||
then
|
then
|
||||||
mkdir "$rcd"
|
mkdir "$rcd"
|
||||||
|
@ -292,16 +295,17 @@ configure() {
|
||||||
fix_darwin
|
fix_darwin
|
||||||
check_out_dir
|
check_out_dir
|
||||||
|
|
||||||
readonly pkg_name="AdGuardHome_${os}_${cpu}.${pkg_ext}"
|
pkg_name="AdGuardHome_${os}_${cpu}.${pkg_ext}"
|
||||||
readonly url="https://static.adguard.com/adguardhome/${channel}/${pkg_name}"
|
url="https://static.adguard.com/adguardhome/${channel}/${pkg_name}"
|
||||||
readonly agh_dir="${out_dir}/AdGuardHome"
|
agh_dir="${out_dir}/AdGuardHome"
|
||||||
|
readonly pkg_name url agh_dir
|
||||||
|
|
||||||
log "AdGuard Home will be installed into $agh_dir"
|
log "AdGuard Home will be installed into $agh_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function is_root checks for root privileges to be granted.
|
# Function is_root checks for root privileges to be granted.
|
||||||
is_root() {
|
is_root() {
|
||||||
if [ "$( id -u )" = '0' ]
|
if [ "$( id -u )" -eq '0' ]
|
||||||
then
|
then
|
||||||
log 'script is executed with root privileges'
|
log 'script is executed with root privileges'
|
||||||
|
|
||||||
|
@ -325,24 +329,26 @@ please, restart it with root privileges'
|
||||||
#
|
#
|
||||||
# TODO(e.burkov): Try to avoid restarting.
|
# TODO(e.burkov): Try to avoid restarting.
|
||||||
rerun_with_root() {
|
rerun_with_root() {
|
||||||
readonly script_url=\
|
script_url=\
|
||||||
'https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh'
|
'https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh'
|
||||||
|
readonly script_url
|
||||||
|
|
||||||
flags=''
|
flags=''
|
||||||
if [ "$reinstall" = '1' ]
|
if [ "$reinstall" -eq '1' ]
|
||||||
then
|
then
|
||||||
flags="${flags} -r"
|
flags="${flags} -r"
|
||||||
fi
|
fi
|
||||||
if [ "$uninstall" = '1' ]
|
if [ "$uninstall" -eq '1' ]
|
||||||
then
|
then
|
||||||
flags="${flags} -u"
|
flags="${flags} -u"
|
||||||
fi
|
fi
|
||||||
if [ "$verbose" = '1' ]
|
if [ "$verbose" -eq '1' ]
|
||||||
then
|
then
|
||||||
flags="${flags} -v"
|
flags="${flags} -v"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly opts="-c $channel -C $cpu -O $os -o $out_dir $flags"
|
opts="-c $channel -C $cpu -O $os -o $out_dir $flags"
|
||||||
|
readonly opts
|
||||||
|
|
||||||
log 'restarting with root privileges'
|
log 'restarting with root privileges'
|
||||||
|
|
||||||
|
@ -397,7 +403,7 @@ handle_existing() {
|
||||||
then
|
then
|
||||||
log 'no need to uninstall'
|
log 'no need to uninstall'
|
||||||
|
|
||||||
if [ "$uninstall" = '1' ]
|
if [ "$uninstall" -eq '1' ]
|
||||||
then
|
then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -428,7 +434,7 @@ handle_existing() {
|
||||||
log 'AdGuard Home was successfully uninstalled'
|
log 'AdGuard Home was successfully uninstalled'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$uninstall" = '1' ]
|
if [ "$uninstall" -eq '1' ]
|
||||||
then
|
then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -14,58 +14,65 @@ fi
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
# Require these to be set. The channel value is validated later.
|
# Require these to be set. The channel value is validated later.
|
||||||
readonly channel="$CHANNEL"
|
channel="$CHANNEL"
|
||||||
readonly commit="$COMMIT"
|
commit="$COMMIT"
|
||||||
readonly dist_dir="$DIST_DIR"
|
dist_dir="$DIST_DIR"
|
||||||
|
readonly channel commit dist_dir
|
||||||
|
|
||||||
if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ]
|
if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ]
|
||||||
then
|
then
|
||||||
readonly version="$(sh ./scripts/make/version.sh)"
|
version="$( sh ./scripts/make/version.sh )"
|
||||||
else
|
else
|
||||||
readonly version="$VERSION"
|
version="$VERSION"
|
||||||
fi
|
fi
|
||||||
|
readonly version
|
||||||
|
|
||||||
echo $version
|
echo $version
|
||||||
|
|
||||||
# Allow users to use sudo.
|
# Allow users to use sudo.
|
||||||
readonly sudo_cmd="${SUDO:-}"
|
sudo_cmd="${SUDO:-}"
|
||||||
|
readonly sudo_cmd
|
||||||
|
|
||||||
readonly docker_platforms="\
|
docker_platforms="\
|
||||||
linux/386,\
|
linux/386,\
|
||||||
linux/amd64,\
|
linux/amd64,\
|
||||||
linux/arm/v6,\
|
linux/arm/v6,\
|
||||||
linux/arm/v7,\
|
linux/arm/v7,\
|
||||||
linux/arm64,\
|
linux/arm64,\
|
||||||
linux/ppc64le"
|
linux/ppc64le"
|
||||||
|
readonly docker_platforms
|
||||||
|
|
||||||
readonly build_date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
|
build_date="$( date -u +'%Y-%m-%dT%H:%M:%SZ' )"
|
||||||
|
readonly build_date
|
||||||
|
|
||||||
# Set DOCKER_IMAGE_NAME to 'adguard/adguard-home' if you want (and are
|
# Set DOCKER_IMAGE_NAME to 'adguard/adguard-home' if you want (and are allowed)
|
||||||
# allowed) to push to DockerHub.
|
# to push to DockerHub.
|
||||||
readonly docker_image_name="${DOCKER_IMAGE_NAME:-adguardhome-dev}"
|
docker_image_name="${DOCKER_IMAGE_NAME:-adguardhome-dev}"
|
||||||
|
readonly docker_image_name
|
||||||
|
|
||||||
# Set DOCKER_OUTPUT to 'type=image,name=adguard/adguard-home,push=true'
|
# Set DOCKER_OUTPUT to 'type=image,name=adguard/adguard-home,push=true' if you
|
||||||
# if you want (and are allowed) to push to DockerHub.
|
# want (and are allowed) to push to DockerHub.
|
||||||
readonly docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}"
|
docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}"
|
||||||
|
readonly docker_output
|
||||||
|
|
||||||
case "$channel"
|
case "$channel"
|
||||||
in
|
in
|
||||||
('release')
|
('release')
|
||||||
readonly docker_image_full_name="${docker_image_name}:${version}"
|
docker_image_full_name="${docker_image_name}:${version}"
|
||||||
readonly docker_tags="--tag ${docker_image_name}:latest"
|
docker_tags="--tag ${docker_image_name}:latest"
|
||||||
;;
|
;;
|
||||||
('beta')
|
('beta')
|
||||||
readonly docker_image_full_name="${docker_image_name}:${version}"
|
docker_image_full_name="${docker_image_name}:${version}"
|
||||||
readonly docker_tags="--tag ${docker_image_name}:beta"
|
docker_tags="--tag ${docker_image_name}:beta"
|
||||||
;;
|
;;
|
||||||
('edge')
|
('edge')
|
||||||
# Don't set the version tag when pushing to the edge channel.
|
# Don't set the version tag when pushing to the edge channel.
|
||||||
readonly docker_image_full_name="${docker_image_name}:edge"
|
docker_image_full_name="${docker_image_name}:edge"
|
||||||
readonly docker_tags=''
|
docker_tags=''
|
||||||
;;
|
;;
|
||||||
('development')
|
('development')
|
||||||
readonly docker_image_full_name="${docker_image_name}"
|
docker_image_full_name="${docker_image_name}"
|
||||||
readonly docker_tags=''
|
docker_tags=''
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
echo "invalid channel '$channel', supported values are\
|
echo "invalid channel '$channel', supported values are\
|
||||||
|
@ -73,11 +80,14 @@ in
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
readonly docker_image_full_name docker_tags
|
||||||
|
|
||||||
|
# Copy the binaries into a new directory under new names, so that it's eaiser to
|
||||||
|
# COPY them later. DO NOT remove the trailing underscores. See file
|
||||||
|
# scripts/make/Dockerfile.
|
||||||
|
dist_docker="${dist_dir}/docker"
|
||||||
|
readonly dist_docker
|
||||||
|
|
||||||
# Copy the binaries into a new directory under new names, so that it's
|
|
||||||
# eaiser to COPY them later. DO NOT remove the trailing underscores.
|
|
||||||
# See scripts/make/Dockerfile.
|
|
||||||
readonly dist_docker="${dist_dir}/docker"
|
|
||||||
mkdir -p "$dist_docker"
|
mkdir -p "$dist_docker"
|
||||||
cp "${dist_dir}/AdGuardHome_linux_386/AdGuardHome/AdGuardHome"\
|
cp "${dist_dir}/AdGuardHome_linux_386/AdGuardHome/AdGuardHome"\
|
||||||
"${dist_docker}/AdGuardHome_linux_386_"
|
"${dist_docker}/AdGuardHome_linux_386_"
|
||||||
|
@ -92,8 +102,8 @@ cp "${dist_dir}/AdGuardHome_linux_arm_7/AdGuardHome/AdGuardHome"\
|
||||||
cp "${dist_dir}/AdGuardHome_linux_ppc64le/AdGuardHome/AdGuardHome"\
|
cp "${dist_dir}/AdGuardHome_linux_ppc64le/AdGuardHome/AdGuardHome"\
|
||||||
"${dist_docker}/AdGuardHome_linux_ppc64le_"
|
"${dist_docker}/AdGuardHome_linux_ppc64le_"
|
||||||
|
|
||||||
# Don't use quotes with $docker_tags and $debug_flags because we want
|
# Don't use quotes with $docker_tags and $debug_flags because we want word
|
||||||
# word splitting and or an empty space if tags are empty.
|
# splitting and or an empty space if tags are empty.
|
||||||
$sudo_cmd docker\
|
$sudo_cmd docker\
|
||||||
$debug_flags\
|
$debug_flags\
|
||||||
buildx build\
|
buildx build\
|
||||||
|
|
|
@ -2,18 +2,20 @@
|
||||||
|
|
||||||
# AdGuard Home Release Script
|
# AdGuard Home Release Script
|
||||||
#
|
#
|
||||||
# The commentary in this file is written with the assumption that the
|
# The commentary in this file is written with the assumption that the reader
|
||||||
# reader only has superficial knowledge of the POSIX shell language and
|
# only has superficial knowledge of the POSIX shell language and alike.
|
||||||
# alike. Experienced readers may find it overly verbose.
|
# Experienced readers may find it overly verbose.
|
||||||
|
|
||||||
# The default verbosity level is 0. Show log messages if the caller
|
# The default verbosity level is 0. Show log messages if the caller requested
|
||||||
# requested verbosity level greather than 0. Show every command that is
|
# verbosity level greather than 0. Show every command that is run if the
|
||||||
# run if the verbosity level is greater than 1. Show the environment if
|
# verbosity level is greater than 1. Show the environment if the verbosity
|
||||||
# the verbosity level is greater than 2. Otherwise, print nothing.
|
# level is greater than 2. Otherwise, print nothing.
|
||||||
#
|
#
|
||||||
# The level of verbosity for the build script is the same minus one
|
# The level of verbosity for the build script is the same minus one level. See
|
||||||
# level. See below in build().
|
# below in build().
|
||||||
readonly verbose="${VERBOSE:-0}"
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
if [ "$verbose" -gt '2' ]
|
if [ "$verbose" -gt '2' ]
|
||||||
then
|
then
|
||||||
env
|
env
|
||||||
|
@ -24,14 +26,15 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# By default, sign the packages, but allow users to skip that step.
|
# By default, sign the packages, but allow users to skip that step.
|
||||||
readonly sign="${SIGN:-1}"
|
sign="${SIGN:-1}"
|
||||||
|
readonly sign
|
||||||
|
|
||||||
# Exit the script if a pipeline fails (-e), prevent accidental filename
|
# Exit the script if a pipeline fails (-e), prevent accidental filename
|
||||||
# expansion (-f), and consider undefined variables as errors (-u).
|
# expansion (-f), and consider undefined variables as errors (-u).
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
# Function log is an echo wrapper that writes to stderr if the caller
|
# Function log is an echo wrapper that writes to stderr if the caller requested
|
||||||
# requested verbosity level greater than 0. Otherwise, it does nothing.
|
# verbosity level greater than 0. Otherwise, it does nothing.
|
||||||
log() {
|
log() {
|
||||||
if [ "$verbose" -gt '0' ]
|
if [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
|
@ -42,85 +45,113 @@ log() {
|
||||||
|
|
||||||
log 'starting to build AdGuard Home release'
|
log 'starting to build AdGuard Home release'
|
||||||
|
|
||||||
# Require the channel to be set. Additional validation is performed
|
# Require the channel to be set. Additional validation is performed later by
|
||||||
# later by go-build.sh.
|
# go-build.sh.
|
||||||
readonly channel="$CHANNEL"
|
channel="$CHANNEL"
|
||||||
|
readonly channel
|
||||||
|
|
||||||
# Check VERSION against the default value from the Makefile. If it is
|
# Check VERSION against the default value from the Makefile. If it is that, use
|
||||||
# that, use the version calculation script.
|
# the version calculation script.
|
||||||
if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ]
|
if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ]
|
||||||
then
|
then
|
||||||
readonly version="$( sh ./scripts/make/version.sh )"
|
version="$( sh ./scripts/make/version.sh )"
|
||||||
else
|
else
|
||||||
readonly version="$VERSION"
|
version="$VERSION"
|
||||||
fi
|
fi
|
||||||
|
readonly version
|
||||||
|
|
||||||
log "channel '$channel'"
|
log "channel '$channel'"
|
||||||
log "version '$version'"
|
log "version '$version'"
|
||||||
|
|
||||||
# Check architecture and OS limiters. Add spaces to the local versions
|
# Check architecture and OS limiters. Add spaces to the local versions for
|
||||||
# for better pattern matching.
|
# better pattern matching.
|
||||||
if [ "${ARCH:-}" != '' ]
|
if [ "${ARCH:-}" != '' ]
|
||||||
then
|
then
|
||||||
log "arches: '$ARCH'"
|
log "arches: '$ARCH'"
|
||||||
readonly arches=" $ARCH "
|
arches=" $ARCH "
|
||||||
else
|
else
|
||||||
readonly arches=''
|
arches=''
|
||||||
fi
|
fi
|
||||||
|
readonly arches
|
||||||
|
|
||||||
if [ "${OS:-}" != '' ]
|
if [ "${OS:-}" != '' ]
|
||||||
then
|
then
|
||||||
log "oses: '$OS'"
|
log "oses: '$OS'"
|
||||||
readonly oses=" $OS "
|
oses=" $OS "
|
||||||
else
|
else
|
||||||
readonly oses=''
|
oses=''
|
||||||
fi
|
fi
|
||||||
|
readonly oses
|
||||||
|
|
||||||
readonly snap_enabled="${SNAP:-1}"
|
snap_enabled="${SNAP:-1}"
|
||||||
if [ "$snap_enabled" = '0' ]
|
readonly snap_enabled
|
||||||
|
|
||||||
|
if [ "$snap_enabled" -eq '0' ]
|
||||||
then
|
then
|
||||||
log 'snap: disabled'
|
log 'snap: disabled'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Require the gpg key and passphrase to be set if the signing is
|
# Require the gpg key and passphrase to be set if the signing is required.
|
||||||
# required.
|
if [ "$sign" -eq '1' ]
|
||||||
if [ "$sign" = '1' ]
|
|
||||||
then
|
then
|
||||||
readonly gpg_key_passphrase="$GPG_KEY_PASSPHRASE"
|
gpg_key_passphrase="$GPG_KEY_PASSPHRASE"
|
||||||
readonly gpg_key="$GPG_KEY"
|
gpg_key="$GPG_KEY"
|
||||||
|
else
|
||||||
|
gpg_key_passphrase=''
|
||||||
|
gpg_key=''
|
||||||
fi
|
fi
|
||||||
|
readonly gpg_key_passphrase gpg_key
|
||||||
|
|
||||||
# The default distribution files directory is dist.
|
# The default distribution files directory is dist.
|
||||||
readonly dist="${DIST_DIR:-dist}"
|
dist="${DIST_DIR:-dist}"
|
||||||
|
readonly dist
|
||||||
|
|
||||||
# Give users the ability to override the go command from environment.
|
# Give users the ability to override the go command from environment. For
|
||||||
# For example, to build two releases with two different Go versions and
|
# example, to build two releases with two different Go versions and test the
|
||||||
# test the difference.
|
# difference.
|
||||||
readonly go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
|
readonly go
|
||||||
|
|
||||||
log "checking tools"
|
log "checking tools"
|
||||||
|
|
||||||
# Make sure we fail gracefully if one of the tools we need is missing.
|
# Make sure we fail gracefully if one of the tools we need is missing. Use
|
||||||
for tool in gpg gzip sed sha256sum snapcraft tar zip
|
# alternatives when available.
|
||||||
|
sha256sum_cmd='sha256sum'
|
||||||
|
for tool in gpg gzip sed "$sha256sum_cmd" snapcraft tar zip
|
||||||
do
|
do
|
||||||
which "$tool" >/dev/null\
|
if ! which "$tool" > /dev/null
|
||||||
|| { log "pieces don't fit, '$tool' not found"; exit 1; }
|
then
|
||||||
|
if [ "$tool" = "$sha256sum_cmd" ] && which 'shasum' > /dev/null
|
||||||
|
then
|
||||||
|
# macOS doesn't have sha256sum installed by default, but
|
||||||
|
# it does have shasum.
|
||||||
|
log 'replacing sha256sum with shasum -a 256'
|
||||||
|
sha256sum_cmd='shasum -a 256'
|
||||||
|
else
|
||||||
|
log "pieces don't fit, '$tool' not found"
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
readonly sha256sum_cmd
|
||||||
|
|
||||||
# Data section. Arrange data into space-separated tables for read -r to
|
# Data section. Arrange data into space-separated tables for read -r to read.
|
||||||
# read. Use 0 for missing values.
|
# Use 0 for missing values.
|
||||||
|
|
||||||
readonly arms='5
|
arms='5
|
||||||
6
|
6
|
||||||
7'
|
7'
|
||||||
|
readonly arms
|
||||||
|
|
||||||
readonly mipses='softfloat'
|
mipses='softfloat'
|
||||||
|
readonly mipses
|
||||||
|
|
||||||
# TODO(a.garipov): Remove armv6, because it was always overwritten by
|
# TODO(a.garipov): Remove armv6, because it was always overwritten by armv7.
|
||||||
# armv7. Rename armv7 to armhf. Rename the 386 snap to i386.
|
# Rename armv7 to armhf. Rename the 386 snap to i386.
|
||||||
|
|
||||||
# os arch arm mips snap
|
# os arch arm mips snap
|
||||||
readonly platforms="\
|
platforms="\
|
||||||
darwin amd64 0 0 0
|
darwin amd64 0 0 0
|
||||||
freebsd 386 0 0 0
|
freebsd 386 0 0 0
|
||||||
freebsd amd64 0 0 0
|
freebsd amd64 0 0 0
|
||||||
|
@ -141,12 +172,13 @@ linux mipsle 0 softfloat 0
|
||||||
linux ppc64le 0 0 0
|
linux ppc64le 0 0 0
|
||||||
windows 386 0 0 0
|
windows 386 0 0 0
|
||||||
windows amd64 0 0 0"
|
windows amd64 0 0 0"
|
||||||
|
readonly platforms
|
||||||
|
|
||||||
# Function build builds the release for one platform. It builds
|
# Function build builds the release for one platform. It builds a binary, an
|
||||||
# a binary, an archive and, if needed, a snap package.
|
# archive and, if needed, a snap package.
|
||||||
build() {
|
build() {
|
||||||
# Get the arguments. Here and below, use the "build_" prefix
|
# Get the arguments. Here and below, use the "build_" prefix for all
|
||||||
# for all variables local to function build.
|
# variables local to function build.
|
||||||
build_dir="${dist}/${1}/AdGuardHome"\
|
build_dir="${dist}/${1}/AdGuardHome"\
|
||||||
build_ar="$2"\
|
build_ar="$2"\
|
||||||
build_os="$3"\
|
build_os="$3"\
|
||||||
|
@ -156,8 +188,7 @@ build() {
|
||||||
build_snap="$7"\
|
build_snap="$7"\
|
||||||
;
|
;
|
||||||
|
|
||||||
# Use the ".exe" filename extension if we build a Windows
|
# Use the ".exe" filename extension if we build a Windows release.
|
||||||
# release.
|
|
||||||
if [ "$build_os" = 'windows' ]
|
if [ "$build_os" = 'windows' ]
|
||||||
then
|
then
|
||||||
build_output="./${build_dir}/AdGuardHome.exe"
|
build_output="./${build_dir}/AdGuardHome.exe"
|
||||||
|
@ -169,11 +200,11 @@ build() {
|
||||||
|
|
||||||
# Build the binary.
|
# Build the binary.
|
||||||
#
|
#
|
||||||
# Set GOARM and GOMIPS to an empty string if $build_arm and
|
# Set GOARM and GOMIPS to an empty string if $build_arm and $build_mips
|
||||||
# $build_mips are zero by removing the zero as if it's a prefix.
|
# are zero by removing the zero as if it's a prefix.
|
||||||
#
|
#
|
||||||
# Don't use quotes with $build_par because we want an empty
|
# Don't use quotes with $build_par because we want an empty space if
|
||||||
# space if parallelism wasn't set.
|
# parallelism wasn't set.
|
||||||
env\
|
env\
|
||||||
GOARCH="$build_arch"\
|
GOARCH="$build_arch"\
|
||||||
GOARM="${build_arm#0}"\
|
GOARM="${build_arm#0}"\
|
||||||
|
@ -187,7 +218,7 @@ build() {
|
||||||
|
|
||||||
log "$build_output"
|
log "$build_output"
|
||||||
|
|
||||||
if [ "$sign" = '1' ]
|
if [ "$sign" -eq '1' ]
|
||||||
then
|
then
|
||||||
gpg\
|
gpg\
|
||||||
--default-key "$gpg_key"\
|
--default-key "$gpg_key"\
|
||||||
|
@ -202,8 +233,8 @@ build() {
|
||||||
# Prepare the build directory for archiving.
|
# Prepare the build directory for archiving.
|
||||||
cp ./CHANGELOG.md ./LICENSE.txt ./README.md "$build_dir"
|
cp ./CHANGELOG.md ./LICENSE.txt ./README.md "$build_dir"
|
||||||
|
|
||||||
# Make archives. Windows and macOS prefer ZIP archives; the
|
# Make archives. Windows and macOS prefer ZIP archives; the rest,
|
||||||
# rest, gzipped tarballs.
|
# gzipped tarballs.
|
||||||
case "$build_os"
|
case "$build_os"
|
||||||
in
|
in
|
||||||
('darwin'|'windows')
|
('darwin'|'windows')
|
||||||
|
@ -220,7 +251,11 @@ build() {
|
||||||
|
|
||||||
log "$build_archive"
|
log "$build_archive"
|
||||||
|
|
||||||
if [ "$build_snap" = '0' ] || [ "$snap_enabled" = '0' ]
|
# build_snap is a string, so use string comparison for it.
|
||||||
|
#
|
||||||
|
# TODO(a.garipov): Consider using a different empty value in the
|
||||||
|
# platforms table.
|
||||||
|
if [ "$build_snap" = '0' ] || [ "$snap_enabled" -eq '0' ]
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -257,10 +292,10 @@ build() {
|
||||||
./scripts/snap/snap.tmpl.yaml\
|
./scripts/snap/snap.tmpl.yaml\
|
||||||
>"${build_snap_dir}/meta/snap.yaml"
|
>"${build_snap_dir}/meta/snap.yaml"
|
||||||
|
|
||||||
# TODO(a.garipov): The snapcraft tool will *always* write
|
# TODO(a.garipov): The snapcraft tool will *always* write everything,
|
||||||
# everything, including errors, to stdout. And there doesn't
|
# including errors, to stdout. And there doesn't seem to be a way to
|
||||||
# seem to be a way to change that. So, save the combined
|
# change that. So, save the combined output, but only show it when
|
||||||
# output, but only show it when snapcraft actually fails.
|
# snapcraft actually fails.
|
||||||
set +e
|
set +e
|
||||||
build_snapcraft_output="$(
|
build_snapcraft_output="$(
|
||||||
snapcraft pack "$build_snap_dir" --output "$build_snap_output" 2>&1
|
snapcraft pack "$build_snap_dir" --output "$build_snap_output" 2>&1
|
||||||
|
@ -278,20 +313,18 @@ build() {
|
||||||
|
|
||||||
log "starting builds"
|
log "starting builds"
|
||||||
|
|
||||||
# Go over all platforms defined in the space-separated table above,
|
# Go over all platforms defined in the space-separated table above, tweak the
|
||||||
# tweak the values where necessary, and feed to build.
|
# values where necessary, and feed to build.
|
||||||
echo "$platforms" | while read -r os arch arm mips snap
|
echo "$platforms" | while read -r os arch arm mips snap
|
||||||
do
|
do
|
||||||
# See if the architecture or the OS is in the allowlist. To do
|
# See if the architecture or the OS is in the allowlist. To do so, try
|
||||||
# so, try removing everything that matches the pattern (well,
|
# removing everything that matches the pattern (well, a prefix, but that
|
||||||
# a prefix, but that doesn't matter here) containing the arch or
|
# doesn't matter here) containing the arch or the OS.
|
||||||
# the OS.
|
|
||||||
#
|
#
|
||||||
# For example, when $arches is " amd64 arm64 " and $arch is
|
# For example, when $arches is " amd64 arm64 " and $arch is "amd64",
|
||||||
# "amd64", then the pattern to remove is "* amd64 *", so the
|
# then the pattern to remove is "* amd64 *", so the whole string becomes
|
||||||
# whole string becomes empty. On the other hand, if $arch is
|
# empty. On the other hand, if $arch is "windows", then the pattern is
|
||||||
# "windows", then the pattern is "* windows *", which doesn't
|
# "* windows *", which doesn't match, so nothing is removed.
|
||||||
# match, so nothing is removed.
|
|
||||||
#
|
#
|
||||||
# See https://stackoverflow.com/a/43912605/1892060.
|
# See https://stackoverflow.com/a/43912605/1892060.
|
||||||
if [ "${arches##* $arch *}" != '' ]
|
if [ "${arches##* $arch *}" != '' ]
|
||||||
|
@ -333,17 +366,16 @@ log "$build_archive"
|
||||||
|
|
||||||
log "calculating checksums"
|
log "calculating checksums"
|
||||||
|
|
||||||
# Calculate the checksums of the files in a subshell with a different
|
# Calculate the checksums of the files in a subshell with a different working
|
||||||
# working directory. Don't use ls, because files matching one of the
|
# directory. Don't use ls, because files matching one of the patterns may be
|
||||||
# patterns may be absent, which will make ls return with a non-zero
|
# absent, which will make ls return with a non-zero status code.
|
||||||
# status code.
|
|
||||||
(
|
(
|
||||||
cd "./${dist}"
|
cd "./${dist}"
|
||||||
|
|
||||||
files="$( find . ! -name . -prune \( -name '*.tar.gz' -o -name '*.zip' \) )"
|
files="$( find . ! -name . -prune \( -name '*.tar.gz' -o -name '*.zip' \) )"
|
||||||
|
|
||||||
# Don't use quotes to get word splitting.
|
# Don't use quotes to get word splitting.
|
||||||
sha256sum $files > ./checksums.txt
|
$sha256sum_cmd $files > ./checksums.txt
|
||||||
)
|
)
|
||||||
|
|
||||||
log "writing versions"
|
log "writing versions"
|
||||||
|
@ -351,20 +383,19 @@ log "writing versions"
|
||||||
echo "version=$version" > "./${dist}/version.txt"
|
echo "version=$version" > "./${dist}/version.txt"
|
||||||
|
|
||||||
# Create the verison.json file.
|
# Create the verison.json file.
|
||||||
#
|
|
||||||
# TODO(a.garipov): Perhaps rewrite this as a go run program. Dealing
|
|
||||||
# with structured documents is really not a Shell's job.
|
|
||||||
|
|
||||||
readonly version_download_url="https://static.adguard.com/adguardhome/${channel}"
|
version_download_url="https://static.adguard.com/adguardhome/${channel}"
|
||||||
readonly version_json="./${dist}/version.json"
|
version_json="./${dist}/version.json"
|
||||||
|
readonly version_download_url version_json
|
||||||
|
|
||||||
# Point users to the master branch if the channel is edge.
|
# Point users to the master branch if the channel is edge.
|
||||||
if [ "$channel" = 'edge' ]
|
if [ "$channel" = 'edge' ]
|
||||||
then
|
then
|
||||||
readonly version_history_url='https://github.com/AdguardTeam/AdGuardHome/commits/master'
|
version_history_url='https://github.com/AdguardTeam/AdGuardHome/commits/master'
|
||||||
else
|
else
|
||||||
readonly version_history_url='https://github.com/AdguardTeam/AdGuardHome/releases'
|
version_history_url='https://github.com/AdguardTeam/AdGuardHome/releases'
|
||||||
fi
|
fi
|
||||||
|
readonly version_history_url
|
||||||
|
|
||||||
rm -f "$version_json"
|
rm -f "$version_json"
|
||||||
echo "{
|
echo "{
|
||||||
|
@ -374,23 +405,11 @@ echo "{
|
||||||
\"selfupdate_min_version\": \"0.0\",
|
\"selfupdate_min_version\": \"0.0\",
|
||||||
" >> "$version_json"
|
" >> "$version_json"
|
||||||
|
|
||||||
# Add the old object keys for compatibility with pre-v0.105.0 MIPS that
|
# Same as with checksums above, don't use ls, because files matching one of the
|
||||||
# did not mention the softfloat variant.
|
# patterns may be absent.
|
||||||
#
|
ar_files="$( find "./${dist}/" ! -name "${dist}" -prune \( -name '*.tar.gz' -o -name '*.zip' \) )"
|
||||||
# TODO(a.garipov): Remove this around the time we hit v0.107.0.
|
ar_files_len="$( echo "$ar_files" | wc -l )"
|
||||||
echo "
|
readonly ar_files ar_files_len
|
||||||
\"download_linux_mips\": \"${version_download_url}/AdGuardHome_linux_mips_softfloat.tar.gz\",
|
|
||||||
\"download_linux_mipsle\": \"${version_download_url}/AdGuardHome_linux_mipsle_softfloat.tar.gz\",
|
|
||||||
\"download_linux_mips64\": \"${version_download_url}/AdGuardHome_linux_mips64_softfloat.tar.gz\",
|
|
||||||
\"download_linux_mips64le\": \"${version_download_url}/AdGuardHome_linux_mips64le_softfloat.tar.gz\",
|
|
||||||
" >> "$version_json"
|
|
||||||
|
|
||||||
# Same as with checksums above, don't use ls, because files matching one
|
|
||||||
# of the patterns may be absent.
|
|
||||||
readonly ar_files="$( \
|
|
||||||
find "./${dist}/" ! -name "${dist}" -prune \( -name '*.tar.gz' -o -name '*.zip' \)
|
|
||||||
)"
|
|
||||||
readonly ar_files_len="$( echo "$ar_files" | wc -l )"
|
|
||||||
|
|
||||||
i='1'
|
i='1'
|
||||||
# Don't use quotes to get word splitting.
|
# Don't use quotes to get word splitting.
|
||||||
|
@ -408,7 +427,7 @@ do
|
||||||
# Use the filename's base path.
|
# Use the filename's base path.
|
||||||
filename="${f#./${dist}/}"
|
filename="${f#./${dist}/}"
|
||||||
|
|
||||||
if [ "$i" = "$ar_files_len" ]
|
if [ "$i" -eq "$ar_files_len" ]
|
||||||
then
|
then
|
||||||
echo " \"download_${platform}\": \"${version_download_url}/${filename}\"" >> "$version_json"
|
echo " \"download_${platform}\": \"${version_download_url}/${filename}\"" >> "$version_json"
|
||||||
else
|
else
|
||||||
|
|
|
@ -12,9 +12,9 @@ set -e -f -u
|
||||||
dist_dir="$DIST_DIR"
|
dist_dir="$DIST_DIR"
|
||||||
go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
|
|
||||||
# Set the GOPATH explicitly in case make clean is called from under sudo
|
# Set the GOPATH explicitly in case make clean is called from under sudo after
|
||||||
# after a Docker build.
|
# a Docker build.
|
||||||
env PATH="$("$go" env GOPATH)/bin":"$PATH" packr clean
|
env PATH="$( "$go" env GOPATH )/bin":"$PATH" packr clean
|
||||||
|
|
||||||
rm -f\
|
rm -f\
|
||||||
./AdGuardHome\
|
./AdGuardHome\
|
||||||
|
|
|
@ -2,41 +2,47 @@
|
||||||
|
|
||||||
# AdGuard Home Build Script
|
# AdGuard Home Build Script
|
||||||
#
|
#
|
||||||
# The commentary in this file is written with the assumption that the
|
# The commentary in this file is written with the assumption that the reader
|
||||||
# reader only has superficial knowledge of the POSIX shell language and
|
# only has superficial knowledge of the POSIX shell language and alike.
|
||||||
# alike. Experienced readers may find it overly verbose.
|
# Experienced readers may find it overly verbose.
|
||||||
|
|
||||||
|
# The default verbosity level is 0. Show every command that is run and every
|
||||||
|
# package that is processed if the caller requested verbosity level greater than
|
||||||
|
# 0. Also show subcommands if the requested verbosity level is greater than 1.
|
||||||
|
# Otherwise, do nothing.
|
||||||
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
# The default verbosity level is 0. Show every command that is run and
|
|
||||||
# every package that is processed if the caller requested verbosity
|
|
||||||
# level greater than 0. Also show subcommands if the requested
|
|
||||||
# verbosity level is greater than 1. Otherwise, do nothing.
|
|
||||||
readonly verbose="${VERBOSE:-0}"
|
|
||||||
if [ "$verbose" -gt '1' ]
|
if [ "$verbose" -gt '1' ]
|
||||||
then
|
then
|
||||||
env
|
env
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags='-x'
|
x_flags='-x'
|
||||||
elif [ "$verbose" -gt '0' ]
|
elif [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
else
|
else
|
||||||
set +x
|
set +x
|
||||||
readonly v_flags=''
|
v_flags=''
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly x_flags v_flags
|
||||||
|
|
||||||
# Exit the script if a pipeline fails (-e), prevent accidental filename
|
# Exit the script if a pipeline fails (-e), prevent accidental filename
|
||||||
# expansion (-f), and consider undefined variables as errors (-u).
|
# expansion (-f), and consider undefined variables as errors (-u).
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
# Allow users to set the Go version.
|
# Allow users to set the Go version.
|
||||||
readonly go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
|
readonly go
|
||||||
|
|
||||||
# Require the channel to be set and validate the value.
|
# Require the channel to be set and validate the value.
|
||||||
readonly channel="$CHANNEL"
|
channel="$CHANNEL"
|
||||||
|
readonly channel
|
||||||
|
|
||||||
case "$channel"
|
case "$channel"
|
||||||
in
|
in
|
||||||
('development'|'edge'|'beta'|'release')
|
('development'|'edge'|'beta'|'release')
|
||||||
|
@ -52,15 +58,19 @@ esac
|
||||||
# Require the version to be set.
|
# Require the version to be set.
|
||||||
#
|
#
|
||||||
# TODO(a.garipov): Additional validation?
|
# TODO(a.garipov): Additional validation?
|
||||||
readonly version="$VERSION"
|
version="$VERSION"
|
||||||
|
readonly version
|
||||||
|
|
||||||
# Set date and time of the current build unless already set.
|
# Set date and time of the current build unless already set.
|
||||||
readonly buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}"
|
buildtime="${BUILD_TIME:-$( date -u +%FT%TZ%z )}"
|
||||||
|
readonly buildtime
|
||||||
|
|
||||||
|
# Set the linker flags accordingly: set the release channel and the current
|
||||||
|
# version as well as goarm and gomips variable values, if the variables are set
|
||||||
|
# and are not empty.
|
||||||
|
version_pkg='github.com/AdguardTeam/AdGuardHome/internal/version'
|
||||||
|
readonly version_pkg
|
||||||
|
|
||||||
# Set the linker flags accordingly: set the release channel and the
|
|
||||||
# current version as well as goarm and gomips variable values, if the
|
|
||||||
# variables are set and are not empty.
|
|
||||||
readonly version_pkg='github.com/AdguardTeam/AdGuardHome/internal/version'
|
|
||||||
ldflags="-s -w"
|
ldflags="-s -w"
|
||||||
ldflags="${ldflags} -X ${version_pkg}.version=${version}"
|
ldflags="${ldflags} -X ${version_pkg}.version=${version}"
|
||||||
ldflags="${ldflags} -X ${version_pkg}.channel=${channel}"
|
ldflags="${ldflags} -X ${version_pkg}.channel=${channel}"
|
||||||
|
@ -74,39 +84,47 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Allow users to limit the build's parallelism.
|
# Allow users to limit the build's parallelism.
|
||||||
readonly parallelism="${PARALLELISM:-}"
|
parallelism="${PARALLELISM:-}"
|
||||||
if [ "$parallelism" != '' ]
|
readonly parallelism
|
||||||
|
|
||||||
|
if [ "${parallelism}" != '' ]
|
||||||
then
|
then
|
||||||
readonly par_flags="-p ${parallelism}"
|
par_flags="-p ${parallelism}"
|
||||||
else
|
else
|
||||||
readonly par_flags=''
|
par_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly par_flags
|
||||||
|
|
||||||
# Allow users to specify a different output name.
|
# Allow users to specify a different output name.
|
||||||
readonly out="${OUT:-}"
|
out="${OUT:-}"
|
||||||
|
readonly out
|
||||||
|
|
||||||
if [ "$out" != '' ]
|
if [ "$out" != '' ]
|
||||||
then
|
then
|
||||||
readonly out_flags="-o ${out}"
|
out_flags="-o ${out}"
|
||||||
else
|
else
|
||||||
readonly out_flags=''
|
out_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly out_flags
|
||||||
|
|
||||||
# Allow users to enable the race detector. Unfortunately, that means
|
# Allow users to enable the race detector. Unfortunately, that means that cgo
|
||||||
# that CGo must be enabled.
|
# must be enabled.
|
||||||
readonly race="${RACE:-0}"
|
if [ "${RACE:-0}" -eq '0' ]
|
||||||
if [ "$race" = '0' ]
|
|
||||||
then
|
then
|
||||||
readonly cgo_enabled='0'
|
cgo_enabled='0'
|
||||||
readonly race_flags=''
|
race_flags=''
|
||||||
else
|
else
|
||||||
readonly cgo_enabled='1'
|
cgo_enabled='1'
|
||||||
readonly race_flags='--race'
|
race_flags='--race'
|
||||||
fi
|
fi
|
||||||
|
readonly cgo_enabled race_flags
|
||||||
|
|
||||||
export CGO_ENABLED="$cgo_enabled"
|
CGO_ENABLED="$cgo_enabled"
|
||||||
export GO111MODULE='on'
|
GO111MODULE='on'
|
||||||
|
export CGO_ENABLED GO111MODULE
|
||||||
|
|
||||||
readonly build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}"
|
build_flags="${BUILD_FLAGS:-$race_flags --trimpath $out_flags $par_flags $v_flags $x_flags}"
|
||||||
|
readonly build_flags
|
||||||
|
|
||||||
# Don't use quotes with flag variables to get word splitting.
|
# Don't use quotes with flag variables to get word splitting.
|
||||||
"$go" generate $v_flags $x_flags ./main.go
|
"$go" generate $v_flags $x_flags ./main.go
|
||||||
|
|
|
@ -1,36 +1,37 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
verbose="${VERBOSE:-0}"
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
if [ "$verbose" -gt '1' ]
|
if [ "$verbose" -gt '1' ]
|
||||||
then
|
then
|
||||||
env
|
env
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags='-x'
|
x_flags='-x'
|
||||||
elif [ "$verbose" -gt '0' ]
|
elif [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
else
|
else
|
||||||
set +x
|
set +x
|
||||||
readonly v_flags=''
|
v_flags=''
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly v_flags x_flags
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
|
|
||||||
# Don't use quotes with flag variables because we want an empty space if
|
# Don't use quotes with flag variables because we want an empty space if those
|
||||||
# those aren't set.
|
# aren't set.
|
||||||
"$go" mod download $x_flags
|
"$go" mod download $x_flags
|
||||||
|
|
||||||
# Reset GOARCH and GOOS to make sure we install the tools for the native
|
# Reset GOARCH and GOOS to make sure we install the tools for the native
|
||||||
# architecture even when we're cross-compiling the main binary, and also
|
# architecture even when we're cross-compiling the main binary, and also to
|
||||||
# to prevent the "cannot install cross-compiled binaries when GOBIN is
|
# prevent the "cannot install cross-compiled binaries when GOBIN is set" error.
|
||||||
# set" error.
|
|
||||||
env\
|
env\
|
||||||
GOARCH=""\
|
GOARCH=""\
|
||||||
GOOS=""\
|
GOOS=""\
|
||||||
|
|
|
@ -2,44 +2,42 @@
|
||||||
|
|
||||||
verbose="${VERBOSE:-0}"
|
verbose="${VERBOSE:-0}"
|
||||||
|
|
||||||
# Verbosity levels:
|
# Set verbosity.
|
||||||
# 0 = Don't print anything except for errors.
|
|
||||||
# 1 = Print commands, but not nested commands.
|
|
||||||
# 2 = Print everything.
|
|
||||||
if [ "$verbose" -gt '0' ]
|
if [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set $EXIT_ON_ERROR to zero to see all errors.
|
# Set $EXIT_ON_ERROR to zero to see all errors.
|
||||||
if [ "${EXIT_ON_ERROR:-1}" = '0' ]
|
if [ "${EXIT_ON_ERROR:-1}" -eq '0' ]
|
||||||
then
|
then
|
||||||
set +e
|
set +e
|
||||||
else
|
else
|
||||||
set -e
|
set -e
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We don't need glob expansions and we want to see errors about unset
|
# We don't need glob expansions and we want to see errors about unset variables.
|
||||||
# variables.
|
|
||||||
set -f -u
|
set -f -u
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Deferred Helpers
|
# Deferred Helpers
|
||||||
|
|
||||||
readonly not_found_msg='
|
not_found_msg='
|
||||||
looks like a binary not found error.
|
looks like a binary not found error.
|
||||||
make sure you have installed the linter binaries using:
|
make sure you have installed the linter binaries using:
|
||||||
|
|
||||||
$ make go-tools
|
$ make go-tools
|
||||||
'
|
'
|
||||||
|
readonly not_found_msg
|
||||||
|
|
||||||
|
# TODO(a.garipov): Put it into a separate script and source it both here and in
|
||||||
|
# txt-lint.sh?
|
||||||
not_found() {
|
not_found() {
|
||||||
if [ "$?" = '127' ]
|
if [ "$?" -eq '127' ]
|
||||||
then
|
then
|
||||||
# Code 127 is the exit status a shell uses when
|
# Code 127 is the exit status a shell uses when a command or
|
||||||
# a command or a file is not found, according to the
|
# a file is not found, according to the Bash Hackers wiki.
|
||||||
# Bash Hackers wiki.
|
|
||||||
#
|
#
|
||||||
# See https://wiki.bash-hackers.org/dict/terms/exit_status.
|
# See https://wiki.bash-hackers.org/dict/terms/exit_status.
|
||||||
echo "$not_found_msg" 1>&2
|
echo "$not_found_msg" 1>&2
|
||||||
|
@ -51,15 +49,17 @@ trap not_found EXIT
|
||||||
|
|
||||||
# Warnings
|
# Warnings
|
||||||
|
|
||||||
readonly go_min_version='go1.15'
|
go_min_version='go1.15'
|
||||||
readonly go_min_version_prefix="go version ${go_min_version}"
|
go_min_version_prefix="go version ${go_min_version}"
|
||||||
readonly go_version_msg="
|
go_version_msg="
|
||||||
warning: your go version is different from the recommended minimal one (${go_min_version}).
|
warning: your go version is different from the recommended minimal one (${go_min_version}).
|
||||||
if you have the version installed, please set the GO environment variable.
|
if you have the version installed, please set the GO environment variable.
|
||||||
for example:
|
for example:
|
||||||
|
|
||||||
export GO='${go_min_version}'
|
export GO='${go_min_version}'
|
||||||
"
|
"
|
||||||
|
readonly go_min_version go_min_version_prefix go_version_msg
|
||||||
|
|
||||||
case "$( "$GO" version )"
|
case "$( "$GO" version )"
|
||||||
in
|
in
|
||||||
("$go_min_version_prefix"*)
|
("$go_min_version_prefix"*)
|
||||||
|
@ -74,15 +74,15 @@ esac
|
||||||
|
|
||||||
# Simple Analyzers
|
# Simple Analyzers
|
||||||
|
|
||||||
# blocklist_imports is a simple check against unwanted packages.
|
# blocklist_imports is a simple check against unwanted packages. Currently it
|
||||||
# Currently it only looks for package log which is replaced by our own
|
# only looks for package log which is replaced by our own package
|
||||||
# package github.com/AdguardTeam/golibs/log.
|
# github.com/AdguardTeam/golibs/log.
|
||||||
blocklist_imports() {
|
blocklist_imports() {
|
||||||
git grep -F -e '"log"' -- '*.go' || exit 0;
|
git grep -F -e '"log"' -- '*.go' || exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# method_const is a simple check against the usage of some raw strings
|
# method_const is a simple check against the usage of some raw strings and
|
||||||
# and numbers where one should use named constants.
|
# numbers where one should use named constants.
|
||||||
method_const() {
|
method_const() {
|
||||||
git grep -F -e '"GET"' -e '"POST"' -- '*.go' || exit 0;
|
git grep -F -e '"GET"' -e '"POST"' -- '*.go' || exit 0;
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,8 @@ underscores() {
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
# exit_on_output exits with a nonzero exit code if there is anything in
|
# exit_on_output exits with a nonzero exit code if there is anything in the
|
||||||
# the command's combined output.
|
# command's combined output.
|
||||||
exit_on_output() (
|
exit_on_output() (
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ exit_on_output() (
|
||||||
|
|
||||||
echo "$output"
|
echo "$output"
|
||||||
|
|
||||||
if [ "$exitcode" = '0' ]
|
if [ "$exitcode" -eq '0' ]
|
||||||
then
|
then
|
||||||
exitcode='1'
|
exitcode='1'
|
||||||
fi
|
fi
|
||||||
|
@ -154,7 +154,8 @@ exit_on_output() (
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
|
|
||||||
readonly go_files='./main.go ./tools.go ./internal/'
|
go_files='./main.go ./tools.go ./internal/'
|
||||||
|
readonly go_files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,8 +182,7 @@ ineffassign ./...
|
||||||
|
|
||||||
unparam ./...
|
unparam ./...
|
||||||
|
|
||||||
git ls-files -- '*.go' '*.md' '*.mod' '*.sh' '*.yaml' '*.yml' 'Makefile'\
|
git ls-files -- '*.go' '*.mod' '*.sh' 'Makefile' | xargs misspell --error
|
||||||
| xargs misspell --error
|
|
||||||
|
|
||||||
looppointer ./...
|
looppointer ./...
|
||||||
|
|
||||||
|
@ -190,9 +190,8 @@ nilness ./...
|
||||||
|
|
||||||
exit_on_output shadow --strict ./...
|
exit_on_output shadow --strict ./...
|
||||||
|
|
||||||
# TODO(a.garipov): Enable errcheck fully after handling all errors,
|
# TODO(a.garipov): Enable errcheck fully after handling all errors, including
|
||||||
# including the deferred and generated ones, properly. Also, perhaps,
|
# the deferred and generated ones, properly. Also, perhaps, enable --blank.
|
||||||
# enable --blank.
|
|
||||||
#
|
#
|
||||||
# errcheck ./...
|
# errcheck ./...
|
||||||
exit_on_output sh -c '
|
exit_on_output sh -c '
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
verbose="${VERBOSE:-0}"
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
# Verbosity levels:
|
# Verbosity levels:
|
||||||
# 0 = Don't print anything except for errors.
|
# 0 = Don't print anything except for errors.
|
||||||
|
@ -21,22 +22,24 @@ else
|
||||||
v_flags=''
|
v_flags=''
|
||||||
x_flags=''
|
x_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly v_flags x_flags
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
race="${RACE:-1}"
|
if [ "${RACE:-1}" -eq '0' ]
|
||||||
if [ "$race" = '0' ]
|
|
||||||
then
|
then
|
||||||
race_flags=''
|
race_flags=''
|
||||||
else
|
else
|
||||||
race_flags='--race'
|
race_flags='--race'
|
||||||
fi
|
fi
|
||||||
|
readonly race_flags
|
||||||
|
|
||||||
readonly go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
readonly timeout_flags="${TIMEOUT_FLAGS:---timeout 30s}"
|
timeout_flags="${TIMEOUT_FLAGS:---timeout 30s}"
|
||||||
readonly cover_flags='--coverprofile ./coverage.txt'
|
cover_flags='--coverprofile ./coverage.txt'
|
||||||
readonly count_flags='--count 1'
|
count_flags='--count 1'
|
||||||
|
readonly go timeout_flags cover_flags count_flags
|
||||||
|
|
||||||
# Don't use quotes with flag variables because we want an empty space if
|
# Don't use quotes with flag variables because we want an empty space if those
|
||||||
# those aren't set.
|
# aren't set.
|
||||||
"$go" test $count_flags $cover_flags $race_flags $timeout_flags $x_flags $v_flags ./...
|
"$go" test $count_flags $cover_flags $race_flags $timeout_flags $x_flags $v_flags ./...
|
||||||
|
|
|
@ -1,33 +1,35 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
verbose="${VERBOSE:-0}"
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
if [ "$verbose" -gt '1' ]
|
if [ "$verbose" -gt '1' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags='-x'
|
x_flags='-x'
|
||||||
elif [ "$verbose" -gt '0' ]
|
elif [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
readonly v_flags='-v'
|
v_flags='-v'
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
else
|
else
|
||||||
set +x
|
set +x
|
||||||
readonly v_flags=''
|
v_flags=''
|
||||||
readonly x_flags=''
|
x_flags=''
|
||||||
fi
|
fi
|
||||||
|
readonly v_flags x_flags
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
go="${GO:-go}"
|
go="${GO:-go}"
|
||||||
|
readonly go
|
||||||
|
|
||||||
# TODO(a.garipov): Add goconst?
|
# TODO(a.garipov): Add goconst?
|
||||||
|
|
||||||
# Reset GOARCH and GOOS to make sure we install the tools for the native
|
# Reset GOARCH and GOOS to make sure we install the tools for the native
|
||||||
# architecture even when we're cross-compiling the main binary, and also
|
# architecture even when we're cross-compiling the main binary, and also to
|
||||||
# to prevent the "cannot install cross-compiled binaries when GOBIN is
|
# prevent the "cannot install cross-compiled binaries when GOBIN is set" error.
|
||||||
# set" error.
|
|
||||||
env\
|
env\
|
||||||
GOARCH=""\
|
GOARCH=""\
|
||||||
GOOS=""\
|
GOOS=""\
|
||||||
|
|
49
scripts/make/txt-lint.sh
Normal file
49
scripts/make/txt-lint.sh
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
verbose="${VERBOSE:-0}"
|
||||||
|
readonly verbose
|
||||||
|
|
||||||
|
# Set verbosity.
|
||||||
|
if [ "$verbose" -gt '0' ]
|
||||||
|
then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set $EXIT_ON_ERROR to zero to see all errors.
|
||||||
|
if [ "${EXIT_ON_ERROR:-1}" -eq '0' ]
|
||||||
|
then
|
||||||
|
set +e
|
||||||
|
else
|
||||||
|
set -e
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We don't need glob expansions and we want to see errors about unset variables.
|
||||||
|
set -f -u
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Deferred Helpers
|
||||||
|
|
||||||
|
not_found_msg='
|
||||||
|
looks like a binary not found error.
|
||||||
|
make sure you have installed the linter binaries using:
|
||||||
|
|
||||||
|
$ make go-tools
|
||||||
|
'
|
||||||
|
readonly not_found_msg
|
||||||
|
|
||||||
|
# TODO(a.garipov): Put it into a separate script and source it both here and in
|
||||||
|
# go-lint.sh?
|
||||||
|
not_found() {
|
||||||
|
if [ "$?" -eq '127' ]
|
||||||
|
then
|
||||||
|
# Code 127 is the exit status a shell uses when a command or
|
||||||
|
# a file is not found, according to the Bash Hackers wiki.
|
||||||
|
#
|
||||||
|
# See https://wiki.bash-hackers.org/dict/terms/exit_status.
|
||||||
|
echo "$not_found_msg" 1>&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
trap not_found EXIT
|
||||||
|
|
||||||
|
git ls-files -- '*.md' '*.yaml' '*.yml' | xargs misspell --error
|
|
@ -2,28 +2,29 @@
|
||||||
|
|
||||||
# AdGuard Home Version Generation Script
|
# AdGuard Home Version Generation Script
|
||||||
#
|
#
|
||||||
# This script generates versions based on the current git tree state.
|
# This script generates versions based on the current git tree state. The valid
|
||||||
# The valid output formats are:
|
# output formats are:
|
||||||
#
|
#
|
||||||
# * For release versions, "v0.123.4". This version should be the one
|
# * For release versions, "v0.123.4". This version should be the one in the
|
||||||
# in the current tag, and the script merely checks, that the current
|
# current tag, and the script merely checks, that the current commit is
|
||||||
|
# properly tagged.
|
||||||
|
#
|
||||||
|
# * For prerelease beta versions, "v0.123.4-b.5". This version should be the
|
||||||
|
# one in the current tag, and the script merely checks, that the current
|
||||||
# commit is properly tagged.
|
# commit is properly tagged.
|
||||||
#
|
#
|
||||||
# * For prerelease beta versions, "v0.123.4-b.5". This version should
|
# * For prerelease alpha versions (aka snapshots), "v0.123.4-a.6+a1b2c3d4".
|
||||||
# be the one in the current tag, and the script merely checks, that
|
|
||||||
# the current commit is properly tagged.
|
|
||||||
#
|
#
|
||||||
# * For prerelease alpha versions (aka snapshots),
|
# BUG(a.garipov): The script currently can't differentiate between beta tags and
|
||||||
# "v0.123.4-a.6+a1b2c3d4".
|
# release tags if they are on the same commit, so the beta tag **must** be
|
||||||
|
# pushed and built **before** the release tag is pushed.
|
||||||
#
|
#
|
||||||
# BUG(a.garipov): The script currently can't differentiate between beta
|
# TODO(a.garipov): The script currently doesn't handle release branches, so it
|
||||||
# tags and release tags if they are on the same commit, so the beta tag
|
# must be modified once we have those.
|
||||||
# **must** be pushed and built **before** the release tag is pushed.
|
|
||||||
#
|
verbose="${VERBOSE:-0}"
|
||||||
# TODO(a.garipov): The script currently doesn't handle release branches,
|
readonly verbose
|
||||||
# so it must be modified once we have those.
|
|
||||||
|
|
||||||
readonly verbose="${VERBOSE:-0}"
|
|
||||||
if [ "$verbose" -gt '0' ]
|
if [ "$verbose" -gt '0' ]
|
||||||
then
|
then
|
||||||
set -x
|
set -x
|
||||||
|
@ -31,9 +32,9 @@ fi
|
||||||
|
|
||||||
set -e -f -u
|
set -e -f -u
|
||||||
|
|
||||||
# bump_minor is an awk program that reads a minor release version,
|
# bump_minor is an awk program that reads a minor release version, increments
|
||||||
# increments the minor part of it, and prints the next version.
|
# the minor part of it, and prints the next version.
|
||||||
readonly bump_minor='/^v[0-9]+\.[0-9]+\.0$/ {
|
bump_minor='/^v[0-9]+\.[0-9]+\.0$/ {
|
||||||
print($1 "." $2 + 1 ".0");
|
print($1 "." $2 + 1 ".0");
|
||||||
|
|
||||||
next;
|
next;
|
||||||
|
@ -44,21 +45,19 @@ readonly bump_minor='/^v[0-9]+\.[0-9]+\.0$/ {
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
}'
|
}'
|
||||||
|
readonly bump_minor
|
||||||
|
|
||||||
# get_last_minor_zero returns the last new minor release.
|
# get_last_minor_zero returns the last new minor release.
|
||||||
get_last_minor_zero() {
|
get_last_minor_zero() {
|
||||||
# List all tags. Then, select those that fit the pattern of
|
# List all tags. Then, select those that fit the pattern of a new minor
|
||||||
# a new minor release: a semver version with the patch part set
|
# release: a semver version with the patch part set to zero.
|
||||||
# to zero.
|
|
||||||
#
|
#
|
||||||
# Then, sort them first by the first field ("1"), starting with
|
# Then, sort them first by the first field ("1"), starting with the
|
||||||
# the second character to skip the "v" prefix (".2"), and only
|
# second character to skip the "v" prefix (".2"), and only spanning the
|
||||||
# spanning the first field (",1"). The sort is numeric and
|
# first field (",1"). The sort is numeric and reverse ("nr").
|
||||||
# reverse ("nr").
|
|
||||||
#
|
#
|
||||||
# Then, sort them by the second field ("2"), and only spanning
|
# Then, sort them by the second field ("2"), and only spanning the
|
||||||
# the second field (",2"). The sort is also numeric and reverse
|
# second field (",2"). The sort is also numeric and reverse ("nr").
|
||||||
# ("nr").
|
|
||||||
#
|
#
|
||||||
# Finally, get the top (that is, most recent) version.
|
# Finally, get the top (that is, most recent) version.
|
||||||
git tag\
|
git tag\
|
||||||
|
@ -67,7 +66,8 @@ get_last_minor_zero() {
|
||||||
| head -n 1
|
| head -n 1
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly channel="$CHANNEL"
|
channel="$CHANNEL"
|
||||||
|
readonly channel
|
||||||
|
|
||||||
case "$channel"
|
case "$channel"
|
||||||
in
|
in
|
||||||
|
@ -77,32 +77,36 @@ in
|
||||||
;;
|
;;
|
||||||
('edge')
|
('edge')
|
||||||
# last_minor_zero is the last new minor release.
|
# last_minor_zero is the last new minor release.
|
||||||
readonly last_minor_zero="$(get_last_minor_zero)"
|
last_minor_zero="$( get_last_minor_zero )"
|
||||||
|
readonly last_minor_zero
|
||||||
|
|
||||||
# num_commits_since_minor is the number of commits since the
|
# num_commits_since_minor is the number of commits since the last new
|
||||||
# last new minor release. If the current commit is the new
|
# minor release. If the current commit is the new minor release,
|
||||||
# minor release, num_commits_since_minor is zero.
|
# num_commits_since_minor is zero.
|
||||||
readonly num_commits_since_minor="$(git rev-list "${last_minor_zero}..HEAD" | wc -l)"
|
num_commits_since_minor="$( git rev-list "${last_minor_zero}..HEAD" | wc -l )"
|
||||||
|
readonly num_commits_since_minor
|
||||||
|
|
||||||
# next_minor is the next minor release version.
|
# next_minor is the next minor release version.
|
||||||
readonly next_minor="$(echo "$last_minor_zero" | awk -F '.' "$bump_minor")"
|
next_minor="$( echo "$last_minor_zero" | awk -F '.' "$bump_minor" )"
|
||||||
|
readonly next_minor
|
||||||
|
|
||||||
# Make this commit a prerelease version for the next minor
|
# Make this commit a prerelease version for the next minor release. For
|
||||||
# release. For example, if the last minor release was v0.123.0,
|
# example, if the last minor release was v0.123.0, and the current
|
||||||
# and the current commit is the fifth since then, the version
|
# commit is the fifth since then, the version will look something like:
|
||||||
# will look something like:
|
|
||||||
#
|
#
|
||||||
# v0.124.0-a.5+a1b2c3d4
|
# v0.124.0-a.5+a1b2c3d4
|
||||||
#
|
#
|
||||||
version="${next_minor}-a.${num_commits_since_minor}+$(git rev-parse --short HEAD)"
|
version="${next_minor}-a.${num_commits_since_minor}+$( git rev-parse --short HEAD )"
|
||||||
;;
|
;;
|
||||||
('beta'|'release')
|
('beta'|'release')
|
||||||
# current_desc is the description of the current git commit. If
|
# current_desc is the description of the current git commit. If the
|
||||||
# the current commit is tagged, git describe will show the tag.
|
# current commit is tagged, git describe will show the tag.
|
||||||
readonly current_desc="$(git describe)"
|
current_desc="$( git describe )"
|
||||||
|
readonly current_desc
|
||||||
|
|
||||||
# last_tag is the most recent git tag.
|
# last_tag is the most recent git tag.
|
||||||
readonly last_tag="$(git describe --abbrev=0)"
|
last_tag="$( git describe --abbrev=0 )"
|
||||||
|
readonly last_tag
|
||||||
|
|
||||||
# Require an actual tag for the beta and final releases.
|
# Require an actual tag for the beta and final releases.
|
||||||
if [ "$current_desc" != "$last_tag" ]
|
if [ "$current_desc" != "$last_tag" ]
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# Get admin tool port from configuration
|
|
||||||
bind_port=$(grep bind_port $SNAP_DATA/AdGuardHome.yaml | awk -F ' ' '{print $2}')
|
|
||||||
|
|
||||||
if [ -z "$bind_port" ]; then
|
# Get the admin interface port from the configuration.
|
||||||
xdg-open http://localhost:3000
|
bind_port="$( grep -e 'bind_port' "${SNAP_DATA}/AdGuardHome.yaml" | awk -F ' ' '{print $2}' )"
|
||||||
|
readonly bind_port
|
||||||
|
|
||||||
|
if [ "$bind_port" = '' ]
|
||||||
|
then
|
||||||
|
xdg-open 'http://localhost:3000'
|
||||||
else
|
else
|
||||||
xdg-open http://localhost:$bind_port
|
xdg-open "http://localhost:${bind_port}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue