2023-06-21 15:14:10 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
verbose="${VERBOSE:-0}"
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
if [ "$verbose" -gt '0' ]; then
|
2023-06-21 15:14:10 +01:00
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
# TODO(a.garipov): Add to helpers.sh and use more actively in scripts.
|
|
|
|
log() {
|
2024-11-08 14:18:16 +00:00
|
|
|
if [ "$verbose" -gt '0' ]; then
|
2023-06-21 15:14:10 +01:00
|
|
|
# Don't use quotes to get word splitting.
|
|
|
|
echo "$1" 1>&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
version="$(./AdGuardHome_amd64 --version | cut -d ' ' -f 4)"
|
|
|
|
if [ "$version" = '' ]; then
|
2023-06-21 15:14:10 +01:00
|
|
|
log 'empty version from ./AdGuardHome_amd64'
|
2024-11-08 14:18:16 +00:00
|
|
|
|
2023-06-21 15:14:10 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
readonly version
|
|
|
|
|
|
|
|
log "version '$version'"
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
for arch in \
|
|
|
|
'amd64' \
|
|
|
|
'arm64' \
|
|
|
|
'armhf' \
|
|
|
|
'i386'; do
|
2023-06-21 15:14:10 +01:00
|
|
|
build_output="./AdGuardHome_${arch}"
|
|
|
|
snap_output="./AdGuardHome_${arch}.snap"
|
|
|
|
snap_dir="${snap_output}.dir"
|
|
|
|
|
|
|
|
# Create the meta subdirectory and copy files there.
|
|
|
|
mkdir -p "${snap_dir}/meta"
|
|
|
|
cp "$build_output" "${snap_dir}/AdGuardHome"
|
|
|
|
cp './snap/local/adguard-home-web.sh' "$snap_dir"
|
|
|
|
cp -r './snap/gui' "${snap_dir}/meta/"
|
|
|
|
|
|
|
|
# Create a snap.yaml file, setting the values.
|
2024-11-08 14:18:16 +00:00
|
|
|
sed \
|
|
|
|
-e 's/%VERSION%/'"$version"'/' \
|
|
|
|
-e 's/%ARCH%/'"$arch"'/' \
|
|
|
|
./snap/snap.tmpl.yaml \
|
|
|
|
>"${snap_dir}/meta/snap.yaml"
|
2023-06-21 15:14:10 +01:00
|
|
|
|
|
|
|
# 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
|
2024-11-08 14:18:16 +00:00
|
|
|
snapcraft_output="$(snapcraft pack "$snap_dir" --output "$snap_output" 2>&1)"
|
2023-06-21 15:14:10 +01:00
|
|
|
snapcraft_exit_code="$?"
|
|
|
|
set -e
|
|
|
|
|
2024-11-08 14:18:16 +00:00
|
|
|
if [ "$snapcraft_exit_code" -ne '0' ]; then
|
2023-06-21 15:14:10 +01:00
|
|
|
log "$snapcraft_output"
|
|
|
|
exit "$snapcraft_exit_code"
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "$snap_output"
|
|
|
|
|
|
|
|
rm -f -r "$snap_dir"
|
|
|
|
done
|