Advertisement
Guest User

titleupdate.sh

a guest
Jan 12th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.96 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # titleupdate.sh rev 2
  4. #
  5. # by Molukki on 12 Jan 2012
  6. #
  7. # This file is public domain.
  8. #
  9.  
  10. # Set field separator to newline
  11. OLDIFS=$IFS
  12. IFS=$(echo -en "\n\b")
  13.  
  14. # Check for cmd line parameters
  15. if [ "x$1" == "x" ]
  16. then
  17.     echo "Usage: $0 [FILE]... [DIR]..."
  18.     exit 1
  19. fi
  20.  
  21. # Function to download a title update
  22. #
  23. # Takes one parameter: the ISO file
  24. function get_title_update
  25. {
  26.     # Save current dir
  27.     CURRENTDIR=$(pwd)
  28.     # Get path component
  29.     ISOPATH=$(dirname "$1")
  30.     # Use ABGX360 to extract the Media ID from ISO file
  31.     MEDIAID=$(abgx360 -f -g -o -w --noverify 2>/dev/null "$1" \
  32.       | grep -i "XEX Media ID" | head -1 | cut -d '-' -f 2)
  33.  
  34.     # Check if ID was found, return if not
  35.     if [ "x$MEDIAID" == "x" ]
  36.     then
  37.         echo "No Media ID found for file $1. (Not an XBox360 iso?)"
  38.         return 0
  39.     fi
  40.  
  41.     echo " === Searching for Media ID $MEDIAID for file $1"
  42.     echo -n " === "
  43.     # Scrape for title update from xbuc.net.
  44.     curl -s "http://www.xbuc.net/?searchString=$MEDIAID" \
  45.       | grep '^<td>' | tr -d '\n' | tr -d '\r' | sed 's/<\/td>/<\/td>\n/g' \
  46.       | head -n 6 | while read DATA
  47.     do
  48.         echo -n $DATA | sed 's/<[^>]*>//g'
  49.         echo -n "  "
  50.         # Check for title update name in line
  51.         if [[ "$DATA" =~ "details=" ]]
  52.         then
  53.             TITLE=$(echo $DATA | sed 's/<[^>]*>//g')
  54.         fi
  55.         # Check for title update download URL in line
  56.         if [[ "$DATA" =~ "download" ]]
  57.         then
  58.             echo
  59.             # Create title update directory in ISO path
  60.             mkdir 2>/dev/null "$ISOPATH/$TITLE"
  61.             cd "$ISOPATH/$TITLE"
  62.             # Extract download path from line
  63.             DOWNLOAD=$(echo "$DATA" | cut -d "'" -f 2 | sed 's/\&amp;/\&/g')
  64.             # Fetch the real download location from xbuc.net
  65.             LOCATION=$(curl -s -D - http://www.xbuc.net/$DOWNLOAD \
  66.               | grep Location: | cut -d ' ' -f 2- | tr -d '\n' | tr -d '\r')
  67.             echo
  68.             echo "=== Downloading $ISOPATH/$TITLE from $LOCATION"
  69.             echo
  70.             # Download the update!
  71.             wget -N --tries=3 $LOCATION
  72.             # Check return value. If download failed, try direct download.
  73.             RETVAL=$?
  74.             if [ $RETVAL -ne 0 ]
  75.             then
  76.                 LOCATION=$(echo $LOCATION | sed 's/.nyud.net//')
  77.                 echo
  78.                 echo " === Downloading $ISOPATH/$TITLE from $LOCATION"
  79.                 echo
  80.                 wget -N --tries=1 $LOCATION
  81.             fi
  82.         fi
  83.     done
  84.     cd "$CURRENTDIR"
  85. }
  86.  
  87. for ARG in "$@"
  88. do
  89.     # Test if file
  90.     if [ -f "$ARG" ]
  91.     then
  92.         get_title_update "$ARG"
  93.     fi
  94.  
  95.     # Test if path
  96.     if [ -d "$ARG" ]
  97.     then
  98.         # Find all .iso files in path
  99.         for ISOFILE in $(find $ARG -iname '*.iso')
  100.         do
  101.             get_title_update "$ISOFILE"
  102.         done
  103.     fi
  104.  
  105. done
  106.  
  107. # Restore field separator
  108. IFS=$OLDIFS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement