SHARE
TWEET

minecraft-upgrade.sh

Snuggledash Jun 4th, 2020 3,684 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. set -e
  3.  
  4. # Benutzer des Minecraft-Servers
  5. TARGET_USER=minecraft
  6. # Heimverzeichnis des Minecraft-Servers
  7. TARGET_DIR=/srv/minecraft
  8. # Dateiname mit Platzhalter für Download
  9. FILENAME_TEMPLATE=minecraft_server.%s.jar
  10. # Dateiname eines symbolischen Links, der auf die heruntergeladene Datei zeigt
  11. SYMLINK_NAME=server.jar
  12. # Manifest-Dokument, das Informationen über alle Minecraft-Versionen enthält
  13. MANIFEST_URL="https://launchermeta.mojang.com/mc/game/version_manifest.json"
  14.  
  15. # Skript nimmt gewünschte Minecraft-Version als Parameter, ansonsten aktuelle stabile Version
  16. VERSION="${1:-latest}"
  17.  
  18. target_group="$(id -gn "$TARGET_USER")"
  19. running_as="$(id -un)"
  20. manifest_versions="$(basename "$MANIFEST_URL")"
  21. manifest=manifest.json
  22.  
  23. [ -d "$TARGET_DIR" ]
  24. working_dir="$(mktemp -d)"
  25. trap 'rm -rf "$working_dir"' EXIT
  26. cd "$working_dir"
  27.  
  28. curl -so "$manifest_versions" "$MANIFEST_URL"
  29. if [ "$VERSION" = "latest" ]; then
  30.         VERSION="$(jq -er '.latest.release' "$manifest_versions")"
  31. fi
  32. manifest_version_url="$(jq -er '.versions[] | select(.id=="'"$VERSION"'") | .url' "$manifest_versions")"
  33. curl -so "$manifest" "$manifest_version_url"
  34. download_sha1="$(jq -er '.downloads.server.sha1' "$manifest")"
  35. download_url="$(jq -er '.downloads.server.url' "$manifest")"
  36.  
  37. target_filename="$(printf "$FILENAME_TEMPLATE" "$VERSION")"
  38. target_file="$TARGET_DIR/$target_filename"
  39. curl -o "$target_file" "$download_url"
  40. echo "$download_sha1  $target_filename" | (cd "$TARGET_DIR"; sha1sum -c)
  41. if [ "$running_as" != "$TARGET_USER" ]; then
  42.         chown "$TARGET_USER:$target_group" "$target_file"
  43. fi
  44.  
  45. if [ "$SYMLINK_NAME" ]; then
  46.         ln -fs "$target_filename" "$TARGET_DIR/$SYMLINK_NAME"
  47.         if [ "$running_as" != "$TARGET_USER" ]; then
  48.                 chown -h "$TARGET_USER:$target_group" "$TARGET_DIR/$SYMLINK_NAME"
  49.         fi
  50. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top