Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- # Benutzer des Minecraft-Servers
- TARGET_USER=minecraft
- # Heimverzeichnis des Minecraft-Servers
- TARGET_DIR=/srv/minecraft
- # Dateiname mit Platzhalter für Download
- FILENAME_TEMPLATE=minecraft_server.%s.jar
- # Dateiname eines symbolischen Links, der auf die heruntergeladene Datei zeigt
- SYMLINK_NAME=server.jar
- # Manifest-Dokument, das Informationen über alle Minecraft-Versionen enthält
- MANIFEST_URL="https://launchermeta.mojang.com/mc/game/version_manifest.json"
- # Skript nimmt gewünschte Minecraft-Version als Parameter, ansonsten aktuelle stabile Version
- VERSION="${1:-latest}"
- target_group="$(id -gn "$TARGET_USER")"
- running_as="$(id -un)"
- manifest_versions="$(basename "$MANIFEST_URL")"
- manifest=manifest.json
- [ -d "$TARGET_DIR" ]
- working_dir="$(mktemp -d)"
- trap 'rm -rf "$working_dir"' EXIT
- cd "$working_dir"
- curl -so "$manifest_versions" "$MANIFEST_URL"
- if [ "$VERSION" = "latest" ]; then
- VERSION="$(jq -er '.latest.release' "$manifest_versions")"
- fi
- manifest_version_url="$(jq -er '.versions[] | select(.id=="'"$VERSION"'") | .url' "$manifest_versions")"
- curl -so "$manifest" "$manifest_version_url"
- download_sha1="$(jq -er '.downloads.server.sha1' "$manifest")"
- download_url="$(jq -er '.downloads.server.url' "$manifest")"
- target_filename="$(printf "$FILENAME_TEMPLATE" "$VERSION")"
- target_file="$TARGET_DIR/$target_filename"
- curl -o "$target_file" "$download_url"
- echo "$download_sha1 $target_filename" | (cd "$TARGET_DIR"; sha1sum -c)
- if [ "$running_as" != "$TARGET_USER" ]; then
- chown "$TARGET_USER:$target_group" "$target_file"
- fi
- if [ "$SYMLINK_NAME" ]; then
- ln -fs "$target_filename" "$TARGET_DIR/$SYMLINK_NAME"
- if [ "$running_as" != "$TARGET_USER" ]; then
- chown -h "$TARGET_USER:$target_group" "$TARGET_DIR/$SYMLINK_NAME"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement