docker-images/images/minetest-mapserver/minetest-mapserver.sh

65 lines
2.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# The architecture - possible values: arm (default), x86, x86_64
2022-11-07 00:40:44 +00:00
arch="${arch:-arm}";
# download_url="https://github.com/minetest-mapserver/mapserver/releases/latest/download/mapserver-linux-${arch}";
2022-11-07 00:40:44 +00:00
download_url="$(curl -sSL https://api.github.com/repos/minetest-mapserver/mapserver/releases/58437588/assets | jq --raw-output '.[] | select(.browser_download_url | contains("_armv")) | .browser_download_url' | head -n1)";
# The registry to push to
DOCKER_REGISTRY="${DOCKER_REGISTRY:-registry.service.mooncarrot.space:5000/}";
if [[ "${DOCKER_REGISTRY}" == "hub" ]]; then DOCKER_REGISTRY=""; fi
###############################################################################
# Make sure the current directory is the location of this script to simplify matters
cd "$(dirname "$(readlink -f "$0")")" || { echo "[minetest-mapserver] Error: Failed to cd"; exit 1; };
temp_dir="$(mktemp --tmpdir -d "minetest-mapserver-XXXXXXX")";
on_exit() {
log_msg "Cleaning up";
rm -rf "${temp_dir}";
}
trap on_exit EXIT;
# Ref https://stackoverflow.com/a/911213/1460422
if [ -t 1 ] || [[ ! -z "${FORCE_COLOUR}" ]]; then
###################
# From lantern.sh #
RS="\033[0m" # reset
HC="\033[1m" # hicolor
LC="\033[2m" # locolor / dim
###################
fi
log_msg() {
echo -e "${HC}>>>${RS} ${LC}[ ${SECONDS} ]${RS} $*" >&2;
}
###############################################################################
log_msg "Downloading mapserver";
curl -sSL -o "${temp_dir}/mapserver.tar.gz" "${download_url}";
tar -xf "${temp_dir}/mapserver.tar.gz" -C "${temp_dir}";
chmod +x "${temp_dir}/mapserver";
log_msg "Determining version";
version="$(curl -sSL https://api.github.com/repos/minetest-mapserver/mapserver/releases/latest | jq --raw-output .tag_name)";
log_msg "Version is ${version}";
log_msg "Preparing docker build context";
cp ./Dockerfile "${temp_dir}/Dockerfile";
log_msg "Building docker image";
docker_image_name="${DOCKER_REGISTRY}minetest-mapserver:${arch}";
docker build "${temp_dir}" --tag "${docker_image_name}";
log_msg "Pushing to ${DOCKER_REGISTRY}";
docker push "${docker_image_name}";