Skip to content

Commit

Permalink
all: imp scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed May 19, 2021
1 parent b3d2840 commit e6e4375
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 307 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'restore-keys': '${{ runner.os }}-go-'
- 'name': 'Get npm cache directory'
'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'
'uses': 'actions/cache@v2'
'with':
Expand Down
22 changes: 21 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ on GitHub and most other Markdown renderers. -->
* 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.
* Put spaces within `$( cmd )`, `$(( expr ))`, and `{ cmd; }`.
Expand All @@ -330,7 +350,7 @@ on GitHub and most other Markdown renderers. -->
* UPPERCASE names for external exported variables, lowercase for local,
unexported ones.
* Use `readonly` liberally.
* Use `=` for strings and `-eq` for numbers.
* Use `set -e -f -u` and also `set -x` in verbose mode.
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ go-os-check:

openapi-lint: ; cd ./openapi/ && $(YARN) test
openapi-show: ; cd ./openapi/ && $(YARN) start

txt-lint: ; $(ENV) "$(SHELL)" ./scripts/make/txt-lint.sh
4 changes: 3 additions & 1 deletion bamboo-specs/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@
cd ./dist/
export CHANNEL="${bamboo.channel}"
CHANNEL="${bamboo.channel}"
export CHANNEL
../bamboo-deploy-publisher/deploy.sh adguard-home-"$CHANNEL"
'final-tasks':
- 'clean'
Expand Down
13 changes: 9 additions & 4 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@

set -e -f -u

if [ "$(git diff --cached --name-only -- 'client/*.js')" ]
if [ "$( git diff --cached --name-only -- 'client/*.js' )" ]
then
make js-lint js-test
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
make js-beta-lint js-beta-test
fi

if [ "$(git diff --cached --name-only -- '*.go' 'go.mod')" ]
if [ "$( git diff --cached --name-only -- '*.go' '*.mod' '*.sh' 'Makefile' )" ]
then
make go-os-check go-lint go-test
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
make openapi-lint
fi
36 changes: 21 additions & 15 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ is_little_endian() {
# unzip (macOS) / tar (other unices)
#
check_required() {
readonly required_darwin="unzip"
readonly required_unix="tar"
required_darwin="unzip"
required_unix="tar"
readonly required_darwin required_unix

# Split with space.
required="curl"
Expand Down Expand Up @@ -132,7 +133,7 @@ parse_opts() {
esac
done

if [ "$uninstall" = '1' ] && [ "$reinstall" = '1' ]
if [ "$uninstall" -eq '1' ] && [ "$reinstall" -eq '1' ]
then
error_exit 'the -r and -u options are mutually exclusive'
fi
Expand Down Expand Up @@ -277,7 +278,9 @@ fix_freebsd() {
return 0
fi

readonly rcd='/usr/local/etc/rc.d'
rcd='/usr/local/etc/rc.d'
readonly rcd

if ! [ -d "$rcd" ]
then
mkdir "$rcd"
Expand All @@ -292,16 +295,17 @@ configure() {
fix_darwin
check_out_dir

readonly pkg_name="AdGuardHome_${os}_${cpu}.${pkg_ext}"
readonly url="https://static.adguard.com/adguardhome/${channel}/${pkg_name}"
readonly agh_dir="${out_dir}/AdGuardHome"
pkg_name="AdGuardHome_${os}_${cpu}.${pkg_ext}"
url="https://static.adguard.com/adguardhome/${channel}/${pkg_name}"
agh_dir="${out_dir}/AdGuardHome"
readonly pkg_name url agh_dir

log "AdGuard Home will be installed into $agh_dir"
}

# Function is_root checks for root privileges to be granted.
is_root() {
if [ "$( id -u )" = '0' ]
if [ "$( id -u )" -eq '0' ]
then
log 'script is executed with root privileges'

Expand All @@ -325,24 +329,26 @@ please, restart it with root privileges'
#
# TODO(e.burkov): Try to avoid restarting.
rerun_with_root() {
readonly script_url=\
script_url=\
'https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh'
readonly script_url

flags=''
if [ "$reinstall" = '1' ]
if [ "$reinstall" -eq '1' ]
then
flags="${flags} -r"
fi
if [ "$uninstall" = '1' ]
if [ "$uninstall" -eq '1' ]
then
flags="${flags} -u"
fi
if [ "$verbose" = '1' ]
if [ "$verbose" -eq '1' ]
then
flags="${flags} -v"
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'

Expand Down Expand Up @@ -397,7 +403,7 @@ handle_existing() {
then
log 'no need to uninstall'

if [ "$uninstall" = '1' ]
if [ "$uninstall" -eq '1' ]
then
exit 0
fi
Expand Down Expand Up @@ -428,7 +434,7 @@ handle_existing() {
log 'AdGuard Home was successfully uninstalled'
fi

if [ "$uninstall" = '1' ]
if [ "$uninstall" -eq '1' ]
then
exit 0
fi
Expand Down
66 changes: 38 additions & 28 deletions scripts/make/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,70 +14,80 @@ 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"
channel="$CHANNEL"
commit="$COMMIT"
dist_dir="$DIST_DIR"
readonly channel commit dist_dir

if [ "${VERSION:-}" = 'v0.0.0' ] || [ "${VERSION:-}" = '' ]
then
readonly version="$(sh ./scripts/make/version.sh)"
version="$( sh ./scripts/make/version.sh )"
else
readonly version="$VERSION"
version="$VERSION"
fi
readonly version

echo $version

# Allow users to use sudo.
readonly sudo_cmd="${SUDO:-}"
sudo_cmd="${SUDO:-}"
readonly sudo_cmd

readonly docker_platforms="\
docker_platforms="\
linux/386,\
linux/amd64,\
linux/arm/v6,\
linux/arm/v7,\
linux/arm64,\
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
# allowed) to push to DockerHub.
readonly docker_image_name="${DOCKER_IMAGE_NAME:-adguardhome-dev}"
# Set DOCKER_IMAGE_NAME to 'adguard/adguard-home' if you want (and are allowed)
# to push to DockerHub.
docker_image_name="${DOCKER_IMAGE_NAME:-adguardhome-dev}"
readonly docker_image_name

# 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}"
# Set DOCKER_OUTPUT to 'type=image,name=adguard/adguard-home,push=true' if you
# want (and are allowed) to push to DockerHub.
docker_output="${DOCKER_OUTPUT:-type=image,name=${docker_image_name},push=false}"
readonly docker_output

case "$channel"
in
('release')
readonly docker_image_full_name="${docker_image_name}:${version}"
readonly docker_tags="--tag ${docker_image_name}:latest"
docker_image_full_name="${docker_image_name}:${version}"
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"
docker_image_full_name="${docker_image_name}:${version}"
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=''
docker_image_full_name="${docker_image_name}:edge"
docker_tags=''
;;
('development')
readonly docker_image_full_name="${docker_image_name}"
readonly docker_tags=''
docker_image_full_name="${docker_image_name}"
docker_tags=''
;;
(*)
echo "invalid channel '$channel', supported values are\
'development', 'edge', 'beta', and 'release'" 1>&2
exit 1
;;
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"
cp "${dist_dir}/AdGuardHome_linux_386/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_386_"
Expand All @@ -92,8 +102,8 @@ cp "${dist_dir}/AdGuardHome_linux_arm_7/AdGuardHome/AdGuardHome"\
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.
# 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\
Expand Down
Loading

0 comments on commit e6e4375

Please sign in to comment.