Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

GPGnet Vault Map Mirror Process

By: cursix on Apr 18th, 2012  |  syntax: Bash  |  size: 2.64 KB  |  views: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. # This script takes the maps extracted from the gpgnet vault
  3. # archive, extracts them from their .vault format and then
  4. # renames them to mapname.v0001 and zips them up
  5. # -Cursix
  6.  
  7. # NOTE: This script uses 7-zip to do extract/create zips
  8.  
  9. SOURCEDIR="/path/to/mods"
  10. MIRRORDIR="/path/to/mirror"
  11. STAGE1DIR="/path/to/stage1"
  12. STAGE2DIR="/path/to/stage2"
  13. LOGFILE="/path/to/log"
  14.  
  15. test -e $MIRRORDIR || mkdir -p $MIRRORDIR
  16. test -e $STAGE1DIR || mkdir -p $STAGE1DIR
  17.  
  18. echo "===Log Start: `date "+%F %H:%M:%S"`===" > $LOGFILE
  19. echo "---Begin Extraction---" >> $LOGFILE
  20.  
  21. cd $SOURCEDIR
  22.  
  23. # Find the latest version of each map and extract them to stagedir
  24. for map in *; do
  25.         # Since we can have 1.vault, 2.vault, etc, find the highest version
  26.         # Probably could be done more efficiently
  27.         mapver=0
  28.         for (( i=1; i<20; i++ )); do
  29.                 if [ -f "$map/$i.vault" ]; then
  30.                         mapver=$i
  31.                 fi
  32.         done
  33.  
  34.         # if mapver is 0 we obviously found no .vault file
  35.         # save map name to logfile to look at manually
  36.         if [ $mapver -lt 1 ]; then
  37.                 echo "ERROR! No vault in: $map" >> $LOGFILE
  38.                 continue
  39.         fi
  40.  
  41.         echo "----------------------------------"
  42.         echo "Extracting $map..."
  43.         mkdir -p "$STAGE1DIR/$map"
  44.         7za x "$map/$mapver.vault" -o"$STAGE1DIR/$map"
  45. done
  46.  
  47. echo "Extraction Complete, begining rename and zip."
  48. echo "This will take a while..."
  49. echo "---Begin Rename and Zip---" >> $LOGFILE
  50.  
  51. cd $STAGE1DIR
  52.  
  53. # Look inside each extracted map, find the senario file and
  54. # rename directory to map name. Should come out to something
  55. # thismap.v0001 or similar according to Ze_PilOt
  56. for map in *; do
  57.         cd "$STAGE1DIR/$map"
  58.         # Find the senario file, don't assume its ${map}_senario.lua
  59.         i=0
  60.         for scenario in "$( find . -maxdepth 1 -name "*_scenario.lua" )"; do
  61.                 mapname=''
  62.                 if [ -z "$scenario" ]; then
  63.                         echo "WARNING! No scenario file in: $map" >> $LOGFILE
  64.                         continue
  65.                 fi
  66.                 # Find the map variable and extract map name
  67.                 mapname=`grep "^[[:space:]]*map[[:space:]]*=" "$scenario" | sed "s/.*maps\/\(.*\)\/.*/\1/"`
  68.                 ((i++))
  69.                 # If i is greater than 1, we have more than one senario file. Complain!
  70.                 if [ $i -gt 1 ]; then
  71.                         echo "WARNING! $map may have more than one senario file!" >> $LOGFILE
  72.                 fi
  73.         done
  74.         if [ -z "$mapname" ]; then
  75.                 # Something went wrong, no mapname was found!
  76.                 echo "ERROR! Unable to find mapname value for: $map" >> $LOGFILE
  77.                 continue
  78.         fi
  79.         # Now rename it
  80.         echo "Renaming $map to $mapname"
  81.         mkdir -p "$STAGE2DIR/$map"
  82.         cd $STAGE1DIR
  83.         mv "$map" "$STAGE2DIR/$map/$mapname"
  84.         cd "$STAGE2DIR/$map"
  85.         echo "Zipping $map"
  86.         7za a -tzip "$MIRRORDIR/$map.zip" "$mapname" -mx=9
  87.         cd $STAGE1DIR
  88. done
  89.  
  90. echo "==================="
  91. echo "Done!"
clone this paste RAW Paste Data