Skip to content

Instantly share code, notes, and snippets.

@not-ivy
Last active July 2, 2022 20:02
Show Gist options
  • Save not-ivy/6d8a9099adf3963dc166ef73e6a9a0bf to your computer and use it in GitHub Desktop.
Save not-ivy/6d8a9099adf3963dc166ef73e6a9a0bf to your computer and use it in GitHub Desktop.
mod updater rewrite in bash
# example config
MINECRAFT_VERSION="1.18.1"
FABRIC_MODS=(
# add the mod id / slug from modrinth here
)
FORGE_MODS=(
# add the mod id / slug from modrinth here
)
QUILT_MODS=(
# add the mod id / slug from modrinth here
)

How to use

pretty easy to use actually

just copy the .env file, customize the file for your mods, and just run the script file.

the string you put in the array must be the id of the mod on modrinth

Example

if you want to add fabric api to the list of mods to download, just find fabric api on modrinth, and copy the link

https://modrinth.com/mod/fabric-api
            you need this^^^^^^^^^^

and add it to the FABRIC_MODS array

FABRIC_MODS=(
+  "fabric-api"
)

License

Copyright (c) 2022 i-spin

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#!/usr/bin/env bash
if [[ -f '.env' ]]; then
# shellcheck source=/dev/null
source .env
else
echo ".env file not found!"
exit 1
fi
# update(modid, loader, version)
update () {
echo "Trying to download mod $1."
mod_json=$(curl -s "https://api.modrinth.com/api/v1/mod/$1")
if [ -z "$mod_json" ]; then
echo "Modrinth API returned nothing for mod $1, skipping."
fi
mapfile -t versions < <(echo "$mod_json" | jq '.versions | .[]' | tr -d '"')
for version in "${versions[@]}"; do
version_json=$(curl -s "https://api.modrinth.com/api/v1/version/${version}")
mapfile -t loaders < <(echo "$version_json" | jq '.loaders' | tr -d '"')
if [[ ! "${loaders[*]}" =~ $2 ]]; then
echo "Version $version for mod $1 does not support $2 loader, fetching next version."
continue
fi
mapfile -t game_versions < <(echo "$version_json" | jq '.game_versions' | tr -d '"')
if [[ "${game_versions[*]}" =~ $3 ]]; then
curl -sfLO "$(echo "$version_json" | jq '.files | .[0] | .url' | tr -d '"')"
echo "Downloaded mod $1, version $(echo "$version_json" | jq '.version_number' | tr -d '"')."
printf %"$COLUMNS"s |tr " " "-"
break
else
echo "Version $version for mod $1 did not contain version $3, fetching next version."
continue
fi
echo "Cannot find version $3 for mod $1 on $2 loader."
printf %"$COLUMNS"s |tr " " "-"
unset version_json
unset game_versions
done
unset mod_json
unset versions
}
for modid in "${FABRIC_MODS[@]}"; do
update "$modid" "fabric" "$MINECRAFT_VERSION"
done
unset modid
for modid in "${FORGE_MODS[@]}"; do
update "$modid" "forge" "$MINECRAFT_VERSION"
done
unset modid
for modid in "${QUILT_MODS[@]}"; do
update "$modid" "quilt" "$MINECRAFT_VERSION"
done
unset modid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment