Skip to content

Instantly share code, notes, and snippets.

@guoxiaoqiao
Last active February 4, 2018 14:38
Show Gist options
  • Save guoxiaoqiao/b68cbbdb94ac34335d31843449e32d29 to your computer and use it in GitHub Desktop.
Save guoxiaoqiao/b68cbbdb94ac34335d31843449e32d29 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 用于创建macOS安装ISO的脚本文件
# 初始脚本来源:http://www.insanelymac.com/forum/topic/308533-how-to-create-a-bootable-el-capitan-iso-fo-vmware/
# High Sierra的ISO制作方法也参考了:http://www.kaufmann.no/roland/articles/20171007-high-sierra-iso.html
set -x
SCRIPT_PATH=`pwd`/$0
APP_PATH="/Applications/Install macOS High Sierra.app"
DMG_PATH="$APP_PATH/Contents/SharedSupport"
# 先卸载要用到的卷名,避免冲突
hdiutil detach "/Volumes/OS X Base System" &> /dev/null
rm /tmp/HighSierra.sparseimage &> /dev/null
# 计算要最终镜像的大小
APP_SIZE=$(du -hsm "$APP_PATH" | awk -F ' ' '{print $1}')
TOTAL_SIZE=`expr $APP_SIZE + 1200`m
# Create the High Sierra Blank ISO Image with a Single Partition - Apple Partition Map
hdiutil create -o /tmp/HighSierra -size $TOTAL_SIZE -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 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
# 复制完整安装程序到镜像,排除重复的文件
rm -rf "/Volumes/"$VOLUME_NAME"/Install macOS High Sierra.app"
rsync -a --progress "$APP_PATH" /Volumes/"$VOLUME_NAME"/
# Unmount the High Sierra ISO Image
hdiutil detach /Volumes/"$VOLUME_NAME"
# 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