This commit is contained in:
Murphy 2024-05-03 23:04:39 -04:00
parent 871d16c849
commit 81da522059
Signed by: freya
GPG key ID: 744AB800E383AE52

72
mcjar
View file

@ -26,6 +26,9 @@ FORGE_VERSION="$(lower "${FORGE_VERSION:-recommended}")"
# other
QUIET=1
# all output
ALL=0
req() {
res=$(curl --fail --silent "$1")
code=$?
@ -96,7 +99,18 @@ papermc() {
get_version
get_build
echo "$api/$MC_TYPE/versions/$MC_VERSION/builds/$PAPERMC_BUILD/downloads/$MC_TYPE-$MC_VERSION-$PAPERMC_BUILD.jar"
name="$MC_TYPE-$MC_VERSION-$PAPERMC_BUILD.jar"
url="$api/$MC_TYPE/versions/$MC_VERSION/builds/$PAPERMC_BUILD/downloads/$name"
if [ $ALL -eq 1 ]; then
echo "JAR_NAME=$name"
echo "JAR_URL=$url"
echo "MC_TYPE=$MC_TYPE"
echo "MC_VERSION=$MC_VERSION"
echo "PAPERMC_BUILD=$PAPERMC_BUILD"
else
echo "$url"
fi
}
fabric() {
@ -141,7 +155,18 @@ fabric() {
get_loader
get_installer
echo "$api/loader/$MC_VERSION/$FABRIC_LOADER/$FABRIC_INSTALLER/server/jar"
url="$api/loader/$MC_VERSION/$FABRIC_LOADER/$FABRIC_INSTALLER/server/jar"
if [ $ALL -eq 1 ]; then
echo "JAR_NAME=fabric-$MC_VERSION-$FABRIC_LOADER-$FABRIC_INSTALLER.jar"
echo "JAR_URL=$url"
echo "MC_TYPE=$MC_TYPE"
echo "MC_VERSION=$MC_VERSION"
echo "FABRIC_LOADER=$FABRIC_LOADER"
echo "FABRIC_INSTALLER=$FABRIC_INSTALLER"
else
echo "$url"
fi
}
vanilla() {
@ -152,6 +177,8 @@ vanilla() {
echo "$versions" | jq -r "map(select(.type == \"$type\"))"
}
url=""
get_version() {
log "Getting VERSION for '$MC_TYPE'"
version=""
@ -171,7 +198,8 @@ vanilla() {
error "Invalid VERSION: $MC_VERSION"
fi
log "VERSION: $(echo "$version" | jq -r '.id')"
MC_VERSION=$(echo "$version" | jq -r '.id')
log "VERSION: $MC_VERSION"
json=$(echo "$version" | jq -r '.url')
url=$(req "$json" | jq -r '.downloads.server.url')
@ -179,11 +207,19 @@ vanilla() {
if [ "$url" = "null" ]; then
error "Cannot get server jar for VERSION: $MC_VERSION"
fi
echo "$url"
}
get_version
if [ $ALL -eq 1 ]; then
echo "JAR_NAME=minecraft-$MC_VERSION.jar"
echo "JAR_URL=$url"
echo "MC_TYPE=$MC_TYPE"
echo "MC_VERSION=$MC_VERSION"
else
echo "$url"
fi
}
forge() {
@ -191,6 +227,8 @@ forge() {
log "Using forge promotions slim json"
url=""
get_forge_url() {
url="https://maven.minecraftforge.net/net/minecraftforge/forge/$1/forge-$1-installer.jar"
code=0
@ -235,19 +273,29 @@ forge() {
log "Searching for forge URL"
log "Trying MC_VERSION-FORGE_VERSION"
ver=$(get_forge_url "$MC_VERSION-$FORGE_VERSION")
if [ "$ver" != "" ]; then echo "$ver"; return 0; fi
if [ "$ver" != "" ]; then url="$ver"; return 0; fi
log "Trying MC_VERSION-FORGE_VERSION-MC_VERSION"
ver=$(get_forge_url "$MC_VERSION-$FORGE_VERSION-$MC_VERSION")
if [ "$ver" != "" ]; then echo "$ver"; return 0; fi
if [ "$ver" != "" ]; then url="$ver"; return 0; fi
log "Trying MC_VERSION-FORGE_VERSION-mc172"
ver=$(get_forge_url "$MC_VERSION-$FORGE_VERSION-mc172")
if [ "$ver" != "" ]; then echo "$ver"; return 0; fi
if [ "$ver" != "" ]; then url="$ver"; return 0; fi
error "Invalid VERSION: $MC_VERSION-$FORGE_VERSION"
}
get_version
get_forge_version
search_for_url
if [ $ALL -eq 1 ]; then
echo "JAR_NAME=forge-$MC_VERSION-$FORGE_VERSION-installer.jar"
echo "JAR_URL=$url"
echo "MC_TYPE=$MC_TYPE"
echo "MC_VERSION=$MC_VERSION"
echo "FORGE_VERSION=$FORGE_VERSION"
else
echo "$url"
fi
}
get_url() {
@ -281,6 +329,7 @@ help() {
printf "options:\n"
printf "\t-h\tshow this message\n"
printf "\t-l\tshow logging (verbose)\n\n"
printf "\t-a\toutput all variables\n\n"
printf "\t-t TYPE\t\tset the mc server type\n"
printf "\t [vanilla,fabric,forge,paper,folia,velocity,waterfall]\n\n"
@ -295,10 +344,12 @@ help() {
printf "\tFABRIC_LOADER\t\tsets the fabric loder version\n"
printf "\tFABRIC_INSTALLER\tsets the fabric installer version\n\n"
printf "\tFORGE_VERSION\tsets the forge loader version\n\n"
}
while getopts "hlt:v:" arg > /dev/null; do
while getopts "hlat:v:" arg > /dev/null; do
case $arg in
h)
help
@ -307,6 +358,9 @@ while getopts "hlt:v:" arg > /dev/null; do
l)
QUIET=0
;;
a)
ALL=1
;;
t)
MC_TYPE=${OPTARG}
;;