add mc forge

This commit is contained in:
Murphy 2024-05-03 16:32:12 -04:00
parent 845b5c56b0
commit 871d16c849
Signed by: freya
GPG key ID: 744AB800E383AE52

77
mcjar
View file

@ -1,5 +1,4 @@
#!/bin/sh
set -e
lower() {
@ -21,6 +20,9 @@ PAPERMC_BUILD="$(lower "${PAPERMC_BUILD:-latest}")"
FABRIC_LOADER="$(lower "${FABRIC_LOADER:-latest}")"
FABRIC_INSTALLER="$(lower "${FABRIC_INSTALLER:-latest}")"
# forge
FORGE_VERSION="$(lower "${FORGE_VERSION:-recommended}")"
# other
QUIET=1
@ -28,7 +30,7 @@ req() {
res=$(curl --fail --silent "$1")
code=$?
if [ $code -ne 0 ]; then
if [ $code -ne 0 ] || [ "$res" = "" ]; then
echo "null";
else
echo "$res";
@ -184,8 +186,71 @@ vanilla() {
get_version
}
get_url() {
forge() {
versions=$(req "https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json" | jq -r '.promos');
log "Using forge promotions slim json"
get_forge_url() {
url="https://maven.minecraftforge.net/net/minecraftforge/forge/$1/forge-$1-installer.jar"
code=0
wget -q --spider "$url" || code=$?
if [ $code -eq 0 ]; then
echo "$url";
fi
}
get_version() {
log "Getting VERSION for '$MC_TYPE'"
if [ "$MC_VERSION" = "latest" ]; then
MC_VERSION=$(echo "$versions" | jq -r '. | keys | .[]' | awk -F '-' '{print $1}' | sort -t "." -n -k1,1 -k2,2 -k3,3 | tail -n1)
fi
log "VERSION: $MC_VERSION"
}
try_forge_version() {
ver=$(echo "$versions" | jq -r ".\"$MC_VERSION-$FORGE_VERSION\"")
if [ "$ver" = "null" ] && [ "$FORGE_VERSION" != "latest" ]; then
FORGE_VERSION=latest
try_forge_version
else
echo "$ver"
fi
}
get_forge_version() {
log "Getting FORGE VERSION for '$MC_TYPE'"
if [ "$FORGE_VERSION" != "latest" ] && [ "$FORGE_VERSION" != "recommended" ]; then
return;
fi
ver=$(try_forge_version)
if [ "$ver" = "null" ]; then
error "Invalid VERSION: $MC_VERSION-$FORGE_VERSION"
fi
FORGE_VERSION="$ver"
log "FORGE VERSION: $FORGE_VERSION"
}
search_for_url() {
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
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
log "Trying MC_VERSION-FORGE_VERSION-mc172"
ver=$(get_forge_url "$MC_VERSION-$FORGE_VERSION-mc172")
if [ "$ver" != "" ]; then echo "$ver"; return 0; fi
error "Invalid VERSION: $MC_VERSION-$FORGE_VERSION"
}
get_version
get_forge_version
search_for_url
}
get_url() {
log "TYPE: $MC_TYPE"
case "$MC_TYPE" in
@ -198,6 +263,9 @@ get_url() {
"fabric")
fabric
;;
"forge")
forge
;;
*)
error "Invalid TYPE: $MC_TYPE"
;;
@ -215,7 +283,7 @@ help() {
printf "\t-l\tshow logging (verbose)\n\n"
printf "\t-t TYPE\t\tset the mc server type\n"
printf "\t [vanilla,fabric,paper,folia,velocity,waterfall]\n\n"
printf "\t [vanilla,fabric,forge,paper,folia,velocity,waterfall]\n\n"
printf "\t-v VERSION\tset the mc server version\n"
printf "\t [latest,snapshot,<version>]\n\n"
@ -247,7 +315,6 @@ while getopts "hlt:v:" arg > /dev/null; do
;;
?)
error "unknown option"
exit 1
;;
esac;
done;