通过命令行

时间:2018-08-13 10:14:37

标签: macos plist macos-high-sierra launchctl

概述:

我正在为在教学套件中运行的MacMini套件执行以下操作。

全新安装后(使用Apple远程桌面和bash脚本)

  1. 安装一些应用程序(Chrome,Logic,Imovie)
  2. 创建用户(此示例为u:p个学生/学生)
  3. 向该用户添加家长控制,并限制他们可以使用的应用。
  4. 修改Dock(通过plist文件)以仅显示我们想要的应用,并在每次启动时运行该应用(以阻止学生将其混入下一个用户中)

我有90%的代码都在工作,但是试图让我的plist工作和加载完全陷入困境。

它可以在我的计算机(也为10.13)上运行,并且可以正常加载,可以在同一台Mac上以管理员身份加载。 尝试以用户身份加载它不起作用。

当前过程

  1. 运行以下Bash脚本:

    #! /bin/bash
    
    # Supercedes the above make user , this CANNOT be run as root , so run as the administrator user we added at creation.
    sysadminctl -addUser student -fullName "Bamm Student" -password student -hint student 
    createhomedir -c /Users/student
    
    # Import the parental controls plist
    dscl . -mcximport /Users/student /tmp/parental_controls.plist
    
    # Dock script needs to be copied to the correct location first
    
    # Set the permissions on the dock script
    chmod +x /usr/local/dock.sh 
    chown student:staff /usr/local/dock.sh
    

这部分全部正常工作,我得到一个用户,我得到了主目录,我将停靠脚本复制到了/usr/local(并且当以用户身份从命令行运行时,它可以工作)

  1. 我将我的plist文件复制到位置/Users/student/LaunchAgents/
  2. 确保其归学生所有:staff
  3. 确保它具有644权限
  4. Dock脚本是可执行文件,并由学生用户拥有,可以通过命令行(通过ssh会话)以学生用户身份运行

这是行不通的(我已经尝试了很多方法)

# load the dock launchAgent (run as the student user)

launchctl load /Users/student/Libray/launchAgent/com.mitsuite.login.plist

给予/Users/temp/Library/LaunchAgents/com.mitsuite.login.plist: Operation not permitted

我也尝试过

launchctl bootstrap gui/502 /Users/student/Libray/launchAgent/com.mitsuite.login.plist

给予Could not find domain for

launchctl bootstrap user/502 /Users/student/Libray/launchAgent/com.mitsuite.login.plist

这些给我system.log中的各种错误,主要是这样的:

Aug 10 15:12:59 MIT-1 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100008.Aqua): Caller not allowed to perform action: launchctl.671, action = service bootstrap, code = 1: Operation not permitted, uid = 502, euid = 502, gid = 20, egid = 20, asid = 649

我尝试创建标准用户而不添加任何家长控制(通过管理面板,没有编写脚本的乐趣),并且遇到相同的问题。

我的Plist看起来像这样:

<?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>local.job</string>
        <key>Program</key>
        <string>/usr/local/dock.sh</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

更新:

作为测试,我在同一台计算机上创建了一个admin用户,并运行了该命令,所有操作都能很好地加载plist并在启动时运行。

如何让标准用户通过命令行安装plist?

更新2:

关于另一个Stackoverflow问题,我已经将用户名添加到.plist文件中,然后将其放在/ Library / LaunchDaemons中,当root运行launchctl load /Library/LaunchDaemons/com.mitquite.login.plist时,所有这些都可以使用

但是,这似乎很不直观(除非其意图是因为标准用户无法安装应用程序?)

1 个答案:

答案 0 :(得分:1)

我会尝试做两件事:

  • 要将<string><key>Label</key>字段中的值更改为com.mitsuite.login而不是local.job
  • 或添加到.plist(至少前两行):

    <key>UserName</key>
    <string>/*name_of_user*/</string>
    <key>GroupName</key>
    <string>/*group_name*/</string>
    <key>InitGroups</key>
    <true/>