Skip to content

Instantly share code, notes, and snippets.

@zhxq
Created October 21, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhxq/d34df0ce34ed34b6d796 to your computer and use it in GitHub Desktop.
Save zhxq/d34df0ce34ed34b6d796 to your computer and use it in GitHub Desktop.
Mac OS X 10.10 Install.DMG Flashdisk Dumper
#!/bin/bash
if [[ $1 == "" ]]; then
echo "欢迎您使用由zhxq开发的Mac OS X 10.10制作安装盘工具!"
echo "本软件以CC-BY-SA 3.0协议发布。"
echo "本软件涉及到磁盘操作,若不当使用可能会造成数据丢失!"
echo "本人对一切数据丢失概不负责。"
echo "操作有价,数据无价!"
echo "ver:1.1 beta"
echo "www.zhxqweb.com"
echo "zhxq@zhxqweb.com"
echo ""
echo "为了您的方便,若您U盘达到8个G,可以考虑拆分成两个分区。"
echo "将其一设置成6.5G左右用作安装盘,另一部分当做正常U盘。"
echo "请输入目标宗卷的名称:"
read volumename
else
volumename=$1
fi
if [ "${volumename:0:8}" != "/Volumes/" ]; then
volumename="/Volumes/$volumename"
fi
if [ ! -d "$volumename" ]; then
direrror1=1
fi
if [ "$volumename" == "" ]; then
direrror2=1
fi
if [ "${volumename:0:4}" == "OS X" ]; then
direrror3=1
fi
if [[ $1 == '' ]]; then
while [ "$direrror1" == "1" ] || [ "$direrror2" == "1" ]
do
echo "输入的宗卷不存在!"
echo "请再次输入目标宗卷的名称:"
read volumename
if [ "${volumename:0:8}" != "/Volumes/" ]; then
volumename="/Volumes/$volumename"
fi
if [ ! -d "$volumename" ]; then
direrror1=1
else
direrror1=0
fi
if [ "$volumename" == "" ]; then
direrror2=1
else
direrror2=0
fi
done
while [ "$direrror3" == "1" ]
do
echo "宗卷名称开头不得为OS X!请重命名或者重新选择一个磁盘"
read volumename
if [ "${volumename:0:4}" == "OS X" ]; then
direrror3=1
else
direrror3=0
fi
done
echo ""
echo "您将要把"$volumename"制作成安装盘"
echo "确定?(y/n)"
read confirminstall
if [ "$confirminstall" != 'y' ]; then
echo '您取消了安装。'
exit
fi
else
if [ "$direrror1" == "1" ] || [ "$direrror2" == "1" ]; then
echo "错误:目标宗卷不存在"
exit
fi
if [ "$direrror3" == "1" ]; then
echo "错误:宗卷名称开头不得为OS X,请您重命名磁盘后再试"
exit
fi
fi
if [[ $2 == '' ]]; then
echo ""
echo "请拖入InstallESD.dmg"
read installesddmg
else
installesddmg=$2
fi
if [ ! -f "$installesddmg" ]; then
fileerror=1
fi
if [ "$installesddmg" == "" ]; then
fileerror=1
fi
if [[ $2 == '' ]]; then
while [ "$fileerror" == "1" ]
do
echo "输入的dmg位置不存在!"
echo "请再次拖入InstallESD.dmg"
read installesddmg
if [ ! -f "$installesddmg" ]; then
fileerror=1
else
fileerror=0
fi
if [ "$installesddmg" == "" ]; then
fileerror=1
else
fileerror=0
fi
done
else
if [ "$fileerror" == "1" ]; then
echo "输入的位置不存在!"
exit
fi
fi
echo ""
echo "现在可以开始安装了!"
if [ $2 != '' ]; then
echo "目标宗卷:"$1" InstallESD镜像:"$2
fi
echo ''>/tmp/zhxqinstall.tmp
cd /Volumes
find -d OS\ X\ * -maxdepth 0 -exec echo {}>>/tmp/zhxqinstall.tmp \;
cat /tmp/zhxqinstall.tmp | while read line
do
echo $line
if [ "$line" != "" ]; then
hdiutil detach "$line" -force
fi
done
rm /tmp/zhxqinstall.tmp
echo ''>"/Volumes/OS X Base System"
rm "/Volumes/OS X Base System"
hdiutil attach -quiet -noautoopen $installesddmg
echo "需要管理员权限,请输入密码"
sudo asr restore --source /Volumes/OS\ X\ Install\ ESD/BaseSystem.dmg --target $volumename --erase --noprompt
echo ""
echo "正在拷入必备文件……"
cd /Volumes
find -d OS\ X\ Base\ System* -maxdepth 0 -exec echo {}>>/tmp/zhxqinstall.tmp \;
cat /tmp/zhxqinstall.tmp | while read line
do
echo $line
if [ "$line" != "" ]; then
cd "/Volumes/$line/System/Installation"
sudo rm Packages
sudo cp -r /Volumes/OS\ X\ Install\ ESD/Packages "/Volumes/$line/System/Installation/"
sudo cp /Volumes/OS\ X\ Install\ ESD/BaseSystem.dmg "/Volumes/$line"
sudo cp /Volumes/OS\ X\ Install\ ESD/BaseSystem.chunklist "/Volumes/$line"
fi
done
rm /tmp/zhxqinstall.tmp
sleep 2
echo ""
echo "完成!"
echo "感谢您的使用!"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment