Pull request: all: add a new Makefile and scripts, remove goreleaaser

Merge in DNS/adguard-home from 2276-releases to master

Updates #2276.

Squashed commit of the following:

commit 84961947c51477aae53606ec6e2e0cce0bdfc139
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Dec 30 14:36:13 2020 +0300

    all: fix github build

commit 54af2adbf2f433e80393fb142e66ba6b3a78b13e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Dec 30 14:34:02 2020 +0300

    all: remove old Dockerfile, improve build scripts

commit 99bb2f2ba1458d32074ac0911b5c02ce6669e43e
Merge: 2292b677a 5e20ac7ed
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Dec 30 13:47:19 2020 +0300

    Merge branch 'master' into WIP-2276-releases

commit 2292b677a20ce8e93d9e6e2bb042cd468606fec3
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Dec 30 13:30:10 2020 +0300

    all: improve docker build

commit 0bcc97c41f105ee4a4363f20fa4775c7643bf0cc
Merge: c7d3f12ef aef4659e9
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Dec 29 17:47:45 2020 +0300

    Merge branch 'master' into WIP-2276-releases

commit c7d3f12ef2b63ddfa2acf46e3129fcbc56fb0a90
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Dec 29 16:28:25 2020 +0300

    all: improve build scripts

commit 55de1e5d7ef0fbdbd1a76cfb71362d16ca0a1966
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Dec 29 15:36:47 2020 +0300

    all: fix Makefile

commit d11b1fe28d0fde1efeaf6160a614951b19d0ef94
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Dec 29 14:16:19 2020 +0300

    scripts: fix build-release

commit ecc0577e2451afa86c37da7283a63a9d26fb37ba
Merge: dde64ed8e 483f02c92
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Dec 29 13:59:32 2020 +0300

    Merge branch 'master' into WIP-2276-releases

commit dde64ed8e456f73559f21c2ca549dc3b46724add
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 25 18:04:46 2020 +0300

    all: imp docs, other improvements

commit be8574408db79901bb15c1d31916db3ca352a35f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 25 14:48:30 2020 +0300

    all: imp docker build

commit fc1876f34b93d667bf166226f4bc666d394f10c7
Merge: fa5a304c8 955b735c8
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 25 13:54:29 2020 +0300

    Merge branch 'master' into WIP-2276-releases

commit fa5a304c83d86145796a2de4141de6d18f7c56bf
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 19:10:51 2020 +0300

    all: improve scripts

commit 3f32e3fd5e658d058d5c5172519384efc6cfef83
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 18:50:01 2020 +0300

    all: improve scripts

commit 2d38b81421acab4b90a7a19da7598c75063e8e93
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 18:25:21 2020 +0300

    all: fix shell for windows, improve go-lint.sh

commit d695285cd6dc476c0d972cfe0c49bbeea5f5a049
Merge: 313b020e9 9fb6bf82c
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 18:14:38 2020 +0300

    Merge branch 'master' into WIP-2276-releases

commit 313b020e9dfcdab736670cee72b2171eac8c32b7
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 18:13:31 2020 +0300

    Makefile: use npm ci again

commit 5acee9d6a6c8cd2a7dd04b173a73929650882bad
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 17:57:54 2020 +0300

    all: try fixing windows build

commit c63a2a54641ac8cd032a3306bb35e49b9ae74728
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 17:39:30 2020 +0300

    all: imp scripts, try another goproxy and direct

commit 423229e8b63ee73caeee8e84c23f67d145aff9df
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Dec 24 17:25:29 2020 +0300

    all: imp HACKING.md, try a new proxy

... and 1 more commit
This commit is contained in:
Ainar Garipov
2020-12-30 18:26:25 +03:00
parent 5e20ac7ed5
commit 0e84962fde
28 changed files with 1065 additions and 663 deletions

159
scripts/README.md Normal file
View File

