Last active
August 12, 2021 00:07
-
-
Save Konicai/eca2e56b9af20fe61f9a3b8e04f054d4 to your computer and use it in GitHub Desktop.
An informative bash script to update Geyser Standalone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # April 2021 - Updates Geyser Standalone. | |
| # Dependencies: unzip, and curl or wget. | |
| # Run geyser after the update check (true). | |
| runGeyser='true' | |
| # Prompt to update (false). | |
| updatePrompt='false' | |
| # If you've renamed Geyser.jar to something else, you must update this value. | |
| localJar='Geyser.jar' | |
| geyser_start () { | |
| echo "Starting Geyser Standalone" | |
| java -Xmx1024M -jar "$localJar" nogui | |
| } | |
| # Make sure a download command exists | |
| if [[ -x "$(command -v curl)" ]]; then | |
| downloadCmd='curl' | |
| else | |
| if [[ -x "$(command -v wget)" ]]; then | |
| downloadCmd='wget' | |
| else | |
| echo "Error: Failed to find a download command! Install wget or curl."; exit 1 | |
| fi | |
| fi | |
| download_geyser () { | |
| jarURL="https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/$1/lastSuccessfulBuild/artifact/bootstrap/standalone/target/Geyser.jar" | |
| if [[ "$downloadCmd" == "curl" ]]; then | |
| curl "$jarURL" -o $localJar | |
| else | |
| wget -O "$localJar" "$jarURL" | |
| fi | |
| } | |
| # Make sure Geyser.jar exists, prompt download if not. | |
| if ! [[ -f "$localJar" ]]; then | |
| echo "Error: $localJar does not exist or is not named properly! Do you want to download the latest Geyser Standalone?" | |
| PS3="Enter a number: " | |
| select installType in "Install master branch" "No install"; do | |
| case $installType in | |
| "Install master branch" ) echo "master branch selected"; download_geyser "master"; break;; | |
| "No install" ) echo "No install selected"; exit 2;; | |
| esac | |
| done | |
| if [[ "$runGeyser" == "true" ]]; then | |
| geyser_start | |
| fi | |
| exit 0 | |
| fi | |
| # Make sure the unzip command exists | |
| if ! [[ -x "$(command -v unzip)" ]]; then | |
| echo "Error: unzip command does not exist! Install unzip."; exit 1 | |
| fi | |
| # Get the local build number and git branch | |
| localBuild=$(unzip -p "$localJar" git.properties | grep "git.build.number" | cut -c 18-) | |
| localBranch=$(unzip -p "$localJar" git.properties | grep "git.branch" | cut -c 12-) | |
| # Get latest build number for the respective branch | |
| buildNumberURL="https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/$localBranch/lastSuccessfulBuild/buildNumber" | |
| if [[ "$downloadCmd" == "curl" ]]; then | |
| serverBuild=$(curl -s "$buildNumberURL") | |
| else | |
| serverBuild=$(wget -q -O - "$buildNumberURL") | |
| fi | |
| if ! [[ $serverBuild =~ ^[0-9]+$ ]]; then | |
| echo "Error: Failed to fetch latest build number from the geyser build server!"; exit 1 | |
| fi | |
| if [[ "$localBuild" -eq "$serverBuild" ]]; then | |
| echo "Geyser Standalone ($localBranch) is on the latest build: $localBuild" | |
| if [[ "$runGeyser" == "true" ]]; then | |
| geyser_start | |
| fi | |
| exit 0 | |
| else | |
| echo "Geyser Standalone ($localBranch) is on build $localBuild. The latest is build $serverBuild." | |
| fi | |
| if [[ "$updatePrompt" == "true" ]]; then | |
| echo "Do you want to update" | |
| PS3="Enter a number: " | |
| select yn in "Yes" "No"; do | |
| case $yn in | |
| "Yes" ) doUpdate='true'; break;; | |
| "No" ) doUpdate='false'; break;; | |
| esac | |
| done | |
| else | |
| doUpdate='true' | |
| fi | |
| if [[ "$doUpdate" == "true" ]]; then | |
| echo "Downloading build $serverBuild." | |
| mv $localJar $localJar.old | |
| download_geyser "$localBranch" | |
| echo "Geyser Standalone ($localBranch) has been updated to build $serverBuild." | |
| fi | |
| if [[ "$runGeyser" == "true" ]]; then | |
| geyser_start | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice