#!/usr/bin/env bash # CONSTANTS readonly IMAGEDIR=${ROOTPATH}/image ## # checks if the defined image exists already # # $1 - string: software-name # $2 - string: mc-version # $3 - string: build-number ## function checkImage() { [[ -n $(podman image ls | grep "$2/$1" | grep "$3") ]] && echo true || echo false } ## # checks if the passed data is up-to-date # # $1 - string: software-name # $2 - string: mc-version # $3 - string: build-number # $4 - string: runner-type ## function checkUpdate() { case "$4" in "server") local remotebuild=$(curl -s "$(getValueByKey SERVERRUNNERS.$1)/versions/$2" | jq -r '.builds | last') ;; "proxy") local remotebuild=$(curl -s "$(getValueByKey PROXYRUNNERS.$1)/versions/$2" | jq -r '.builds | last') ;; esac if [[ "$3" == "$remotebuild" ]]; then echo false else echo true fi } ## # updates the config-file to the latest build # # $1 - string: software-name # $2 - string: mc-version # $3 - string: config-dir # $4 - string: runner-type ## function updateBuild() { case "$4" in "server") local latest=$(curl -s "$(getValueByKey SERVERRUNNERS.$1)/versions/$2" | jq -r '.builds | last') ;; "proxy") local latest=$(curl -s "$(getValueByKey PROXYRUNNERS.$1)/versions/$2" | jq -r '.builds | last') ;; esac log d "Updating build-no. to '$latest'" setLocalConfValue "$3" "(.build=$latest)" } ## # builds the podman image with the proper settings # # $1 - string: software-name # $2 - string: mc-version # $3 - string: build-number # $4 - string: download-url # ## function buildImage() { log d "lookup jar-name for download" local app_name=$(curl -s "$4" | jq -r '.downloads.application.name') log d "downloading server.jar" curl "$4/downloads/$app_name" -o "${BUILDDIR}/server.jar" log d "building docker image" podman build --rm "${BUILDDIR}" --tag "${2}/${1}:${3}" log d "removing server.jar, if present" [[ -f "${BUILDDIR}/server.jar" ]] && rm -f "${BUILDDIR}/server.jar" } ## # starts the specified container # # $1 - string: containername # $2 - string: image # $3 - int: port ## function startContainer() { log d "Starting container '$1'" podman run --name "$1" --userns=keep-id:uid=1000 --rm -it -d -p $3:25565 -v $(getValueByKey 'PODMAN_DIRECTORY')/$1/data:/var/server "$2" java -Dcom.mojang.eula.agree=true -jar /var/exec/server.jar --nogui --port 25565 } ## # stops the specified container # # $1 - string: containername ## function stopContainer() { log d "Stopping container '$1'" podman container stop --time 100 $1 }