Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # titleupdate.sh rev 2
- #
- # by Molukki on 12 Jan 2012
- #
- # This file is public domain.
- #
- # Set field separator to newline
- OLDIFS=$IFS
- IFS=$(echo -en "\n\b")
- # Check for cmd line parameters
- if [ "x$1" == "x" ]
- then
- echo "Usage: $0 [FILE]... [DIR]..."
- exit 1
- fi
- # Function to download a title update
- #
- # Takes one parameter: the ISO file
- function get_title_update
- {
- # Save current dir
- CURRENTDIR=$(pwd)
- # Get path component
- ISOPATH=$(dirname "$1")
- # Use ABGX360 to extract the Media ID from ISO file
- MEDIAID=$(abgx360 -f -g -o -w --noverify 2>/dev/null "$1" \
- | grep -i "XEX Media ID" | head -1 | cut -d '-' -f 2)
- # Check if ID was found, return if not
- if [ "x$MEDIAID" == "x" ]
- then
- echo "No Media ID found for file $1. (Not an XBox360 iso?)"
- return 0
- fi
- echo " === Searching for Media ID $MEDIAID for file $1"
- echo -n " === "
- # Scrape for title update from xbuc.net.
- curl -s "http://www.xbuc.net/?searchString=$MEDIAID" \
- | grep '^<td>' | tr -d '\n' | tr -d '\r' | sed 's/<\/td>/<\/td>\n/g' \
- | head -n 6 | while read DATA
- do
- echo -n $DATA | sed 's/<[^>]*>//g'
- echo -n " "
- # Check for title update name in line
- if [[ "$DATA" =~ "details=" ]]
- then
- TITLE=$(echo $DATA | sed 's/<[^>]*>//g')
- fi
- # Check for title update download URL in line
- if [[ "$DATA" =~ "download" ]]
- then
- echo
- # Create title update directory in ISO path
- mkdir 2>/dev/null "$ISOPATH/$TITLE"
- cd "$ISOPATH/$TITLE"
- # Extract download path from line
- DOWNLOAD=$(echo "$DATA" | cut -d "'" -f 2 | sed 's/\&/\&/g')
- # Fetch the real download location from xbuc.net
- LOCATION=$(curl -s -D - http://www.xbuc.net/$DOWNLOAD \
- | grep Location: | cut -d ' ' -f 2- | tr -d '\n' | tr -d '\r')
- echo
- echo "=== Downloading $ISOPATH/$TITLE from $LOCATION"
- echo
- # Download the update!
- wget -N --tries=3 $LOCATION
- # Check return value. If download failed, try direct download.
- RETVAL=$?
- if [ $RETVAL -ne 0 ]
- then
- LOCATION=$(echo $LOCATION | sed 's/.nyud.net//')
- echo
- echo " === Downloading $ISOPATH/$TITLE from $LOCATION"
- echo
- wget -N --tries=1 $LOCATION
- fi
- fi
- done
- cd "$CURRENTDIR"
- }
- for ARG in "$@"
- do
- # Test if file
- if [ -f "$ARG" ]
- then
- get_title_update "$ARG"
- fi
- # Test if path
- if [ -d "$ARG" ]
- then
- # Find all .iso files in path
- for ISOFILE in $(find $ARG -iname '*.iso')
- do
- get_title_update "$ISOFILE"
- done
- fi
- done
- # Restore field separator
- IFS=$OLDIFS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement