Created
September 23, 2023 19:50
-
-
Save WizardlyBump17/8e6598564d1c6e1f75df6d7a39389581 to your computer and use it in GitHub Desktop.
Utility script to easily run the BuildTools provided by Spigot
This file contains 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 | |
# checks if this script was executed correctly | |
if (( $# == 0 )); then | |
echo -e "Usage: $0 <version> [Java path]" | |
exit 2 | |
fi | |
digit_regex="^[0-9]+$" | |
version=$1 | |
IFS="." | |
read -ra version_numbers <<< "$version" | |
version_length=${#version_numbers[@]} | |
# checks if the version is right | |
echo -e "Checking the version..." | |
if (( $version_length < 2 )) || (( $version_length > 3 )); then | |
echo -e "Invalid version. It must be in the MAJOR.MINOR or MAJOR.MINOR.PATCH format" | |
exit 2 | |
fi | |
for i in ${version_numbers[@]}; do | |
if [[ "$i" =~ $digit_regex ]]; then | |
continue | |
fi | |
echo -e "The version numbers must be a number!" | |
exit 2 | |
done | |
echo -e "Chosen version: $version\n\n\n" | |
# initializes some variables | |
root_dir="${version_numbers[0]}.${version_numbers[1]}" | |
dir="$version" | |
full_dir="$root_dir/$dir" | |
# create the necessary directories | |
echo -e "Creating directories..." | |
if ! [ -d "$root_dir" ]; then | |
mkdir "$root_dir" | |
fi | |
cd "$root_dir" | |
if [ -d "$dir" ]; then | |
echo -e "Deleting the $full_dir directory because it already exists..." | |
rm -rf "$dir" | |
fi | |
mkdir "$dir" && cd "$dir" | |
echo -e "Created all directories!\n\n\n" | |
# downloads the BuildTools | |
echo -e "Downloading BuildTools..." | |
curl -O https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar | |
echo -e "BuildTools downloaded!\n\n\n" | |
# executes the BuildTools | |
echo -e "Executing BuildTools..." | |
java_path="java" | |
if (( $# < 2 )); then | |
echo -e "The Java path was not provided. Using 'java' as default..." | |
else | |
java_path=$2 | |
fi | |
$java_path -jar BuildTools.jar --rev "$version" | |
echo -e "\n\n\nBuildTools executed!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment