71 lines
2.6 KiB
Bash
Executable File
71 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
umask 022
|
|
|
|
IMAGE="andrius/asterisk:22"
|
|
PROJECT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
OUTPUT_DIR="$PROJECT_DIR/offline/images"
|
|
PULL_IMAGE=1
|
|
|
|
usage() {
|
|
cat <<'USAGE'
|
|
Usage: ./save-asterisk-image.sh [--no-pull] [--output-dir DIR]
|
|
|
|
Pulls the project's Asterisk image unless --no-pull is set, then saves a
|
|
compressed Docker image archive and SHA-256 sidecar. The installer build embeds
|
|
this archive in the Debian package so target servers do not need Docker Hub.
|
|
This script does not start an Asterisk container.
|
|
USAGE
|
|
}
|
|
|
|
while (($#)); do
|
|
case "$1" in
|
|
--output-dir)
|
|
(($# >= 2)) || { usage >&2; exit 2; }
|
|
OUTPUT_DIR="$2"
|
|
shift
|
|
;;
|
|
--no-pull) PULL_IMAGE=0 ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) usage >&2; exit 2 ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
command -v docker >/dev/null 2>&1 || { printf 'docker is required\n' >&2; exit 1; }
|
|
command -v gzip >/dev/null 2>&1 || { printf 'gzip is required\n' >&2; exit 1; }
|
|
|
|
DOCKER_ARCH="$(docker info --format '{{.Architecture}}')"
|
|
case "$DOCKER_ARCH" in
|
|
x86_64|amd64) ARCH=amd64 ;;
|
|
*) printf 'Raymand CTI installer supports amd64 only (Docker reports %s).\n' "$DOCKER_ARCH" >&2; exit 1 ;;
|
|
esac
|
|
|
|
mkdir -p -- "$OUTPUT_DIR"
|
|
OUTPUT_FILE="$OUTPUT_DIR/asterisk-22-$ARCH.tar.gz"
|
|
TEMP_FILE="$(mktemp "$OUTPUT_DIR/.asterisk-22-$ARCH.XXXXXX")"
|
|
trap 'rm -f -- "$TEMP_FILE"' EXIT
|
|
|
|
if ((PULL_IMAGE == 1)); then
|
|
printf '[asterisk-image] Pulling %s for linux/%s\n' "$IMAGE" "$ARCH"
|
|
docker pull --platform "linux/$ARCH" "$IMAGE"
|
|
else
|
|
command -v docker >/dev/null 2>&1 && docker image inspect "$IMAGE" >/dev/null 2>&1 \
|
|
|| { printf 'Image %s is not loaded locally; load it first or omit --no-pull.\n' "$IMAGE" >&2; exit 1; }
|
|
LOCAL_ARCH="$(docker image inspect --format '{{.Architecture}}' "$IMAGE")"
|
|
[[ "$LOCAL_ARCH" == "$ARCH" ]] \
|
|
|| { printf 'Local image architecture is %s, expected %s.\n' "$LOCAL_ARCH" "$ARCH" >&2; exit 1; }
|
|
printf '[asterisk-image] Reusing local image %s for linux/%s\n' "$IMAGE" "$ARCH"
|
|
fi
|
|
|
|
printf '[asterisk-image] Saving compressed Docker archive to %s\n' "$OUTPUT_FILE"
|
|
docker save --platform "linux/$ARCH" "$IMAGE" | gzip -1 >"$TEMP_FILE"
|
|
mv -f -- "$TEMP_FILE" "$OUTPUT_FILE"
|
|
(cd -- "$(dirname -- "$OUTPUT_FILE")" && sha256sum "$(basename -- "$OUTPUT_FILE")") \
|
|
>"$OUTPUT_FILE.sha256"
|
|
|
|
IMAGE_ID="$(docker image inspect --format '{{.Id}}' "$IMAGE")"
|
|
printf '[asterisk-image] Image: %s\n[asterisk-image] ID: %s\n[asterisk-image] SHA-256: ' "$IMAGE" "$IMAGE_ID"
|
|
awk '{print $1}' "$OUTPUT_FILE.sha256"
|
|
printf '[asterisk-image] Archive and checksum are ready for the installer build.\n'
|