mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 21:15:35 +03:00
0e84962fde
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: 2292b677a5e20ac7ed
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: c7d3f12efaef4659e9
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: dde64ed8e483f02c92
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: fa5a304c8955b735c8
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: 313b020e99fb6bf82c
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
325 lines
8.2 KiB
Bash
325 lines
8.2 KiB
Bash
#!/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"
|