You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
wormhole-client/scripts/create-dmg.sh

152 lines
4.3 KiB

#!/bin/bash
set -e
# 项目信息
APP_NAME="Wormhole Client"
VERSION="v1.0.0"
# 路径配置
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BUILD_DIR="$PROJECT_ROOT/build"
APP_DIR="$BUILD_DIR/$APP_NAME.app"
DMG_DIR="$BUILD_DIR/dmg"
TEMP_DMG="$BUILD_DIR/temp.dmg"
FINAL_DMG="$BUILD_DIR/Wormhole-Client-$VERSION.dmg"
# DMG 配置
DMG_TITLE="Wormhole Client $VERSION"
DMG_SIZE="100m"
DMG_BACKGROUND="$PROJECT_ROOT/scripts/dmg-background.png"
DMG_ICON_SIZE=128
DMG_TEXT_SIZE=16
echo "📦 Creating DMG installer for Wormhole Client..."
# 检查应用程序包是否存在
if [ ! -d "$APP_DIR" ]; then
echo "❌ Application bundle not found. Please run build-macos.sh first."
exit 1
fi
# 清理并创建 DMG 目录
echo "🧹 Preparing DMG directory..."
rm -rf "$DMG_DIR"
mkdir -p "$DMG_DIR"
# 复制应用程序到 DMG 目录
echo "📱 Copying application to DMG..."
cp -R "$APP_DIR" "$DMG_DIR/"
# 创建 Applications 符号链接
echo "🔗 Creating Applications symlink..."
ln -s "/Applications" "$DMG_DIR/Applications"
# 创建 README 文件
echo "📝 Creating README..."
cat > "$DMG_DIR/README.txt" << EOF
Wormhole SOCKS5 Client $VERSION
安装说明:
1. 将 "Wormhole Client.app" 拖拽到 Applications 文件夹
2. 双击运行应用程序
3. 首次运行时,可能需要在系统偏好设置中允许运行
使用方法:
- HTTP 模式:./wormhole-client -mode http
- 全局模式:sudo ./wormhole-client -mode global (需要管理员权限)
Web 管理界面:http://127.0.0.1:8080/gui
统计信息:http://127.0.0.1:8080/stats
更多信息请访问:https://github.com/azoic/wormhole-client
Copyright © 2024 Azoic. All rights reserved.
EOF
# 创建临时 DMG
echo "💿 Creating temporary DMG..."
hdiutil create -srcfolder "$DMG_DIR" -volname "$DMG_TITLE" -fs HFS+ \
-fsargs "-c c=64,a=16,e=16" -format UDRW -size "$DMG_SIZE" "$TEMP_DMG"
# 挂载临时 DMG 进行自定义
echo "🎨 Customizing DMG appearance..."
DEVICE=$(hdiutil attach -readwrite -noverify -noautoopen "$TEMP_DMG" | \
egrep '^/dev/' | sed 1q | awk '{print $1}')
# 等待挂载完成
sleep 2
# 设置 DMG 窗口属性
MOUNT_DIR="/Volumes/$DMG_TITLE"
# 使用 AppleScript 设置 Finder 窗口
/usr/bin/osascript << EOF
tell application "Finder"
tell disk "$DMG_TITLE"
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, 920, 440}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to $DMG_ICON_SIZE
set text size of theViewOptions to $DMG_TEXT_SIZE
-- 设置图标位置
set position of item "Wormhole Client.app" of container window to {140, 120}
set position of item "Applications" of container window to {380, 120}
set position of item "README.txt" of container window to {260, 280}
-- 应用更改
update without registering applications
delay 2
end tell
end tell
EOF
# 等待 AppleScript 完成
sleep 3
# 卸载临时 DMG
hdiutil detach "$DEVICE"
# 创建最终的只读 DMG
echo "✨ Creating final DMG..."
rm -f "$FINAL_DMG"
hdiutil convert "$TEMP_DMG" -format UDZO -imagekey zlib-level=9 -o "$FINAL_DMG"
# 清理临时文件
echo "🧹 Cleaning up..."
rm -f "$TEMP_DMG"
rm -rf "$DMG_DIR"
# 显示结果
echo ""
echo "🎉 DMG creation completed successfully!"
echo "📁 DMG file: $FINAL_DMG"
echo "📊 File size: $(du -h "$FINAL_DMG" | cut -f1)"
echo ""
echo "✅ Installation package ready for distribution!"
# 验证 DMG
echo "🔍 Verifying DMG integrity..."
if hdiutil verify "$FINAL_DMG"; then
echo "✅ DMG verification passed"
else
echo "❌ DMG verification failed"
exit 1
fi
# 显示安装说明
echo ""
echo "📋 Installation Instructions:"
echo "1. Double-click the DMG file to mount it"
echo "2. Drag 'Wormhole Client.app' to the Applications folder"
echo "3. Eject the DMG"
echo "4. Launch 'Wormhole Client' from Applications"
echo ""
echo "🔒 Security Note:"
echo "If macOS blocks the app, go to System Preferences > Security & Privacy"
echo "and click 'Open Anyway' to allow the application to run."