Advertisement
Guest User

getextras_single.sh

a guest
Aug 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Argument to script should be a filename with a list of mame romnames without file ending.
  4. # It takes a base directory with MAME EXTRAs files and searches in pre defined comma separated
  5. # directories like flyers,snap for .png files. These .png files must match the list of romnames
  6. # found in the file from argument. The list of romnames in file must be new line separated without
  7. # file extension. It only copies the first found image and leaves out the rest.
  8.  
  9. # Argument 1 is a file with romnames without file ending separated by new line. In example:
  10. # bosco
  11. # bjourney
  12. # lizwiz
  13. filename="$1"
  14.  
  15. # This is the base directory to look for files to copy. It is assumened that this directory have
  16. # subfolders with those images. Usually it is the mame base folder, where all these EXTRAs subfolders
  17. # are found.
  18. basedir="/media/tuncay/K/roms/Pleasuredome/mame/MAME 0.155 EXTRAs"
  19.  
  20. # List of directories to use found in base directory. The list should be comma separated.
  21. includedir="flyers,marquees,snap"
  22.  
  23. # Error messages sent to this file. Contains only an entry for each romname, if nothing is found.
  24. logfile="log_single.txt"
  25.  
  26. # Remove previous logfile.
  27. rm "$logfile"
  28.  
  29. # Create folder to copy files to.
  30. mkdir -p "extras"
  31.  
  32. # counter is just temporary number for the print for each romname.
  33. counter=0
  34. # Use the file from argument as the input. Each line represents a romname.
  35. for line in $(cat "$filename")
  36. do
  37.     # Proceed only if the line is not empty.
  38.     if [ -z "$line" ];
  39.     then
  40.         continue
  41.     else
  42.         # Print the actual romname in line of file and corresponding number.
  43.         counter=$[$counter+1]
  44.         romname="$line"
  45.         echo "$counter - $romname"
  46.        
  47.         # Look for each directory in the comma separated list to copy files from.
  48.         # Variable found will be set to true, if any file for a romname is found.
  49.         found=false
  50.         for dir in $(echo $includedir | sed "s/,/ /g")
  51.         do
  52.             # Build up final file to look at. If file exists, then copy it into
  53.             # the created folder. If not, write a line that the file does not exist.
  54.             # Look only for first found file and then exit for searching next romname.
  55.             file="$basedir/$dir/$romname.png"
  56.             if [ -f "$file" ];
  57.             then
  58.                 cp "$file" "extras/$romname-$dir.png"
  59.                 found=true
  60.                 break
  61.             else
  62.                 found=false
  63.             fi
  64.         done
  65.        
  66.         # If nothing is found per romname, it will create a only one entry for each romname.
  67.         if [ "$found" = false ];  
  68.         then
  69.             echo "Nothing found for $romname." >> "$logfile"
  70.         fi
  71.        
  72.     fi # End of Proceed only if the line is not empty.
  73. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement