Last active
May 16, 2017 08:17
-
-
Save guoxiaoqiao/d55a3b50b1b1a59f418cdb1f47543b8f to your computer and use it in GitHub Desktop.
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 | |
# 用于创建macOS安装ISO的脚本文件 | |
# 初始脚本来源:http://www.insanelymac.com/forum/topic/308533-how-to-create-a-bootable-el-capitan-iso-fo-vmware/ | |
set -x | |
SCRIPT_PATH=`pwd`/$0 | |
# 先卸载要用到的卷名,避免冲突 | |
hdiutil detach /Volumes/OS\ X\ Install\ ESD &> /dev/null | |
hdiutil detach /Volumes/OS\ X\ Base\ System &> /dev/null | |
hdiutil detach /Volumes/install_app &> /dev/null | |
rm /tmp /tmp/Sierra.cdr.dmg &> /dev/null | |
# Mount the installer image | |
hdiutil attach /Applications/Install\ macOS\ Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app | |
# 计算要创建的ISO文件大小,算法为基础软件包大小加上BaseSystem.dmg大小的4倍再减去170M | |
PACKAGE_SIZE=$(du -hsm /Volumes/install_app/Packages | awk -F ' ' '{print $1}') | |
DMG_SIZE=$(du -hsm /Volumes/install_app/BaseSystem.dmg | awk -F ' ' '{print $1}') | |
TOTAL_SIZE=`expr $PACKAGE_SIZE + $DMG_SIZE \* 4 - 170` | |
# Create the Sierra Blank ISO Image with a Single Partition - Apple Partition Map | |
hdiutil create -o /tmp/Sierra.cdr -size ${TOTAL_SIZE}m -layout SPUD -fs HFS+J | |
# Mount the Sierra Blank ISO Image | |
hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build | |
# Restore the Base System into the Sierra Blank ISO Image | |
asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase | |
# 更改磁盘名称与当前版本相关 | |
VERSION=$(sed -n -e 's/.*<string>\(.*\)<\/string>.*/\1/p' /Volumes/OS\ X\ Base\ System/System/Library/CoreServices/SystemVersion.plist | tail -n 1) | |
VOLUME_NAME="macOS $VERSION Install" | |
diskutil rename "OS X Base System" "$VOLUME_NAME" | |
# 复制光盘图标 | |
cp -p /Applications/Install\ macOS\ Sierra.app/Contents/Resources/InstallAssistant.icns /Volumes/"$VOLUME_NAME"/.VolumeIcon.icns | |
SetFile -a C /Volumes/"$VOLUME_NAME"/ | |
# 将本脚本复制到光盘 | |
cp -a $SCRIPT_PATH /Volumes/"$VOLUME_NAME"/ | |
# 写入说明文件 | |
cat << EOF > /Volumes/"$VOLUME_NAME"/说明.txt | |
此镜像为VMware Workstation安装苹果系统用,原始文件来源于苹果系统官方更新包,未添加任何其他程序,完全可放心使用。 | |
更新包获取方法:在App Store中查找Sierra,并点击“获取”,等下载完不安装。然后执行ISO打包脚本即可创建此ISO。 | |
镜像作者:小桥 | |
QQ:29551030 | |
EOF | |
# Remove Package link and replace with actual files | |
rm /Volumes/"$VOLUME_NAME"/System/Installation/Packages | |
cp -rp /Volumes/install_app/Packages /Volumes/"$VOLUME_NAME"/System/Installation/ | |
# Copy El Capitan installer dependencies | |
cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/"$VOLUME_NAME"/BaseSystem.chunklist | |
cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/"$VOLUME_NAME"/BaseSystem.dmg | |
# Unmount the installer image | |
hdiutil detach /Volumes/install_app | |
# Unmount the Sierra ISO Image | |
hdiutil detach /Volumes/"$VOLUME_NAME" | |
# Convert the Sierra ISO Image to ISO/CD master (Optional) | |
hdiutil convert /tmp/Sierra.cdr.dmg -format UDTO -o /tmp/Sierra.iso | |
rm /tmp/Sierra.cdr.dmg | |
# Rename the Sierra ISO Image and move it to the desktop | |
mv /tmp/Sierra.iso.cdr ~/Desktop/"$VOLUME_NAME".iso |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
版本3增加了ISO大小的自动计算,避免因新版本容量增加导致镜像创建失败。