Created
August 4, 2014 05:19
-
-
Save meoow/9daae45b4025595c5ce7 to your computer and use it in GitHub Desktop.
Convert DMG to ISO format (using expect and mkisofs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#export IFS=$'\n' | |
which -s mkisofs || { | |
echo can\'t not find mkisofs >&2 | |
exit 1 | |
} | |
path="$(dirname "$1")" | |
name="$(basename "$1")" | |
folder="${name%.[Dd][Mm][Gg]}" | |
cd "$path" | |
while ! mkdir "${folder}_$((++i))";do | |
: | |
done | |
expect <<_EOF_ | |
spawn hdiutil attach -mountpoint "${folder}_$i" -noverify -noidme -noautoopen "$name" | |
sleep 1 | |
expect "access*:" | |
send "www.macx.cn\r" | |
set timeout 2 | |
expect eof | |
_EOF_ | |
sleep 1 | |
mkisofs -R -o "$folder".iso -A "$folder" -find "${folder}_$i" ! \( -maxdepth 1 \( -ipath "${folder}_$i/.*" -o -ipath "${folder}_$i/*.webloc" -o -type l \) \) -a \( -maxdepth 10000 -a ! -iname '*@2x*.png' -a \( ! -ipath '*.lproj/*' -o -ipath '*/english.lproj/*' -o -ipath '*/zh[-_]cn.lproj/*' -o -ipath '*/zh[-_]hans.lproj/*' -o -ipath '*/chinese.lproj/*' -o -ipath '*/en.lproj/*' \) \) || { | |
hdiutil detach "${folder}_$i" && rm -rf "${folder}_$i" | |
exit 1 | |
} | |
sleep 1 | |
read -n 1 -p "Remove the source file? [Y/n]:" ans | |
echo "" | |
hdiutil detach "${folder}_$i" && rm -rf "${folder}_$i" | |
if [[ $ans == "" ]] || [[ $ans =~ [^Nn] ]] ;then | |
rm "$1" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment