|
#!/usr/bin/env bash |
|
# A script for making HCRDotum.bundle for PwnageTool up-to-date |
|
# Usage: update-HCRDotum.bundle.sh "iPhone Software Updates"/*.ipsw |
|
# |
|
# Author: Jaeho Shin <[email protected]> |
|
# Created: 2011-05-07 |
|
set -eu |
|
|
|
bundle=HCRDotum.bundle |
|
path=System/Library/Fonts/Cache |
|
|
|
[ $# -eq 1 ] || { sed -n '2,/^#$/ s/^# //p' <"$0"; exit 1; } |
|
|
|
ipsw=$1; shift |
|
|
|
name=`basename "$ipsw"` |
|
name=${name%_Restore.ipsw} |
|
device=${name%%_*} |
|
version=$name |
|
version=${version#${device}_} |
|
|
|
mkdir -p "$bundle/files/$path" |
|
|
|
# first, download fonts (HCRDotum) |
|
LocalName=Hamchorom-LVT.zip |
|
URL=http://ftp.ktug.or.kr/KTUG/hcr-lvt/Hamchorom-LVT.zip |
|
echo "Downloading $LocalName" |
|
completeFlag="$LocalName.complete" |
|
if [ -e "$completeFlag" ]; then |
|
# avoid downloading twice if we have a complete one |
|
rm -f "$completeFlag" |
|
curl -L -Rz "$LocalName" -o "$LocalName" "$URL" || curl -L -R -o "$LocalName" "$URL" |
|
else |
|
# otherwise, try resuming the previous one |
|
curl -L -R -C - -o "$LocalName" "$URL" || curl -L -R -o "$LocalName" "$URL" |
|
fi |
|
touch "$completeFlag" |
|
echo "Extracting Fonts from $LocalName" |
|
unzip -o "$LocalName" HANDotum* |
|
mv -f HANDotum-LVT.ttf "$bundle/files/$path"/AppleGothic.ttf |
|
mv -f HANDotumB-LVT.ttf "$bundle/files/$path"/AppleGothicBold.ttf |
|
|
|
#read -p "Please mount the root filesystem of the ipsw and press Enter..." |
|
dmg_decrypted="${device}_$version".dmg |
|
if [ -f "$dmg_decrypted" ]; then |
|
echo "Using $dmg_decrypted" |
|
else |
|
echo "Extracting $dmg_decrypted from ipsw" |
|
tmp=`mktemp -d /tmp/PwnageToolBundleGenerator.XXXXXX` |
|
trap "rm -rf $tmp" EXIT |
|
# extract ipsw |
|
echo "Extracting ipsw" |
|
unzip "$ipsw" -d $tmp |
|
dmg=`ls -S $tmp/*.dmg | head -n 1` |
|
# decrypt root fs |
|
dmgname=`basename $dmg` |
|
build=${version#*_} |
|
echo "Consult http://theiphonewiki.com/wiki/index.php?search=$dmgname+$build" |
|
read -p "And enter the found VFDecrypt Key for $dmgname:" key |
|
./vfdecrypt -i $dmg -k "$key" -o "$dmg_decrypted" |
|
fi |
|
|
|
# attach the root fs image and import contents from it |
|
root=(/Volumes/*.N88OS) |
|
if [ ! -d "$root" ]; then |
|
hdiutil attach "$dmg_decrypted" |
|
root=(/Volumes/*.N88OS) |
|
fi |
|
echo "Importing original files from $root" |
|
rm -f "$bundle/files/$path"/../*.plist |
|
find "$root/$path"/../*.plist -type f -exec cp -av {} "$bundle/files/$path"/../ \; |
|
|
|
# Update plists |
|
( |
|
cd "$bundle" |
|
for p in "files/$path"/../*.plist; do |
|
echo "Updating $p" |
|
plutil -convert xml1 "$p" |
|
vim +'%s/\(Bold.*\n.*AppleGothic\)</\1 Bold</g' +wq "$p" |
|
vim +1 +'/>AppleGothic Regular<' +'norm 2yyjp' +'norm fRceBold' +'norm jf.iBold' +wq "$p" |
|
plutil -convert binary1 "$p" |
|
done |
|
) |
|
|
|
# Adjust Info.plist |
|
# SupportedFirmware |
|
vim +'%s:\(<string>'"$device"'_\)\d\+\(\.\d\+\)\+_\w\+\(</string>\):\1'"$version"'\3:g' +wq "$bundle"/Info.plist |
|
echo "Updating Info.plist: SupportedFirmware ${device}_$version" |
|
# Size |
|
size=$(bc <<<"`stat -c %s "$bundle/files/$path"/* | tr '\n' '+'` -`stat -c %s "$root/$path"/AppleGothic.ttf`") |
|
echo "Updating Info.plist: Size=$size" |
|
vim +'%s/\(Size.*\n.*integer>\)\d\+</\1'"$size"'</g' +wq "$bundle"/Info.plist |
|
|
|
|
|
# clean up |
|
hdiutil detach "$root" |