Skip to content

Instantly share code, notes, and snippets.

@Xalcon
Last active May 22, 2017 14:51
Show Gist options
  • Save Xalcon/7df9c62513a7b6669217568913ddb175 to your computer and use it in GitHub Desktop.
Save Xalcon/7df9c62513a7b6669217568913ddb175 to your computer and use it in GitHub Desktop.
Copies all mods from the mods folder into a maven style directory structure and creates a mods.txt containing the maven coordinates. This can be used to create a ModList file (https://github.com/MinecraftForge/FML/wiki/New-JSON-Modlist-format). This script requires jq to work (https://stedolan.github.io/jq/)
#!/bin/bash
modsDir=mods/*.jar
repoDir=repo/mods
for file in $modsDir
do
mcmodInfo=`unzip -p "$file" mcmod.info 2> /dev/null`
if [[ $? -ne 0 ]]; then
echo "$file has no mcmeta.info"
continue;
fi
modid=`echo "$mcmodInfo" | tr "\r" " " | tr "\n" " " | jq --raw-output 'if type=="array" then .[0].modid else .modList[0].modid end'`
version=`echo "$mcmodInfo" | tr "\r" " " | tr "\n" " " | jq --raw-output 'if type=="array" then .[0].version else .modList[0].version end'`
if [[ $? -ne 0 ]]; then
echo "Unable to parse mcmeta of $file"
echo "$mcmodInfo" > "$file.json"
continue;
fi
target="$repoDir/${modid,,}/$version/${modid,,}-$version.jar"
mkdir -p `dirname $target` 2> /dev/null
cp "$file" "$target"
echo "mods:$modid:$version" >> mods.txt
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment