Skip to content

Instantly share code, notes, and snippets.

@greguz
Last active March 13, 2023 08:59
Show Gist options
  • Save greguz/aa33f06e00e725a0abc5da2a0d53d0ca to your computer and use it in GitHub Desktop.
Save greguz/aa33f06e00e725a0abc5da2a0d53d0ca to your computer and use it in GitHub Desktop.
Split Xbox ISO files when necessary, also build its attach.xbe
#!/bin/bash
set -e
isoDir="$1"
if ! [ -d "$isoDir" ];
then
echo "$isoDir not a dir"
exit 1
fi
maxSize=4242538495 # 4 GiB minus 50 MiB (bytes)
part1Dir=$isoDir/.tmp1
part2Dir=$isoDir/.tmp2
mkdir -p "$part1Dir"
mkdir -p "$part2Dir"
for isoFile in $isoDir/*.iso; do
echo "process $isoFile"
isoSize=$(stat -c%s "$isoFile")
echo "prepare"
rm -rf $part1Dir/*
rm -rf $part2Dir/*
echo "extract xiso"
extract-xiso "$isoFile" -d "$part1Dir" > /dev/null
isoName=$(basename "$isoFile" .iso)
mkdir "$isoDir/$isoName"
# see https://github.com/greguz/attach-xbe-builder
if [[ -f "$part1Dir/default.xbe" ]]; then
echo "build default.xbe"
./build-attach-xbe-linux "$part1Dir/default.xbe" "$isoDir/$isoName/default.xbe"
fi
if [[ -f "$part1Dir/Default.xbe" ]]; then
echo "build default.xbe"
./build-attach-xbe-linux "$part1Dir/Default.xbe" "$isoDir/$isoName/default.xbe"
fi
if [ $isoSize -gt $maxSize ]
then
oldSize=0
echo "move files"
find "$part1Dir" -type f | while read file
do
fileSize=$(stat --printf="%s" "$file")
newSize=$(($oldSize + $fileSize))
if [ $newSize -gt $maxSize ]
then
mvFile="${file/"$part1Dir"/"$part2Dir"}"
mvDir=$(dirname "$mvFile")
mkdir -p "$mvDir"
mv "$file" "$mvFile"
fi
oldSize=$newSize
done
echo "build part1 iso"
extract-xiso -c "$part1Dir" "$isoDir/$isoName/game.1.iso" > /dev/null
echo "build part2 iso"
extract-xiso -c "$part2Dir" "$isoDir/$isoName/game.2.iso" > /dev/null
else
echo "move iso"
mv "$isoFile" "$isoDir/$isoName/game.iso"
fi
done
echo "cleanup"
rm -rf "$part1Dir"
rm -rf "$part2Dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment