Pieds-Nus_custom-scripts/factorimods

49 lines
1.8 KiB
Bash

#!/bin/bash
# Dependencies : you'll need a dmenu-like to run this script.
# On debian and debian-like distros (ubuntu, mint...), simply run:
# sudo apt install dmenu
# Edit this line to meet your installation
factorio_dir="/DATA/Games/factorio"
# If you have installed new mods, this script will revert to previously saved
# mods before launching factorio. To update the modlist for a save, select the
# appropriate mods (via the GUI menu in factorio), then exit, call
# factorimods -r
# and select that save. This will replace the previously saved mods for that
# save with the active list from factorio.
cd $factorio_dir/saves
#Ask the user to select a save
save=$(ls -t *.zip | grep -v autosave | rev | cut -d "." -f 2- | rev | dmenu -i -l 5 -p "Chose a save file: ")
test $? -ne 0 && echo "No save selected" && exit 1
echo $save
if test "$1" = "-r" ; then
cp ../mods/mod-list.json mod-list.json_$save
modlist=$save
#Check if a modlist exists for that save
elif test -s "mod-list.json_$save" ; then
modlist=$save
else
#Otherwise, prompt to load another modlist
modlist=$(ls -t mod-list.json_* | cut -d "_" -f 2- | dmenu -p "No mod list found for savegame \"$save\". Select mod list from available: ")
test $? -ne 0 && echo "No modlist selected" && exit 1
#And prompt to save it for later
echo -e "yes\nno" | dmenu -p "Save selected modlist for savegame $save ?" | grep -q "yes" && cp mod-list.json_$modlist mod-list.json_$save && modlist=$save
fi
echo $modlist
#Link that modlist to the file read by factorio
ln -fs ../saves/mod-list.json_$modlist ../mods/mod-list.json
#Launch the game and the requested save
cd ..
echo "$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip"
$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip