feat: improve installation mechanism

This commit is contained in:
ezequielnick 2025-05-30 10:11:13 +08:00
parent 1a1992c617
commit bdb7fb6489
4 changed files with 121 additions and 32 deletions

View File

@ -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,28 +21,51 @@ 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"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@ -52,24 +83,26 @@ cat << EOF > "$LAUNCH_DAEMON"
<string>/tmp/party.mihomo.helper.err</string>
<key>StandardOutPath</key>
<string>/tmp/party.mihomo.helper.log</string>
</dict>
</dict>
</plist>
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

View File

@ -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

View File

@ -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

27
scripts/cleanup-mac.sh Executable file
View File

@ -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."