Last active
June 4, 2020 21:52
-
-
Save iainconnor/40553794504c2a29e8686d7adadc7773 to your computer and use it in GitHub Desktop.
Rom Merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ROMS="./roms-old" | |
UPGRADES="./upgrades" | |
NEW="./roms-new" | |
for ROM_FILE in $ROMS/*.zip $ROMS/*.7z; do | |
[ -f "$ROM_FILE" ] || break | |
ROM_FILE_NAME=$(basename "$ROM_FILE") | |
ROM_FILE_NAME_WITHOUT_EXTENSION="${ROM_FILE_NAME%.*}" | |
ROM_FILE_EXTENSION="${ROM_FILE_NAME##*.}" | |
UPGRADE_FILE="$UPGRADES/$ROM_FILE_NAME" | |
if test -f "$UPGRADE_FILE"; then | |
if [ ! -d "$NEW" ]; then | |
mkdir -p "$NEW" | |
fi | |
UPGRADE_FILE_NAME=$(basename "$UPGRADE_FILE") | |
UPGRADE_FILE_NAME_WITHOUT_EXTENSION="${UPGRADE_FILE_NAME%.*}" | |
UPGRADE_FILE_EXTENSION="${UPGRADE_FILE_NAME##*.}" | |
echo "Upgrading $ROM_FILE_NAME..." | |
echo "... copying..." | |
cp "$ROM_FILE" "$NEW/$ROM_FILE_NAME" | |
echo "... extracting upgrade..." | |
7z e "$UPGRADE_FILE" -o"$UPGRADES/$ROM_FILE_NAME_WITHOUT_EXTENSION" -y > /dev/null 2>&1 | |
echo "... cleaning extract..." | |
find "$UPGRADES/$ROM_FILE_NAME_WITHOUT_EXTENSION" -type d -empty -delete | |
echo "... adding files..." | |
7z a "$NEW/$ROM_FILE_NAME" "$UPGRADES/$ROM_FILE_NAME_WITHOUT_EXTENSION/*" > /dev/null 2>&1 | |
echo "... cleaning up..." | |
rm -rf "$UPGRADES/$ROM_FILE_NAME_WITHOUT_EXTENSION" | |
echo "... complete." | |
echo "" | |
fi | |
done | |
echo "All done, updated roms can be found at `$NEW` 🍺" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment