Last active
November 16, 2015 01:25
-
-
Save xkyii/3a82464f1d4762ad99e8 to your computer and use it in GitHub Desktop.
制作DMG
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/sh | |
#from http://blog.csdn.net/zenghao0708/article/details/24330621 | |
LogFile="/private/var/tmp/VTechMakeProductLog.txt"; | |
fun() | |
{ | |
StateCode=$? | |
c_time=$(date +%Y/%m/%d" "%H:%M:%S) | |
/bin/echo "\n$c_time [build dmg] state=[$StateCode]:$1" >> $LogFile | |
/bin/echo "$2" >> $LogFile 2>&1 | |
} | |
if [ $# != 3 ]; then | |
echo "Usage: CreateDmg.sh volName srcDir destDmg" | |
echo $VOL | |
exit 0 | |
fi | |
VOL="$1" | |
ORIGIN="$2" | |
Dest="$3" | |
DMG="$Dest.dmg" | |
if [ -e "$DMG" ]; then | |
rm -f "$DMG" | |
fi | |
echo ORIGIN=[$ORIGIN] | |
SIZE=$(du -sh $ORIGIN) | |
SIZE=$(echo $SIZE | awk -F'[ ]' '{printf $1}') | |
UNIT=$(echo $SIZE|awk '{print substr($0,length($0),length($0))}') | |
SIZE=$(echo $SIZE|awk '{print substr($0,0,length($0)-1)}') | |
echo unit=[$UNIT]; | |
echo SIZE=[$SIZE] | |
if [ $UNIT = "G" ]; then | |
SIZE=$(echo $SIZE | awk '{print $0*1024*1024+10}')"M" | |
elif [ $UNIT = "M" ];then | |
SIZE=$(echo $SIZE | awk '{print $0+5}')"M" | |
elif [ $UNIT = "K" ];then | |
SIZE=$(echo $SIZE | awk '{print $0/1000+10}')"M" | |
elif [ $UNIT = "B" ];then | |
SIZE=$(echo $SIZE | awk '{print $0+1000*1000}')"B" | |
fi | |
echo [$SIZE] | |
if [ -e "/Volumes/$VOL" ]; then | |
hdiutil create -megabytes $SIZE -fs HFS+ -volname "$VOL" DmgTemp 2>&1 | |
fi | |
cmdRes=$(hdiutil create -megabytes $SIZE -fs HFS+ -volname "$VOL" DmgTemp 2>&1) | |
fun "hdiutil create" "$cmdRes" | |
cmdRes=$(hdiutil mount DmgTemp.dmg 2>&1) | |
fun "hdiutil mount" "$cmdRes" | |
cmdRes=$(/usr/bin/codesign --display --verbose=4 "$ORIGIN/$VOL.app" 2>&1) | |
fun "codesign check" "$cmdRes" | |
cmdRes=$(ditto -rsrcFork "$ORIGIN" "/Volumes/$VOL" 2>&1) | |
fun "ditto -rsrcFork" "$cmdRes" | |
cmdRes=$(hdiutil eject "/Volumes/$VOL" 2>&1) | |
fun "hdiutil eject" "$cmdRes" | |
cmdRes=$(hdiutil convert DmgTemp.dmg -format UDZO -o "$DMG" 2>&1) | |
fun "hdiutil convert" "$cmdRes" | |
rm "DmgTemp.dmg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment