mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
feat: improve installation mechanism
This commit is contained in:
parent
1a1992c617
commit
bdb7fb6489
@ -1,9 +1,17 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
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 权限
|
# 检查 root 权限
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Please run as root"
|
log "Error: Please run as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -13,63 +21,88 @@ if [[ $2 == *".app" ]]; then
|
|||||||
else
|
else
|
||||||
APP_PATH="$2/Mihomo Party.app"
|
APP_PATH="$2/Mihomo Party.app"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HELPER_PATH="/Library/PrivilegedHelperTools/party.mihomo.helper"
|
HELPER_PATH="/Library/PrivilegedHelperTools/party.mihomo.helper"
|
||||||
LAUNCH_DAEMON="/Library/LaunchDaemons/party.mihomo.helper.plist"
|
LAUNCH_DAEMON="/Library/LaunchDaemons/party.mihomo.helper.plist"
|
||||||
|
|
||||||
# 设置核心文件权限
|
log "Starting installation..."
|
||||||
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"
|
|
||||||
|
|
||||||
# 创建目录并复制 helper
|
# 创建目录并设置权限
|
||||||
mkdir -p /Library/PrivilegedHelperTools
|
log "Creating directories and setting permissions..."
|
||||||
if [ ! -f "$APP_PATH/Contents/Resources/files/party.mihomo.helper" ]; then
|
mkdir -p "/Library/PrivilegedHelperTools"
|
||||||
echo "Helper file not found"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp "$APP_PATH/Contents/Resources/files/party.mihomo.helper" "$HELPER_PATH"
|
|
||||||
chown root:wheel "$HELPER_PATH"
|
|
||||||
chmod 544 "$HELPER_PATH"
|
|
||||||
|
|
||||||
# 创建并配置 LaunchDaemon
|
# 创建并配置 LaunchDaemon
|
||||||
mkdir -p /Library/LaunchDaemons
|
log "Configuring LaunchDaemon..."
|
||||||
|
mkdir -p "/Library/LaunchDaemons"
|
||||||
cat << EOF > "$LAUNCH_DAEMON"
|
cat << EOF > "$LAUNCH_DAEMON"
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string>party.mihomo.helper</string>
|
<string>party.mihomo.helper</string>
|
||||||
<key>AssociatedBundleIdentifiers</key>
|
<key>AssociatedBundleIdentifiers</key>
|
||||||
<string>party.mihomo.app</string>
|
<string>party.mihomo.app</string>
|
||||||
<key>KeepAlive</key>
|
<key>KeepAlive</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>Program</key>
|
<key>Program</key>
|
||||||
<string>${HELPER_PATH}</string>
|
<string>${HELPER_PATH}</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>/tmp/party.mihomo.helper.err</string>
|
<string>/tmp/party.mihomo.helper.err</string>
|
||||||
<key>StandardOutPath</key>
|
<key>StandardOutPath</key>
|
||||||
<string>/tmp/party.mihomo.helper.log</string>
|
<string>/tmp/party.mihomo.helper.log</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
chown root:wheel "$LAUNCH_DAEMON"
|
chown root:wheel "$LAUNCH_DAEMON"
|
||||||
chmod 644 "$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
|
if ! launchctl load "$LAUNCH_DAEMON"; then
|
||||||
echo "Failed to load helper service"
|
log "Error: Failed to load helper service"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! launchctl start party.mihomo.helper; then
|
if ! launchctl start party.mihomo.helper; then
|
||||||
echo "Failed to start helper service"
|
log "Error: Failed to start helper service"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Installation completed successfully"
|
log "Installation completed successfully"
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
26
build/pkg-scripts/preinstall
Normal file
26
build/pkg-scripts/preinstall
Normal 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
|
||||||
@ -52,6 +52,9 @@ pkg:
|
|||||||
background:
|
background:
|
||||||
alignment: bottomleft
|
alignment: bottomleft
|
||||||
file: build/background.png
|
file: build/background.png
|
||||||
|
preinstallScript: build/pkg-scripts/preinstall
|
||||||
|
postinstallScript: build/pkg-scripts/postinstall
|
||||||
|
scripts: "/build/pkg-scripts"
|
||||||
linux:
|
linux:
|
||||||
desktop:
|
desktop:
|
||||||
Name: Mihomo Party
|
Name: Mihomo Party
|
||||||
|
|||||||
27
scripts/cleanup-mac.sh
Executable file
27
scripts/cleanup-mac.sh
Executable 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."
|
||||||
Loading…
x
Reference in New Issue
Block a user