@@ -0,0 +1,159 @@
# AdGuard Home Scripts
## `hooks/`: Git Hooks
### Usage
Run `make init` from the project root.
## `querylog/`: Query Log Helpers
### Usage
* `npm install`: install dependencies. Run this first.
* `npm run anonymize <source> <dst>`: read the query log from the `<source>`
and write anonymized version to `<dst>`.
## `make/`: Makefile Scripts
The release channels are: `development` (the default), `edge`, `beta`, and
`release`. If verbosity levels aren't documented here, there are only two: `0`,
don't print anything, and `1`, be verbose.
### `build-docker.sh`: Build A Multi-Architecture Docker Image
Required environment:
* `CHANNEL`: release channel, see above.
* `COMMIT`: current Git revision.
* `DIST_DIR`: the directory where a release has previously been built.
* `VERSION`: release version.
Optional environment:
* `DOCKER_IMAGE_NAME`: the name of the resulting Docker container. By default
it's `adguardhome-dev`.
* `DOCKER_OUTPUT`: the `--output` parameters. By default they are
`type=image,name=${DOCKER_IMAGE_NAME},push=false`.
* `SUDO`: allow users to use `sudo` or `doas` with `docker`. By default none
is used.
### `build-release.sh`: Build A Release For All Platforms
Required environment:
* `CHANNEL`: release channel, see above.
* `GPG_KEY` and `GPG_KEY_PASSPHRASE`: data for `gpg`. Only required if `SIGN`
is `1`.
Optional environment:
* `DIST_DIR`: the directory to build a release into. The default value is
`dist`.
* `GO`: set an alternarive name for the Go compiler.
* `SIGN`: `0` to not sign the resulting packages, `1` to sign. The default
value is `1`.
* `VERBOSE`: `1` to be verbose, `2` to also print environment. This script
calls `go-build.sh` with the verbosity level one level lower, so to get
verbosity level `2` in `go-build.sh`, set this to `3` when calling
`build-release.sh`.
* `VERSION`: release version. Will be set by `version.sh` if it is unset or
it has the default `Makefile` value of `v0.0.0`.
### `clean.sh`: Cleanup
Optional environment:
* `GO`: set an alternarive name for the Go compiler.
Required environment:
* `DIST_DIR`: the directory where a release has previously been built.
### `go-build.sh`: Build The Backend
Optional environment:
* `GOARM`: ARM processor options for the Go compiler.
* `GOMIPS`: ARM processor options for the Go compiler.
* `GO`: set an alternarive name for the Go compiler.
* `OUT`: output binary name.
* `PARALLELISM`: set the maximum number of concurrently run build commands
(that is, compiler, linker, etc.).
* `VERBOSE`: verbosity level. `1` shows every command that is run and every
Go package that is processed. `2` also shows subcommands and environment.
The default value is `0`, don't be verbose.
Required environment:
* `CHANNEL`: release channel, see above.
* `VERSION`: release version.
### `go-deps.sh`: Install Backend Dependencies
Optional environment:
* `GO`: set an alternarive name for the Go compiler.
* `VERBOSE`: verbosity level. `1` shows every command that is run and every
Go package that is processed. `2` also shows subcommands and environment.
The default value is `0`, don't be verbose.
### `go-lint.sh`: Run Backend Static Analyzers
Don't forget to run `make go-tools` once first!
Optional environment:
* `EXIT_ON_ERROR`: if set to `0`, don't exit the script after the first
encountered error. The default value is `1`.
* `GO`: set an alternarive name for the Go compiler.
* `VERBOSE`: verbosity level. `1` shows every command that is run. `2` also
shows subcommands. The default value is `0`, don't be verbose.
### `go-test.sh`: Run Backend Tests
Optional environment:
* `GO`: set an alternarive name for the Go compiler.
* `RACE`: set to `0` to not use the Go race detector. The default value is
`1`, use the race detector.
* `VERBOSE`: verbosity level. `1` shows every command that is run and every
Go package that is processed. `2` also shows subcommands. The default
value is `0`, don't be verbose.
### `go-tools.sh`: Install Backend Tooling
Installs the Go static analysis and other tools into `${PWD}/bin`. Either add
`${PWD}/bin` to your `$PATH` before all other entries, or use the commands
directly, or use the commands through `make` (for example, `make go-lint`).
Optional environment:
* `GO`: set an alternarive name for the Go compiler.
### `version.sh`: Print The Current Version
Required environment:
* `CHANNEL`: release channel, see above.
## `snap/`: Snap GUI Files
App icons (see https://github.com/AdguardTeam/AdGuardHome/pull/1836), Snap
manifest file templates, and helper scripts.
## `translations/`: Twosky Integration Script
### Usage
* `npm install`: install dependencies. Run this first.
* `npm run locales:download`: download and save all translations.
* `npm run locales:upload`: upload the base `en` locale.
* `npm run locales:summary`: show the current locales summary.
* `npm run locales:unused`: show the list of unused strings.
After the download you'll find the output locales in the `client/src/__locales/`
directory.
## `whotracksme/`: Whotracks.me Database Converter
A simple script that converts the Ghostery/Cliqz trackers database to a json format.
### Usage
```sh
yarn install
node index.js
```
You'll find the output in the `whotracksmedb.json` file. Then, move it to
`client/src/helpers/trackers`.

13
scripts/hooks/pre-commit Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
set -e -f -u
if [ "$(git diff --cached --name-only -- '*.js')" ]
then
make js-lint js-test
fi
if [ "$(git diff --cached --name-only -- '*.go' 'go.mod')" ]
then
make go-lint go-test
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
# AdGuardHome installation script
# AdGuard Home Installation Script
#
# 1. Download the package
# 2. Unpack it
@@ -227,4 +227,4 @@ main() {
log_info " sudo ${AGH_DIR}/AdGuardHome -s start|stop|restart|status|install|uninstall"
}
main "$@"
main "$@"

49
scripts/make/Dockerfile Normal file
View File

@@ -0,0 +1,49 @@
# A docker file for scripts/make/build-docker.sh.
FROM alpine:3.12
ARG BUILD_DATE
ARG VERSION
ARG VCS_REF
LABEL maintainer="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.url="https://adguard.com/adguard-home.html" \
org.opencontainers.image.source="https://github.com/AdguardTeam/AdGuardHome" \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.vendor="AdGuard" \
org.opencontainers.image.title="AdGuard Home" \
org.opencontainers.image.description="Network-wide ads & trackers blocking DNS server" \
org.opencontainers.image.licenses="GPL-3.0"
# Update certificates.
RUN apk --no-cache --update add ca-certificates libcap && \
rm -rf /var/cache/apk/* && \
mkdir -p /opt/adguardhome/conf /opt/adguardhome/work && \
chown -R nobody: /opt/adguardhome
ARG DIST_DIR
ARG TARGETARCH
ARG TARGETOS
ARG TARGETVARIANT
COPY --chown=nobody:nogroup\
./${DIST_DIR}/docker/AdGuardHome_${TARGETOS}_${TARGETARCH}_${TARGETVARIANT}\
/opt/adguardhome/AdGuardHome
RUN setcap 'cap_net_bind_service=+eip' /opt/adguardhome/AdGuardHome
EXPOSE 53/tcp 53/udp 67/udp 68/udp 80/tcp 443/tcp 853/tcp 3000/tcp
VOLUME ["/opt/adguardhome/conf", "/opt/adguardhome/work"]
WORKDIR /opt/adguardhome/work
ENTRYPOINT ["/opt/adguardhome/AdGuardHome"]
CMD [ \
"--no-check-update", \
"-c", "/opt/adguardhome/conf/AdGuardHome.yaml", \
"-h", "0.0.0.0", \
"-w", "/opt/adguardhome/work", \
]

View File

@@ -0,0 +1,101 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
debug_flags='-D'
else
set +x
debug_flags=''
fi
set -e -f -u
# Require these to be set. The channel value is validated later.
readonly channel="$CHANNEL"
readonly commit="$COMMIT"
readonly dist_dir="$DIST_DIR"
readonly version="$VERSION"
# Allow users to use sudo.
readonly sudo_cmd="${SUDO:-}"
readonly docker_platforms="\
linux/386,\
linux/amd64,\
linux/arm/v6,\
linux/arm/v7,\
linux/arm64,\
linux/ppc64le"
readonly build_date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
# Set DOCKER_IMAGE_NAME to 'adguard/adguard-home' if you want (and are
# allowed) to push to DockerHub.
readonly docker_image_name="${DOCKER_IMAGE_NAME:-adguardhome-dev}"
# Set DOCKER_OUTPUT to 'type=image,name=adguard/adguard-home,push=true'
# if you want (and are allowed) to push to DockerHub.
readonly docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}"
case "$channel"
in
('release')
readonly docker_image_full_name="${docker_image_name}:${version}"
readonly docker_tags="--tag ${docker_image_name}:latest"
;;
('beta')
readonly docker_image_full_name="${docker_image_name}:${version}"
readonly docker_tags="--tag ${docker_image_name}:beta"
;;
('edge')
# Don't set the version tag when pushing to the edge channel.
readonly docker_image_full_name="${docker_image_name}:edge"
readonly docker_tags=''
;;
('development')
readonly docker_image_full_name="${docker_image_name}"
readonly docker_tags=''
;;
(*)
echo "invalid channel '$channel', supported values are\
'development', 'edge', 'beta', and 'release'" 1>&2
exit 1
;;
esac
# 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"
cp "${dist_dir}/AdGuardHome_linux_386/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_386_"
cp "${dist_dir}/AdGuardHome_linux_amd64/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_amd64_"
cp "${dist_dir}/AdGuardHome_linux_arm64/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_arm64_"
cp "${dist_dir}/AdGuardHome_linux_arm_6/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_arm_v6"
cp "${dist_dir}/AdGuardHome_linux_arm_7/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_arm_v7"
cp "${dist_dir}/AdGuardHome_linux_ppc64le/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_ppc64le_"
# Don't use quotes with $docker_tags and $debug_flags because we want
# word splitting and or an empty space if tags are empty.
$sudo_cmd docker\
$debug_flags\
buildx build\
--build-arg BUILD_DATE="$build_date"\
--build-arg DIST_DIR="$dist_dir"\
--build-arg VCS_REF="$commit"\
--build-arg VERSION="$version"\
--output "$docker_output"\
--platform "$docker_platforms"\
$docker_tags\
-t "$docker_image_full_name"\
-f ./scripts/make/Dockerfile\
.

View File

@@ -0,0 +1,325 @@
#!/bin/sh
# AdGuard Home Release Script
#
# The commentary in this file is written with the assumption that the
# reader only has superficial knowledge of the POSIX shell language and
# alike. Experienced readers may find it overly verbose.
# The default verbosity level is 0. Show every command that is run if
# the caller requested verbosity level greater than 0. Show the
# environment if the callre requested verbosity level greater than 1.
# Otherwise, print nothing.
#
# The level of verbosity for the build script is the same minus one
# level. See below in build().
readonly verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '1' ]
then
env
set -x
elif [ "$verbose" -gt '0' ]
then
set -x
fi
# By default, sign the packages, but allow users to skip that step.
readonly sign="${SIGN:-1}"
# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u
# 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
# Don't use quotes to get word splitting.
echo $@ 1>&2
fi
}
log 'starting to build AdGuard Home release'
# Require the channel to be set. Additional validation is performed
# later by go-build.sh.
readonly channel="$CHANNEL"
# Check VERSION against the default value from the Makefile. If it is
# that, use the version calculation script.
if [ "${VERSION:-}" = 'v0.0.0' -o "${VERSION:-}" = '' ]
then
readonly version="$(sh ./scripts/make/version.sh)"
else
readonly version="$VERSION"
fi
log "channel '$channel'"
log "version '$version'"
# Require the gpg key and passphrase to be set if the signing is
# required.
if [ "$sign" = '1' ]
then
readonly gpg_key_passphrase="$GPG_KEY_PASSPHRASE"
readonly gpg_key="$GPG_KEY"
fi
# The default distribution files directory is dist.
readonly dist="${DIST_DIR:-dist}"
# Give users the ability to override the go command from environment.
# For example, to build two releases with two different Go versions and
# test the difference.
readonly go="${GO:-go}"
log "checking tools"
# Make sure we fail gracefully if one of the tools we need is missing.
for tool in gpg gzip sed sha256sum snapcraft tar zip
do
which "$tool" >/dev/null ||\
{ log "pieces don't fit, '$tool' not found"; exit 1; }
done
# Data section. Arrange data into space-separated tables for read -r to
# read. Use 0 for missing values.
readonly arms='5
6
7'
readonly mipses='softfloat'
# os arch arm mips snap
readonly platforms="\
darwin 386 0 0 0
darwin amd64 0 0 0
freebsd 386 0 0 0
freebsd amd64 0 0 0
freebsd arm 5 0 0
freebsd arm 6 0 0
freebsd arm 7 0 0
linux 386 0 0 i386
linux amd64 0 0 amd64
linux arm 5 0 0
linux arm 6 0 0
linux arm 7 0 armhf
linux arm64 0 0 arm64
linux mips 0 softfloat 0
linux mips64 0 softfloat 0
linux mips64le 0 softfloat 0
linux mipsle 0 softfloat 0
linux ppc64le 0 0 0
windows 386 0 0 0
windows amd64 0 0 0"
# Function build builds the release for one platform. It builds
# a binary, an archive and, if needed, a snap package.
build() {
# Get the arguments. Here and below, use the "build_" prefix
# for all variables local to function build.
build_dir="${dist}/${1}/AdGuardHome"\
build_ar="$2"\
build_os="$3"\
build_arch="$4"\
build_arm="$5"\
build_mips="$6"\
build_snap="$7"\
;
# Use the ".exe" filename extension if we build a Windows
# release.
if [ "$build_os" = 'windows' ]
then
build_output="./${build_dir}/AdGuardHome.exe"
else
build_output="./${build_dir}/AdGuardHome"
fi
mkdir -p "./${build_dir}"
# Build the binary.
#
# Set GOARM and GOMIPS to an empty string if $build_arm and
# $build_mips are zero by removing the zero as if it's a prefix.
#
# Don't use quotes with $build_par because we want an empty
# space if parallelism wasn't set.
env\
GOARCH="$build_arch"\
GOARM="${build_arm#0}"\
GOMIPS="${build_mips#0}"\
GOOS="$os"\
VERBOSE="$(( verbose - 1 ))"\
OUT="$build_output"\
sh ./scripts/make/go-build.sh\
;
log "$build_output"
if [ "$sign" = '1' ]
then
gpg\
--default-key "$gpg_key"\
--detach-sig\
--passphrase "$gpg_key_passphrase"\
--pinentry-mode loopback\
-q\
"$build_output"\
;
fi
# Prepare the build directory for archiving.
cp ./CHANGELOG.md ./LICENSE.txt ./README.md "$build_dir"
# Make archives. Windows and macOS prefer ZIP archives; the
# rest, gzipped tarballs.
case "$build_os"
in
('darwin'|'windows')
build_archive="./${dist}/${build_ar}.zip"
zip -9 -q "$build_archive" "$build_dir"
;;
(*)
build_archive="./${dist}/${build_ar}.tar.gz"
tar -C "./${dist}/${1}" -c -f - "./AdGuardHome"\
| gzip -9 - >"$build_archive"
;;
esac
log "$build_archive"
if [ "$build_snap" = '0' ]
then
return
fi
# Prepare snap build.
build_snap_output="./${dist}/AdGuardHome_${build_snap}.snap"
build_snap_dir="${build_snap_output}.dir"
# Create the meta subdirectory and copy files there.
mkdir -p "${build_snap_dir}/meta"
cp "$build_output"\
'./scripts/snap/local/adguard-home-web.sh'\
"$build_snap_dir"
cp -r './scripts/snap/gui'\
"${build_snap_dir}/meta/"
# Create a snap.yaml file, setting the values.
sed -e 's/%VERSION%/'"$version"'/'\
-e 's/%ARCH%/'"$build_snap"'/'\
./scripts/snap/snap.tmpl.yaml\
>"${build_snap_dir}/meta/snap.yaml"
# TODO(a.garipov): The snapcraft tool will *always* write
# everything, including errors, to stdout. And there doesn't
# seem to be a way to change that. So, save the combined
# output, but only show it when snapcraft actually fails.
set +e
build_snapcraft_output="$(
snapcraft pack "$build_snap_dir"\
--output "$build_snap_output" 2>&1
)"
build_snapcraft_exit_code="$?"
set -e
if [ "$build_snapcraft_exit_code" != '0' ]
then
log "$build_snapcraft_output"
exit "$build_snapcraft_exit_code"
fi
log "$build_snap_output"
}
log "starting builds"
# Go over all platforms defined in the space-separated table above,
# tweak the values where necessary, and feed to build.
echo "$platforms" | while read -r os arch arm mips snap
do
case "$arch"
in
(arm)
dir="AdGuardHome_${os}_${arch}_${arm}"
ar="AdGuardHome_${os}_${arch}v${arm}"
;;
(mips*)
dir="AdGuardHome_${os}_${arch}_${mips}"
ar="$dir"
;;
(*)
dir="AdGuardHome_${os}_${arch}"
ar="$dir"
;;
esac
build "$dir" "$ar" "$os" "$arch" "$arm" "$mips" "$snap"
done
log "calculating checksums"
# Calculate the checksums of the files in a subshell with file expansion
# enabled (+f) so that we don't need to use find or basename.
(
set +f
cd "./${dist}"
# Don't use quotes to get word splitting.
sha256sum $(ls *.tar.gz *.zip) > ./checksums.txt
)
log "writing versions"
echo "$version" > "./${dist}/version.txt"
# Create the verison.json file.
readonly version_download_url="https://static.adguard.com/adguardhome/${channel}"
readonly version_json="./${dist}/version.json"
# Point users to the master branch if the channel is edge.
if [ "$channel" = 'edge' ]
then
readonly version_history_url='https://github.com/AdguardTeam/AdGuardHome/commits/master'
else
readonly version_history_url='https://github.com/AdguardTeam/AdGuardHome/releases'
fi
rm -f "$version_json"
echo "{
\"version\": \"${version}\",
\"announcement\": \"AdGuard Home ${version} is now available!\",
\"announcement_url\": \"${version_history_url}\",
\"selfupdate_min_version\": \"0.0\",
" >> "$version_json"
(
# Use +f here so that ls works and we don't need to use find.
set +f
# Don't use quotes to get word splitting.
for f in $(ls "./${dist}/"*.tar.gz "./${dist}/"*.zip)
do
platform="$f"
# Remove the prefix.
platform="${platform#./${dist}/AdGuardHome_}"
# Remove the filename extensions.
platform="${platform%.zip}"
platform="${platform%.tar.gz}"
# Use the filename's base path.
filename="${f#./${dist}/}"
echo " \"download_${platform}\": \"${version_download_url}/${filename}\"," >> "$version_json"
done
)
echo '}' >> "$version_json"
log "finished"

33
scripts/make/clean.sh Normal file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
dist_dir="$DIST_DIR"
go="${GO:-go}"
# Set the GOPATH explicitly in case make clean is called from under sudo
# after a Docker build.
env PATH="$("$go" env GOPATH)/bin":"$PATH" packr clean
rm -f\
./AdGuardHome\
./AdGuardHome.exe\
./coverage.txt\
;
rm -f -r\
./bin/\
./build/\
./build2/\
./client/node_modules/\
./client2/node_modules/\
./data/\
"./${dist_dir}/"\
;

98
scripts/make/go-build.sh Normal file
View File

@@ -0,0 +1,98 @@
#!/bin/sh
# AdGuard Home Build Script
#
# The commentary in this file is written with the assumption that the
# reader only has superficial knowledge of the POSIX shell language and
# alike. 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}"
if [ "$verbose" -gt '1' ]
then
env
set -x
readonly v_flags='-v'
readonly x_flags='-x'
elif [ "$verbose" -gt '0' ]
then
set -x
readonly v_flags='-v'
readonly x_flags=''
else
set +x
readonly v_flags=''
readonly x_flags=''
fi
# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u
# Allow users to set the Go version.
go="${GO:-go}"
# Require the channel to be set and validate the value.
channel="$CHANNEL"
case "$channel"
in
('development'|'edge'|'beta'|'release')
# All is well, go on.
;;
(*)
echo "invalid channel '$channel', supported values are\
'development', 'edge', 'beta', and 'release'" 1>&2
exit 1
;;
esac
# Require the version to be set.
#
# TODO(a.garipov): Additional validation?
version="$VERSION"
# Set the linker flags accordingly: set the channel and the versio as
# well as goarm and gomips variable values, if the variables are set and
# are not empty.
ldflags="-s -w -X main.version=${version}"
ldflags="${ldflags} -X main.channel=${channel}"
if [ "${GOARM:-}" != '' ]
then
ldflags="${ldflags} -X main.goarm=${GOARM}"
elif [ "${GOMIPS:-}" != '' ]
then
ldflags="${ldflags} -X main.gomips=${GOMIPS}"
fi
# Allow users to limit the build's parallelism.
readonly parallelism="${PARALLELISM:-}"
if [ "$parallelism" != '' ]
then
readonly par_flags="-p ${parallelism}"
else
readonly par_flags=''
fi
# Allow users to specify a different output name.
readonly out="${OUT:-}"
if [ "$out" != '' ]
then
readonly out_flags="-o ${out}"
else
readonly out_flags=''
fi
# Don't use cgo. Use modules.
export CGO_ENABLED='0' GO111MODULE='on'
readonly build_flags="${BUILD_FLAGS:-$out_flags $par_flags\
$v_flags $x_flags}"
# Don't use quotes with flag variables to get word splitting.
"$go" generate $v_flags $x_flags ./...
# Don't use quotes with flag variables to get word splitting.
"$go" build --ldflags "$ldflags" $build_flags

31
scripts/make/go-deps.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '1' ]
then
env
set -x
readonly v_flags='-v'
readonly x_flags='-x'
elif [ "$verbose" -gt '0' ]
then
set -x
readonly v_flags='-v'
readonly x_flags=''
else
set +x
readonly v_flags=''
readonly x_flags=''
fi
set -e -f -u
go="${GO:-go}"
# Don't use quotes with flag variables because we want an empty space if
# those aren't set.
"$go" mod download $x_flags
env GOBIN="${PWD}/bin" "$go" install $v_flags $x_flags\
github.com/gobuffalo/packr/packr

View File

@@ -1,13 +1,23 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
# Verbosity levels:
# 0 = Don't print anything except for errors.
# 1 = Print commands, but not nested commands.
# 2 = Print everything.
test "${VERBOSE:=0}" -gt '0' && set -x
if [ "$verbose" -gt '0' ]
then
set -x
fi
# Set $EXITONERROR to zero to see all errors.
test "${EXITONERROR:=1}" = '0' && set +e || set -e
# Set $EXIT_ON_ERROR to zero to see all errors.
if [ "${EXIT_ON_ERROR:-1}" = '0' ]
then
set +e
else
set -e
fi
# We don't need glob expansions and we want to see errors about unset
# variables.
@@ -17,7 +27,7 @@ not_found_msg='
looks like a binary not found error.
make sure you have installed the linter binaries using:
$ make go-install-tools
$ make go-tools
'
not_found() {
@@ -95,7 +105,8 @@ ineffassign .
unparam ./...
git ls-files -- '*.go' '*.md' '*.yaml' '*.yml' | xargs misspell --error
git ls-files -- '*.go' '*.md' '*.yaml' '*.yml' 'Makefile'\
| xargs misspell --error
looppointer ./...

41
scripts/make/go-test.sh Normal file
View File

@@ -0,0 +1,41 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
# Verbosity levels:
# 0 = Don't print anything except for errors.
# 1 = Print commands, but not nested commands.
# 2 = Print everything.
if [ "$verbose" -gt '1' ]
then
set -x
v_flags='-v'
x_flags='-x'
elif [ "$verbose" -gt '0' ]
then
set -x
v_flags='-v'
x_flags=''
else
set +x
v_flags=''
x_flags=''
fi
set -e -f -u
race="${RACE:-1}"
if [ "$race" = '0' ]
then
race_flags=''
else
race_flags='--race'
fi
go="${GO:-go}"
cover_flags='--coverprofile ./coverage.txt'
count_flags='--count 1'
# Don't use quotes with flag variables because we want an empty space if
# those aren't set.
"$go" test $race_flags $count_flags $cover_flags $x_flags $v_flags ./...

View File

@@ -1,6 +1,12 @@
#!/bin/sh
test "$VERBOSE" = '1' && set -x
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
# TODO(a.garipov): Add goconst?

57
scripts/make/version.sh Normal file
View File

@@ -0,0 +1,57 @@
#!/bin/sh
readonly verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '1' ]
then
set -x
fi
set -e -f -u
readonly awk_program='/^v[0-9]+\.[0-9]+\.[0-9]+.*$/ {
if (!$4) {
# The last tag is a full release version, so bump the
# minor one to get the next one.
$2++;
}
print($1 "." $2 "." $3);
next;
}
{
printf("invalid version: \"%s\"\n", $0);
exit 1;
}'
readonly last_tag="$(git describe --abbrev=0)"
readonly current_desc="$(git describe)"
readonly channel="$CHANNEL"
case "$channel"
in
('development')
echo 'v0.0.0'
;;
('edge')
next=$(echo $last_tag | awk -F '[.+-]' "$awk_program")
echo "${next}-SNAPSHOT-$(git rev-parse --short HEAD)"
;;
('beta'|'release')
if [ "$current_desc" != "$last_tag" ]
then
echo 'need a tag' 1>&2
exit 1
fi
echo "$last_tag"
;;
(*)
echo "invalid channel '$channel', supported values are\
'development', 'edge', 'beta', and 'release'" 1>&2
exit 1
;;
esac

View File

@@ -1,10 +0,0 @@
# Helper tools to work with the Query log
### Usage
- `npm install` - Install the dependencies
- `npm run anonymize <source> <dst>` - Reads querylog from the `<source>` and writes anonymized version to `<dst>`
### Examples
- `npm run anonymize test/querylog.json test/anonquerylog.json` - anonymizes the `test/querylog.json`.

View File

@@ -1,6 +0,0 @@
# Snap GUI
These files are added to the AdGuard Home snap in order to add an app icon:
https://github.com/AdguardTeam/AdGuardHome/pull/1836
See .goreleaser.yml: snapcrafts.extra_files

View File

@@ -0,0 +1,37 @@
# The %VARIABLES% are be replaced by actual values by the build script.
'name': 'adguard-home'
'base': 'core20'
'version': '%VERSION%'
'summary': Network-wide ads & trackers blocking DNS server
'description': |
AdGuard Home is a network-wide software for blocking ads & tracking. After
you set it up, it'll cover ALL your home devices, and you don't need any
client-side software for that.
It operates as a DNS server that re-routes tracking domains to a "black hole,"
thus preventing your devices from connecting to those servers. It's based
on software we use for our public AdGuard DNS servers -- both share a lot
of common code.
'grade': 'stable'
'confinement': 'strict'
'architectures':
- '%ARCH%'
'apps':
'adguard-home':
'command': 'AdGuardHome --no-check-update -w $SNAP_DATA'
'plugs':
# Add the "netrwork-bind" plug to bind to interfaces.
- 'network-bind'
# Add the "netrwork-observe" plug to be able to bind to ports below 1024
# (cap_net_bind_service) and also to bind to a particular interface using
# SO_BINDTODEVICE (cap_net_raw).
- 'network-observe'
'daemon': 'simple'
'restart-condition': 'always'
'adguard-home-web':
'command': 'adguard-home-web.sh'
'plugs':
- 'desktop'

View File

@@ -1,11 +0,0 @@
## Twosky integration script
### Usage
- `npm install` Install the dependencies in the local node_modules folder
- `npm run locales:download` - Download and save all translations
- `npm run locales:upload` - Upload base `en` locale
- `npm run locales:summary` - Shows the current locales summary
- `npm run locales:unused` - Shows a list of unused strings
After download you'll find the output locales in the `client/src/__locales/` folder.

View File

@@ -1,13 +0,0 @@
## Whotracks.me database converter
A simple script that converts the Ghostery/Cliqz trackers database to a json format.
### Usage
```
yarn install
node index.js
```
You'll find the output in the `whotracksmedb.json` file.
Move it to `client/src/helpers/trackers`.