You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

99 lines
2.4 KiB

# -*- mode: shell-script -*-
MINECRAFT_PATH="$SERVICE_CONFIGSTORE/opt/apps/minecraft"
MINECRAFT_DATA="/var/lib/minecraft"
minecraft:init-binary() {
local type="$1" version="$2"
case "$type" in
"legacy")
MINECRAFT_URL="https://docker.0k.io/downloads/minecraft_server.${version}.jar"
MINECRAFT_BINARY="minecraft_server.${version}.jar"
;;
"paper")
MINECRAFT_URL="https://api.papermc.io/v2/projects/paper/versions/${version%-*}/builds/${version##*-}/downloads/paper-${version}.jar"
MINECRAFT_BINARY="paper.${version}.jar"
;;
*)
err "Unknown ${WHITE}type${NORMAL} '$type'. Please use on of: legacy, paper"
exit 1
;;
esac
if ! [ -f "$MINECRAFT_BINARY" ]; then
mkdir -p "${MINECRAFT_PATH}"
wget "$MINECRAFT_URL" -O "$MINECRAFT_PATH/$MINECRAFT_BINARY" || exit 1
fi
init-config-add "
$SERVICE_NAME:
volumes:
- \"$MINECRAFT_PATH/${MINECRAFT_BINARY}:${MINECRAFT_DATA}/server.jar\"
"
}
minecraft:init-command() {
local threads="${1:-4}" mem="${2:-2048M}"
init-config-add "
$SERVICE_NAME:
command:
- java
- -Xmx${mem}
- -Xms${mem}
- -XX:ParallelGCThreads=${threads}
- -jar
- server.jar
- nogui
"
echo "eula=TRUE" > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/eula.txt"
}
minecraft:make-whitelist() {
local whitelist="$1"
{
e "$whitelist" |
yq -o=json \
'to_entries | map({"uuid": .key, "name": .value})'
} > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/whitelist.json"
}
minecraft:make-ops() {
local ops="$1"
{
e "$ops" |
yq -o=json \
'to_entries | map({
"uuid": .value.uuid,
"name": .key,
"level": .value.level,
"bypassesPlayerLimit": .value.bypassesPlayerLimit
})'
} > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/ops.json"
}
minecraft:make-properties() {
local properties="$1"
{
e "$properties" |
yq 'to_entries | map(.key + "=" + .value) | .[]'
} > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/server.properties"
}
minecraft:config-hash() {
local opts="$1"
debug "Adding config hash to enable recreating upon config change."
config_hash=$(e "$opts" | md5_compat) || exit 1
init-config-add "
$SERVICE_NAME:
labels:
- compose.config_hash=$config_hash
"
}