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.

87 lines
1.9 KiB

  1. # -*- mode: shell-script -*-
  2. MINECRAFT_PATH="$SERVICE_CONFIGSTORE/opt/apps/minecraft"
  3. MINECRAFT_DATA="/var/lib/minecraft"
  4. minecraft:init-binary() {
  5. local version="$1"
  6. MINECRAFT_BINARY="${MINECRAFT_PATH}/minecraft_server.${version}.jar"
  7. if ! [ -f "$MINECRAFT_BINARY" ]; then
  8. mkdir -p "${MINECRAFT_PATH}"
  9. wget "https://docker.0k.io/downloads/minecraft_server.${version}.jar" \
  10. -O "$MINECRAFT_BINARY"
  11. fi
  12. init-config-add "
  13. $SERVICE_NAME:
  14. volumes:
  15. - \"${MINECRAFT_BINARY}:${MINECRAFT_DATA}/server.jar\"
  16. "
  17. }
  18. minecraft:init-command() {
  19. local threads="${1:-4}" mem="${2:-2048M}"
  20. init-config-add "
  21. $SERVICE_NAME:
  22. command:
  23. - java
  24. - -Xmx${mem}
  25. - -Xms${mem}
  26. - -XX:ParallelGCThreads=${threads}
  27. - -jar
  28. - server.jar
  29. - nogui
  30. "
  31. echo "eula=TRUE" > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/eula.txt"
  32. }
  33. minecraft:make-whitelist() {
  34. local whitelist="$1"
  35. {
  36. e "$whitelist" |
  37. yq -o=json \
  38. 'to_entries | map({"uuid": .key, "name": .value})'
  39. } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/whitelist.json"
  40. }
  41. minecraft:make-ops() {
  42. local ops="$1"
  43. {
  44. e "$ops" |
  45. yq -o=json \
  46. 'to_entries | map({
  47. "uuid": .value.uuid,
  48. "name": .key,
  49. "level": .value.level,
  50. "bypassesPlayerLimit": .value.bypassesPlayerLimit
  51. })'
  52. } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/ops.json"
  53. }
  54. minecraft:make-properties() {
  55. local properties="$1"
  56. {
  57. e "$properties" |
  58. yq 'to_entries | map(.key + "=" + .value) | .[]'
  59. } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/server.properties"
  60. }
  61. minecraft:config-hash() {
  62. local opts="$1"
  63. debug "Adding config hash to enable recreating upon config change."
  64. config_hash=$(e "$opts" | md5_compat) || exit 1
  65. init-config-add "
  66. $SERVICE_NAME:
  67. labels:
  68. - compose.config_hash=$config_hash
  69. "
  70. }