網站首頁 語言 會計 網際網路計算機 醫學 學歷 職場 文藝體育 範文
當前位置:學識谷 > 計算機 > 作業系統

Linux系統通過命令列建立dmg檔案

欄目: 作業系統 / 釋出於: / 人氣:8.94K

Linux系統操作中,很多人對dmg檔案不甚瞭解,更不知道要如何建立dmg檔案了,本文要給大家介紹的是Linux使用命令列建立dmg檔案的方法,不瞭解的朋友可以來了解下。更多內容請關注應屆畢業生網!

Linux系統通過命令列建立dmg檔案

  什麼是DMG檔案,如何開啟?

DMG格式是在MAC系統上的一個鏡象檔案,也可以說是壓縮檔案,如果你用PC且沒有裝MAC OS X for X86的話,就不要費力了。如果你是使用蘋果機或在PC上裝了MAC OS X for X86,在MAC系統上雙擊這個檔案就可以解開了;如果想把這個檔案燒錄成DVD,用toast把檔案燒成光碟即可:dmg=》disc image

  命令列建立dmg

自動獲取軟體版本號

APP_NAME=“Soulver”

VERSION=$(/usr/libexec/plistbuddy -c Print:CFBundleShortVersionString: “${APP_NAME}.app/Contents/Info.plist”)

DMG_BACKGROUND_IMG=“Background.png”

VOL_NAME=“${APP_NAME} ${VERSION}”

DMG_TMP=“${VOL_NAME}”

DMG_FINAL=“${VOL_NAME}”

STAGING_DIR=“。/Install”

  建立dmg

# 清理資料夾

rm -rf “${STAGING_DIR}” “${DMG_TMP}” “${DMG_FINAL}”

# 建立資料夾,拷貝,計算

mkdir -p “${STAGING_DIR}”

cp -rpf “${APP_NAME}” “${STAGING_DIR}”

SIZE=`du -sh “${STAGING_DIR}” | sed ‘s/([0-9.]*)M(.*)/1/’`

SIZE=`echo “${SIZE} + 1.0” | bc | awk ‘{print int($1+0.5)}’`

# 容錯處理

if [ $? -ne 0 ]; then

echo “Error: Cannot compute size of staging dir”

exit

fi

# 建立臨時dmg檔案

hdiutil create -srcfolder “${STAGING_DIR}” -volname “${VOL_NAME}” -fs HFS+

-fsargs “-c c=64,a=16,e=16” -format UDRW -size ${SIZE}M “${DMG_TMP}”

echo “Created DMG: ${DMG_TMP}”

  設定dmg

DEVICE=$(hdiutil attach -readwrite -noverify “${DMG_TMP}” |

egrep ‘^/dev/’ | sed 1q | awk ‘{print $1}’)

sleep 2

# 增加Applications目錄的.軟連結

echo “Add link to /Applications”

pushd /Volumes/“${VOL_NAME}”

ln -s /Applications

popd

# 拷貝背景圖片

mkdir /Volumes/“${VOL_NAME}”/ground

cp “${DMG_BACKGROUND_IMG}” /Volumes/“${VOL_NAME}”/ground/

# 使用applescript設定一系列的視窗屬性

echo ‘

tell application “Finder”

tell disk “’${VOL_NAME}‘”

open

set current view of container window to icon view

set toolbar visible of container window to false

set statusbar visible of container window to false

set the bounds of container window to {400, 100, 938, 432}

set viewOptions to the icon view options of container window

set arrangement of viewOptions to not arranged

set icon size of viewOptions to 72

set background picture of viewOptions to file “ground:’${DMG_BACKGROUND_IMG}‘”

set position of item “’${APP_NAME}‘” of container window to {160, 195}

set position of item “Applications” of container window to {360, 195}

close

open

update without registering applications

delay 2

end tell

end tell

’ | osascript

sync

# 解除安裝

hdiutil detach “${DEVICE}”

  壓縮dmg

echo “Creating compressed image”

hdiutil convert “${DMG_TMP}” -format UDZO -imagekey zlib-level=9 -o “${DMG_FINAL}”

# 清理資料夾

rm -rf “${DMG_TMP}”

rm -rf “${STAGING_DIR}”

echo ‘Done.’

exit

上面就是Linux使用命令列建立dmg檔案的方法介紹了,上文對什麼是dmg檔案做了詳細介紹,讓使用者對dmg檔案有更深入的認識。