Skip to content

Instantly share code, notes, and snippets.

@t0mtee
Last active December 9, 2023 20:28
Show Gist options
  • Save t0mtee/afbe91d62ffaf20a34c1bcbf9e8c0208 to your computer and use it in GitHub Desktop.
Save t0mtee/afbe91d62ffaf20a34c1bcbf9e8c0208 to your computer and use it in GitHub Desktop.
Lenny's Mod Loader Linux Script. Put it in your lml folder. (written by ChatGPT)
#!/bin/bash
# Erase lines between <Mods> and </Mods> excluding the tags
sed -i '/<Mods>/,/<\/Mods>/ { /<Mods>/b; /<\/Mods>/b; d; }' mods.xml
# Erase lines between <LoadOrder> and </LoadOrder> excluding the tags
sed -i '/<LoadOrder>/,/<\/LoadOrder>/ { /<LoadOrder>/b; /<\/LoadOrder>/b; d; }' mods.xml
# Find all install.xml files in subfolders, sort them alphabetically based on parent directory's name, and process each one
find . -name 'install.xml' | sort -t/ -k2,2 -r | while read -r install_xml; do
# Get the directory of the install.xml file
LOCATION=$(dirname "$install_xml")
# Trim to cut out all folders above the script
LOCATION=$(realpath --relative-to=. "$LOCATION")
# Get the value between <name> and </name>
NAME=$(grep -oP '(?<=<Name>).*?(?=</Name>)' "$install_xml")
# Add to mods.xml at line 4
sed -i "4i\\
<Mod folder=\"$LOCATION\">\n <Name>$NAME</Name>\n <Enabled>true</Enabled>\n <Overwrite>false</Overwrite>\n <DisabledGroups />\n </Mod>" mods.xml
# Add under the line containing <LoadOrder>
sed -i "/<LoadOrder>/a\ <Mod>$LOCATION</Mod>" mods.xml
done
rm patterns.dat
<?xml version="1.0" encoding="utf-8"?>
<ModsManager>
<Mods>
</Mods>
<LoadOrder>
</LoadOrder>
</ModsManager>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment