diff --git a/build/pkg-scripts/postinstall b/build/pkg-scripts/postinstall index e3eedf7..c37baa8 100644 --- a/build/pkg-scripts/postinstall +++ b/build/pkg-scripts/postinstall @@ -1,9 +1,17 @@ #!/bin/sh set -e +# 设置日志文件 +LOG_FILE="/tmp/mihomo-party-install.log" +exec > "$LOG_FILE" 2>&1 + +log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" +} + # 检查 root 权限 if [ "$EUID" -ne 0 ]; then - echo "Please run as root" + log "Error: Please run as root" exit 1 fi @@ -13,63 +21,88 @@ if [[ $2 == *".app" ]]; then else APP_PATH="$2/Mihomo Party.app" fi + HELPER_PATH="/Library/PrivilegedHelperTools/party.mihomo.helper" LAUNCH_DAEMON="/Library/LaunchDaemons/party.mihomo.helper.plist" -# 设置核心文件权限 -chown root:admin "$APP_PATH/Contents/Resources/sidecar/mihomo" -chown root:admin "$APP_PATH/Contents/Resources/sidecar/mihomo-alpha" -chmod +s "$APP_PATH/Contents/Resources/sidecar/mihomo" -chmod +s "$APP_PATH/Contents/Resources/sidecar/mihomo-alpha" +log "Starting installation..." -# 创建目录并复制 helper -mkdir -p /Library/PrivilegedHelperTools -if [ ! -f "$APP_PATH/Contents/Resources/files/party.mihomo.helper" ]; then - echo "Helper file not found" +# 创建目录并设置权限 +log "Creating directories and setting permissions..." +mkdir -p "/Library/PrivilegedHelperTools" +chmod 755 "/Library/PrivilegedHelperTools" +chown root:wheel "/Library/PrivilegedHelperTools" + +# 设置核心文件权限 +log "Setting core file permissions..." +if [ -f "$APP_PATH/Contents/Resources/sidecar/mihomo" ]; then + chown root:admin "$APP_PATH/Contents/Resources/sidecar/mihomo" + chmod +s "$APP_PATH/Contents/Resources/sidecar/mihomo" + log "Set permissions for mihomo" +else + log "Warning: mihomo binary not found at $APP_PATH/Contents/Resources/sidecar/mihomo" +fi + +if [ -f "$APP_PATH/Contents/Resources/sidecar/mihomo-alpha" ]; then + chown root:admin "$APP_PATH/Contents/Resources/sidecar/mihomo-alpha" + chmod +s "$APP_PATH/Contents/Resources/sidecar/mihomo-alpha" + log "Set permissions for mihomo-alpha" +else + log "Warning: mihomo-alpha binary not found at $APP_PATH/Contents/Resources/sidecar/mihomo-alpha" +fi + +# 复制 helper 工具 +log "Installing helper tool..." +if [ -f "$APP_PATH/Contents/Resources/files/party.mihomo.helper" ]; then + cp -f "$APP_PATH/Contents/Resources/files/party.mihomo.helper" "$HELPER_PATH" + chown root:wheel "$HELPER_PATH" + chmod 544 "$HELPER_PATH" + log "Helper tool installed successfully" +else + log "Error: Helper file not found at $APP_PATH/Contents/Resources/files/party.mihomo.helper" exit 1 fi -cp "$APP_PATH/Contents/Resources/files/party.mihomo.helper" "$HELPER_PATH" -chown root:wheel "$HELPER_PATH" -chmod 544 "$HELPER_PATH" - # 创建并配置 LaunchDaemon -mkdir -p /Library/LaunchDaemons +log "Configuring LaunchDaemon..." +mkdir -p "/Library/LaunchDaemons" cat << EOF > "$LAUNCH_DAEMON" - Label - party.mihomo.helper - AssociatedBundleIdentifiers - party.mihomo.app - KeepAlive - - Program - ${HELPER_PATH} - StandardErrorPath - /tmp/party.mihomo.helper.err - StandardOutPath - /tmp/party.mihomo.helper.log - + Label + party.mihomo.helper + AssociatedBundleIdentifiers + party.mihomo.app + KeepAlive + + Program + ${HELPER_PATH} + StandardErrorPath + /tmp/party.mihomo.helper.err + StandardOutPath + /tmp/party.mihomo.helper.log + EOF chown root:wheel "$LAUNCH_DAEMON" chmod 644 "$LAUNCH_DAEMON" +log "LaunchDaemon configured" # 加载并启动服务 -launchctl unload "$LAUNCH_DAEMON" || true +log "Loading and starting service..." +launchctl unload "$LAUNCH_DAEMON" 2>/dev/null || true if ! launchctl load "$LAUNCH_DAEMON"; then - echo "Failed to load helper service" + log "Error: Failed to load helper service" exit 1 fi if ! launchctl start party.mihomo.helper; then - echo "Failed to start helper service" + log "Error: Failed to start helper service" exit 1 fi -echo "Installation completed successfully" +log "Installation completed successfully" exit 0 diff --git a/build/pkg-scripts/preinstall b/build/pkg-scripts/preinstall new file mode 100644 index 0000000..48aaadc --- /dev/null +++ b/build/pkg-scripts/preinstall @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +# 检查 root 权限 +if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit 1 +fi + +HELPER_PATH="/Library/PrivilegedHelperTools/party.mihomo.helper" +LAUNCH_DAEMON="/Library/LaunchDaemons/party.mihomo.helper.plist" + +# 停止并卸载现有的 LaunchDaemon +if [ -f "$LAUNCH_DAEMON" ]; then + launchctl unload "$LAUNCH_DAEMON" 2>/dev/null || true + rm -f "$LAUNCH_DAEMON" +fi + +# 移除 helper 工具 +rm -f "$HELPER_PATH" + +# 清理可能存在的旧版本文件 +rm -rf "/Applications/Mihomo Party.app" +rm -rf "/Applications/Mihomo\\ Party.app" + +exit 0 diff --git a/electron-builder.yml b/electron-builder.yml index 0e136c0..142396b 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -52,6 +52,9 @@ pkg: background: alignment: bottomleft file: build/background.png + preinstallScript: build/pkg-scripts/preinstall + postinstallScript: build/pkg-scripts/postinstall + scripts: "/build/pkg-scripts" linux: desktop: Name: Mihomo Party diff --git a/scripts/cleanup-mac.sh b/scripts/cleanup-mac.sh new file mode 100755 index 0000000..f9c207f --- /dev/null +++ b/scripts/cleanup-mac.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +echo "=== Mihomo Party Cleanup Tool ===" +echo "This script will remove all Mihomo Party related files and services." +read -p "Are you sure you want to continue? (y/N) " -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Aborted." + exit 1 +fi + +# Stop and unload services +echo "Stopping services..." +sudo launchctl unload /Library/LaunchDaemons/party.mihomo.helper.plist 2>/dev/null || true + +# Remove files +echo "Removing files..." +sudo rm -f /Library/LaunchDaemons/party.mihomo.helper.plist +sudo rm -f /Library/PrivilegedHelperTools/party.mihomo.helper +sudo rm -rf "/Applications/Mihomo Party.app" +sudo rm -rf "/Applications/Mihomo\\ Party.app" +sudo rm -rf ~/Library/Application\ Support/mihomo-party +sudo rm -rf ~/Library/Caches/mihomo-party +sudo rm -f ~/Library/Preferences/party.mihomo.app.helper.plist +sudo rm -f ~/Library/Preferences/party.mihomo.app.plist + +echo "Cleanup complete. Please restart your computer to complete the process."