我想以当前用户身份运行该进程。但它是以root身份开始的。如何以当前用户身份启动该过程?
此脚本在 OSX 包的 postinstall 中运行。使用 pkgbuild 打包。
与我如何在 Xcode 中构建命令行工具有任何关系吗?
NAME="myapp"
SCPROXY_INSTALLATION_DIR="/opt/local/bin"
# Script identifier (same as package identifier).
IDENTIFIER="com.mycomp.myapp"
LAUNCH_AGENT_PLIST="/Library/LaunchAgents/$IDENTIFIER.plist"
# Write LaunchDaemon plist file.
echo '<?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">
<plist version="1.0">
<dict>
<key>Label</key>
<string>'$IDENTIFIER'</string>
<key>ProgramArguments</key>
<array>
<string>'$SCPROXY_INSTALLATION_DIR/$NAME'</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/var/log/scproxy.log</string>
<key>StandardErrorPath</key>
<string>/var/log/scproxy.log</string>
<key>Debug</key>
<true/>
</dict>
</plist>' > "$LAUNCH_AGENT_PLIST"
/bin/launchctl unload $LAUNCH_AGENT_PLIST
/bin/launchctl load $LAUNCH_AGENT_PLIST
#exit 0
# Check LaunchDaemon is loaded.
STATUS=`/bin/launchctl list | /usr/bin/grep $IDENTIFIER | /usr/bin/awk '{print $3}'`
if [ "$STATUS" = "$IDENTIFIER" ]
then
echo "Success: LaunchAgent loaded."
exit 0
else
echo "Error: LaunchAgent not loaded."
exit 1
fi