#!/usr/bin/bash # # mame_create_index_files.sh # EmulationStation MAME index files creation. # # As input, this script takes the MAME driver information XML file from the official # MAME release and generates the files mamebioses.xml, mamedevices.xml and mamenames.xml. # # There is not much error checking going on here, this script is not intended to be # used by the end user. # # xmlstarlet must be installed or this script will fail. # # Download the driver file from here: # https://www.mamedev.org/release.php # It's enough to download the driver information, not the complete emulator. # # This script is intended to only be used on Linux systems. # # Leon Styhre # 2020-06-16 # if [ $# -ne 1 ]; then echo "Usage: ./mame_create_index_files.sh " echo "For example:" echo "./mame_create_index_files.sh mame0221.xml" exit fi if [ ! -f $1 ]; then echo "Can't find MAME driver file" $1 exit fi MAME_XML_FILE=$1 MAMEBIOSFILE=mamebioses.xml MAMEDEVICEFILE=mamedevices.xml MAMENAMEFILE=mamenames.xml echo "" > $MAMEBIOSFILE for bios in $(xmlstarlet sel -t -m "/mame/machine[@isbios=\"yes\"]" -v "@name" \ -n $MAME_XML_FILE); do echo ""${bios}"" >> $MAMEBIOSFILE done echo "" > $MAMEDEVICEFILE for device in $(xmlstarlet sel -t -m "/mame/machine[@isdevice=\"yes\"][rom]" \ -v "@name" -n $MAME_XML_FILE); do echo ""${device}"" >> $MAMEDEVICEFILE done echo "" > $MAMENAMEFILE xmlstarlet sel -t -m "/mame/machine[not(@isbios=\"yes\")][not(@isdevice=\"yes\")][rom]" \ -v "@name" -o " " -v description -n $MAME_XML_FILE | \ awk '{ print "" $1 ""; print $1=""; print "" $0 ""}' | \ sed s/"realname> "/"realname>"/g | sed '/^[[:space:]]*$/d' | \ sed s/"\n\t"/"<\/realname>\n<\/game>"/g >> $MAMENAMEFILE