Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script doesnt auto-detect and install the new server and .jar file version. #108

Open
PGQT opened this issue Sep 2, 2024 · 0 comments
Open

Comments

@PGQT
Copy link

PGQT commented Sep 2, 2024

I have noticed that it sometimes takes a while for you to get back to the script to update it for the new server jar file download, and i wanted to contribute in a small way to help with that. here is a script you are welcome to pull from to auto detect (i think it should work for all future versions) and download the minecraft_server.jar file from the mincraft webiste. I just want to help however I can, so let me know how I can do so.

#!/bin/bash

# Move to user's minecraft installation directory
cd ~/minecraft

# Fetch the webpage content with a user-agent string
page_content=$(curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" https://www.minecraft.net/en-us/download/server)

# Extract the download link (searching for the specific structure in the <a> tag)
download_link=$(echo "$page_content" | grep -oP '(?<=href=")https://piston-data\.mojang\.com/v1/objects/[a-f0-9]+/server\.jar')

# Extract the version number from the page content (only the first match)
version=$(echo "$page_content" | grep -oP 'minecraft_server\.\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)

# Print the version number and download the .jar file to a directory named after the version number
if [ -n "$download_link" ] && [ -n "$version" ]; then
    echo "Minecraft Server Version: $version"
    
    # Create a directory named after the version number
    mkdir -p "$version"
    
    # Download the .jar file into the directory
    wget -O "$version/minecraft.jar" "$download_link"

   #success or failure messages
    echo "Downloaded minecraft.jar to $(pwd)/$version/"
else
    echo "Download link or version number not found"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant