简体   繁体   English

如何在Mac OS X 10.6下使用脚本自动执行新系统配置?

[英]How can I automate new system provisioning with scripts under Mac OS X 10.6?

I've been working on this for days but simply cannot find the correct references to make it work. 我已经在这方面工作了好几天,但根本找不到正确的参考来使它工作。

The idea is to have a script that will baseline newly purchased Macs that comes into the company with basic stuffs like set autologin to off, create a new admin user (for remote admins to access for support, set password to unlock screensaver and etc) . 我们的想法是制作一个脚本,用于为进入公司的新购买的Mac提供基本功能,例如将自动设置设置为关闭,创建新的管理员用户(用于远程管理员访问支持,设置密码以解锁屏幕保护程序等)。

Sample list for baseline that admins have to do on each new machine: 管理员必须在每台新计算机上执行的基线示例列表:

  • Click the Login Options button Set Automatic Login: OFF 单击“登录选项”按钮“设置自动登录:关闭”
  • Check: Show the Restart, Sleep, and Shutdown buttons 检查:显示“重新启动”,“睡眠”和“关机”按钮
  • Uncheck: Show input menu in login window 取消选中:在登录窗口中显示输入菜单
  • Uncheck: Show password hints 取消选中:显示密码提示
  • Uncheck: Use voice over in the login window 取消选中:在登录窗口中使用语音
  • Check: Show fast user switching menu as Short Name 检查:将快速用户切换菜单显示为短名称

    (note: this is only part of a long list to do on each machine) (注意:这只是每台机器上长列表的一部分)

I've managed to find some references to make some parts work. 我已经设法找到一些参考来使一些部分工作。 Like autologin can be unset with: 像自动登录一样可以解雇:

defaults write /Library/Preferences/.GlobalPreferences com.apple.userspref.DisableAutoLogin -bool TRUE

and I've kinda found ways to muscle in a new user creation (including prompts) with AppleScript and shell commands. 而且我有点找到了使用AppleScript和shell命令来锻炼新用户(包括提示)的方法。

But generally its tough finding ways to do somewhat simple things like turn on password to get out of screensaver or to allow fast user switching. 但通常很难找到方法来做一些简单的事情,比如打开密码以退出屏幕保护程序或允许快速用户切换。 References are either too limited or just no where to be seen (eg I can unset autologin via cli but the very next setting on the system preference "show restart, sleep and shutdown buttons" is somewhere else and I can't find any command line to make it set) 参考文件要么太有限,要么根本没有看到(例如我可以通过cli取消设置自动登录,但系统首选项“show restart,sleep和shutdown按钮”的下一个设置是在其他地方,我找不到任何命令行使它成立)

Does anyone have any ideas on a list, document, reference or anything of where each setting on the system resides so that I can be pointed to make it work? 有没有人对列表,文档,引用或系统上每个设置所在的位置有任何想法,以便我可以指出它使它工作? or maybe sample scripts for the above example... 或者上面例子的示例脚本......

My thanks for reading thus far—a huge thank you for whoever that has any info on the above. 到目前为止,我对你的阅读表示感谢 - 非常感谢有关上述内容的任何人。

In general, the location of various settings tends not to be documented, but usually isn't too hard to figure out. 一般来说,各种设置的位置往往没有记录,但通常不太难以弄清楚。

One way to do this is to change the setting and watch what file(s) get modified. 一种方法是更改​​设置并查看要修改的文件。 fseventer is good for this, or if you have Xcode installed you can use Packagemaker (start a snapshot package, change the setting, then stop recording and see what files are listed as changed in the snapshot), or just run sudo fs_usage -ew (and sort through its copious output). fseventer对此有好处,或者如果您安装了Xcode,则可以使用Packagemaker(启动快照包,更改设置,然后停止录制并查看快照中列出的文件已更改),或者只运行sudo fs_usage -ew (并通过其丰富的输出进行排序)。

Once you've found the relevant file(s), change the setting back & forth to see how they change. 找到相关文件后,反复更改设置以查看它们的更改方式。 If the files are .plists, you can use defaults to dump them before & after and compare, or use plutil -convert xml1 to switch them from binary into the human-readable XML format, and compare by eye. 如果文件是.plists,您可以使用defaults在之前和之后转储它们并进行比较,或者使用plutil -convert xml1将它们从二进制转换为人类可读的XML格式,并通过眼睛进行比较。 Note that there are sometimes multiple change to make; 请注意,有时会进行多次更改; for example, when disabling autologin, you really should delete the autoLoginUser key from /Library/Preferences/com.apple.loginwindow.plist, and also delete the file /etc/kcpassword. 例如,当禁用自动登录时,您确实应该从/Library/Preferences/com.apple.loginwindow.plist中删除autoLoginUser密钥,并删除文件/ etc / kcpassword。

Another way to find configurable settings is to take advantage of Apple's server-based preference tool, Workgroup Manager. 查找可配置设置的另一种方法是利用Apple的基于服务器的首选项工具Workgroup Manager。 You can install Apple's server admin tools on a non-server, and play around with it locally: 您可以在非服务器上安装Apple的服务器管理工​​具,并在本地使用它:

  • run /Applications/Server/Workgroup Manager.app 运行/ Applications / Server / Workgroup Manager.app
  • when it asks to connect to a server, select the Server > View Directories menu option instead 当它要求连接到服务器时,请选择“服务器”>“查看目录”菜单选项
  • authenticate as an admin (padlock button near top right) 作为管理员进行身份验证(右上角附近的挂锁按钮)
  • select the Computer account list (the rectangle icon in the row of small tabs near the top left) 选择计算机帐户列表(左上角附近的小标签行中的矩形图标)
  • create a dummy computer account (New Computer button in the toolbar) 创建一个虚拟计算机帐户(工具栏中的“新计算机”按钮)
  • swap over to the prefs management section (Preferences button in toolbar) 切换到prefs管理部分(工具栏中的“首选项”按钮)
  • there'll be a bunch of categories of manageable preferences (most of the ones you mentioned would be in the Login section); 会有一堆可管理的偏好(你提到的大多数都会出现在登录部分); make whatever selections you're interested in 做出你感兴趣的任何选择
  • switch to the Details tab and you'll be able to see what preference domain (essentially, the .plist filename) and preference keys are being controlled. 切换到详细信息选项卡,您将能够看到正在控制的首选项域(实质上是.plist文件名)和首选项键。

You can also get additional settings (beyond those in the Overview tab) for applications that include a preference manifest: under Details, click the "+" button, select an application, then open the relevant preference domain and try adding keys to the various sections; 您还可以为包含首选项清单的应用程序获取其他设置(超出“概述”选项卡中的设置):在“详细信息”下,单击“+”按钮,选择一个应用程序,然后打开相关的首选项域并尝试将键添加到各个部分; if the app had a manifest, clicking on the preference key name will give you a pop-up menu of available keys, and selecting one will autofill the value type, default value, and a description of what it does. 如果应用程序有清单,单击首选项键名称将为您提供可用键的弹出菜单,选择一个将自动填充值类型,默认值以及它的作用说明。 The manifest for /System/Library/CoreServices/ManagedClient.app has some really interesting options; /System/Library/CoreServices/ManagedClient.app的清单有一些非常有趣的选项; check it out. 看看这个。

Some settings are per-user, meaning that if you want to apply them to existing accounts, you'll have to script changing /Users/*/Library/Preferences/ whatever , and may also want to edit the user template (/System/Library/User Template/English.lproj/Library/Preferences/ whatever ) so subsequently-created accounts will get the settings. 一些设置是每个用户,这意味着,如果你想将它们应用到现有的帐户,你必须脚本更改/用户/ * /库/首选项/ 什么的 ,可能还需要编辑用户模板(/系统/库/用户模板/ English.lproj / Library / Preferences / whatever )因此随后创建的帐户将获得设置。 Also, some settings are both per-user and per-computer; 此外,一些设置是每用户每台计算机; these get stored in ~/Library/Preferences/ByHost, with a computer ID (either ethernet MAC address or a hardware UUID) in the filename; 这些存储在〜/ Library / Preferences / ByHost中,文件名中包含计算机ID(以太网MAC地址或硬件UUID); use defaults -currentHost to set these. 使用defaults -currentHost来设置它们。

If you're making a bunch of changes to one file (eg the loginwindow prefs), it may be easier to simply copy a pre-tweaked settings file rather than modifying the existing file. 如果您对一个文件(例如loginwindow prefs)进行了大量更改,则可能更容易简单地复制预先调整的设置文件而不是修改现有文件。

For better ways to script account creation, see this serverfault question and/or take a look at the createUser package script included with instadmg . 有关创建脚本帐户的更好方法,请参阅此serverfault问题和/或查看instadmg附带的createUser包脚本。

If you're deploying a lot of similar computers, it might be worth looking into imaging them rather than setting each one up individually. 如果您正在部署许多类似的计算机,那么可能值得研究它们的成像,而不是单独设置它们。 Take a look at Apple's System Image Utility , DeployStudio , and the various discussions & tools at afp548 . 看看苹果的系统映像实用工具DeployStudio ,以及各种讨论和工具在AFP548 There's also an Apple training class on deployment (statement of bias: I'm one of the trainers for this class, so I think everyone should attend it), or you can buy the class reference book separately. 还有一个关于部署Apple培训课程 (偏见声明:我是本课程的培训师之一,所以我认为每个人都应该参加),或者你可以单独购买课程参考书

Edit: I forgot to mention the systemsetup and networksetup commands -- for the settings they cover, they're the best way to go. 编辑:我忘了提及systemsetupnetworksetup命令 - 对于它们所涵盖的设置,它们是最好的方法。

I dont know where to find authoritative docs... perhaps on developer.apple.com or in one of the system admin certification study guides. 我不知道在哪里可以找到权威文档...也许在developer.apple.com或系统管理员认证学习指南之一。 However i can tell you that input menu and password hin are in in the domain /Library/Preferences/com.apple.loginwindow with the keys showInputMenu (boolean - false or no key for off) and retriesUntilHint (integer, >=1 is on, 0 or non-existant is off) respectively. 但是我可以告诉你输入菜单和密码hin在域/Library/Preferences/com.apple.loginwindow ,键为showInputMenu (boolean - false或no key for off)和retriesUntilHint (整数,> = 1开启) ,0或不存在分别是关闭的。

you can always use defaults domain to list all the available defaults domains and then try and reason out which domin you think something would be in. Or you could try defaults find <somestring> but sometimes setting are obscure so just doing a dump of a suspected domain would be easier. 你总是可以使用defaults domain列出所有可用的默认域,然后尝试defaults find <somestring>出你认为会有什么东西。或者你可以尝试defaults find <somestring>但有时设置是模糊的所以只是做一个怀疑的转储域名会更容易。 Ofcourse if the default value is to be tuned off the key wont even exsits most likely... so if you have to use this approach... turn everything on first so the key gets set. 当然,如果要调整默认值,关键字甚至都不会出现...所以如果你必须使用这种方法......首先打开所有内容,这样就可以设置密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM