Last active
June 1, 2018 20:00
-
-
Save guoxiaoqiao/5b8f13ecf1853933932ec3ef0cf00c26 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 | |
DMG_PATH="/Applications/Install macOS High Sierra.app/Contents/SharedSupport" | |
# 先卸载要用到的卷名,避免冲突 | |
hdiutil detach "/Volumes/InstallESD" &> /dev/null | |
hdiutil detach "/Volumes/OS X Base System" &> /dev/null | |
rm /tmp/HighSierra.sparseimage &> /dev/null | |
# Create the High Sierra Blank ISO Image with a Single Partition - Apple Partition Map | |
hdiutil create -o /tmp/HighSierra -size 3g -layout SPUD -fs HFS+J -type SPARSE | |
# Mount the High Sierra Blank ISO Image | |
hdiutil attach /tmp/HighSierra.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build | |
# Restore the Base System into the High Sierra Blank ISO Image | |
asr restore -source "$DMG_PATH/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 Online Install" | |
hdiutil detach /Volumes/"$VOLUME_NAME" &> /dev/null | |
diskutil rename "OS X Base System" "$VOLUME_NAME" | |
# 复制光盘图标 | |
cp -p "$DMG_PATH/../../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中查找High Sierra,并点击“获取”,等下载完不安装。然后执行ISO打包脚本即可创建此ISO。 | |
注意:系统需要先安装Commnad Line Developer Tools才能执行打包命令,或者在执行出错时按提示安装,安装后再次执行即可。 | |
镜像作者:小桥 | |
QQ:29551030 | |
EOF | |
# Copy installer package | |
hdiutil attach "$DMG_PATH/InstallESD.dmg" -noverify -nobrowse -mountpoint /Volumes/InstallESD | |
ditto -V /Volumes/InstallESD/Packages/OSInstall.mpkg /Volumes/"$VOLUME_NAME"/ | |
hdiutil detach "/Volumes/InstallESD" &> /dev/null | |
# Unmount the High Sierra ISO Image | |
hdiutil detach /Volumes/"$VOLUME_NAME" | |
hdiutil resize -size `hdiutil resize -limits /tmp/HighSierra.sparseimage | tail -n 1 | awk '{ print $1 }'`b /tmp/HighSierra.sparseimage | |
# Convert the High Sierra ISO Image to ISO/CD master (Optional) | |
hdiutil convert /tmp/HighSierra.sparseimage -format UDTO -o /tmp/HighSierra.iso | |
rm /tmp/HighSierra.sparseimage | |
# Rename the High Sierra ISO Image and move it to the desktop | |
mv /tmp/HighSierra.iso.cdr ~/Desktop/"$VOLUME_NAME".iso | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment