Files
karuo-ai/01_卡资(金)/金仓_存储备份/脚本/karuo_sudo_setup.sh
2026-07-19 00:21:46 +08:00

30 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 一次性:把 Mac 登录密码写入登录钥匙串,以后 Agent 静默 sudo不再弹 osascript 管理员窗)
set -euo pipefail
SERVICE="karuo-mac-admin"
ACCOUNT="${USER}"
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
pass="$(osascript <<'APPLESCRIPT'
try
set d to display dialog "卡若AI 一次性配置:将 Mac 登录密码存入本机钥匙串。" & return & return & "保存后 Agent 执行 tmutil/NAS 等将自动 sudo不再弹出「osascript 想要进行更改」。" default answer "" with hidden answer with title "卡若AI · 静默 sudo" buttons {"取消", "保存并验证"} default button "保存并验证"
return text returned of d
on error errMsg number errNum
if errNum is -128 then error number -128
error errMsg number errNum
end try
APPLESCRIPT
)" || exit 128
[ -n "$pass" ] || { echo "❌ 密码为空"; exit 1; }
if security find-generic-password -a "$ACCOUNT" -s "$SERVICE" >/dev/null 2>&1; then
security delete-generic-password -a "$ACCOUNT" -s "$SERVICE" >/dev/null 2>&1 || true
fi
security add-generic-password -a "$ACCOUNT" -s "$SERVICE" -w "$pass" -l "卡若AI Mac 管理员Agent 静默 sudo" >/dev/null
printf '%s\n' "$pass" | sudo -S -p '' true
echo "✅ 钥匙串已写入 · sudo 验证通过"
echo " 以后 Agent 调用: bash ${SELF_DIR}/karuo_sudo.sh …"