#!/bin/sh set -e # 检查 root 权限 if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit 1 fi # 判断 $2 是否以 .app 结尾 if [[ $2 == *".app" ]]; then APP_PATH="$2" 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" # 创建目录并复制 helper mkdir -p /Library/PrivilegedHelperTools if [ ! -f "$APP_PATH/Contents/Resources/files/party.mihomo.helper" ]; then echo "Helper file not found" 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 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 EOF chown root:wheel "$LAUNCH_DAEMON" chmod 644 "$LAUNCH_DAEMON" # 加载并启动服务 launchctl unload "$LAUNCH_DAEMON" || true if ! launchctl load "$LAUNCH_DAEMON"; then echo "Failed to load helper service" exit 1 fi if ! launchctl start party.mihomo.helper; then echo "Failed to start helper service" exit 1 fi echo "Installation completed successfully" exit 0