Skip to content

Instantly share code, notes, and snippets.

@RoboMWM
Last active July 15, 2021 23:08
Show Gist options
  • Save RoboMWM/22c2a00b26e48847254e7f2be807e06d to your computer and use it in GitHub Desktop.
Save RoboMWM/22c2a00b26e48847254e7f2be807e06d to your computer and use it in GitHub Desktop.
from ZombieChickenMan and billy
#!/bin/bash
# A place to store build information
DIR=~/.purpur/
FILE=$DIR"build"
# Get the latest version from pl3x api
echo "Checking for latest version ..."
VERSION=`curl -sN 'https://api.pl3x.net/v2/purpur/' | jq -r '.versions[0]'`
echo "Latest version is $VERSION"
# Get the latest build for that version from pl3x api
echo "Checking for latest build ..."
BUILD=`curl -sN "https://api.pl3x.net/v2/purpur/$VERSION/" | jq -r '.builds.latest'`
echo "Latest build is $BUILD"
# Check stored build information
echo "Checking previous build ..."
# Create the dir/file where we store build info if it doesnt exist
if [ ! -f $FILE ]; then
mkdir -p $DIR
touch $FILE
fi
# Get the stored build information
PREVIOUS=`cat $FILE`
DOWNLOAD=true
# Check if their was a previous build stored
if [ -z "$PREVIOUS" ]; then
echo "No previous builds detected"
else
echo "Previous build is $PREVIOUS"
# Compare previous build to current build
if [ $BUILD == $PREVIOUS ]; then
# They are the same build, do not download
DOWNLOAD=false
echo "Not downloading the same build again"
fi
fi
# Download the latest build now
if $DOWNLOAD; then
echo "Downloading build $BUILD $DOWNLOAD"
# Store the current build information
echo $BUILD > $FILE
# Use wget with -O to specify our own filename
wget https://api.pl3x.net/v2/purpur/$VERSION/$BUILD/download/ -O puprur.jar
fi
export VER="$(curl https://papermc.io/api/v2/projects/paper | jq -r '.versions[-1]')"
export LATEST_BUILD="$(curl -s https://papermc.io/api/v2/projects/paper/versions/$VER | jq -r '.builds[-1]')"
if [ "$LATEST_BUILD" != "$(cat last_update)" ]
then
export LATEST_NAME="$(curl https://papermc.io/api/v2/projects/paper/versions/$VER/builds/$LATEST_BUILD | jq -r .downloads.applications.name")
curl "https://papermc.io/api/v2/projects/paper/versions/$VER/builds/$LATEST_BUILD/downloads/$LATEST_NAME" -o paperclip.jar
echo "$LATEST_BUILD" > last_update
fi
export VER="$(curl -s https://api.pl3x.net/v2/purpur/ | jq -r '.versions[0]')"
export LATEST_BUILD="$(curl -s https://api.pl3x.net/v2/purpur/versions/$VER | jq -r '.builds[-1]')"
if [ "$LATEST_BUILD" != "$(cat last_update)" ]
then
curl https://api.pl3x.net/v2/purpur/1.17.1/latest/download -o purpurclip.jar
echo "$LATEST_BUILD" > last_update
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment