Looking for help to finish a master setup for macOS system



as an Apple administrator, I wrote a complete shell to install and set a complete macOS system on new computers. I've a 250 systems park to drive.

Using shell bash, I use some commands as :

  • "scutil", "networksetup", "systemsetup" or "dsconfigad" to preset Network capabilities,
  • "dscl" to create account
  • and also install lot of softwares using "hdiutil", "installer" and "rm" or "cp" for files.

My shell program is build as a modern code with a main process and a lot of functions.

I design with xCode a new application with menus and something more pretty than Terminal. All is ready, only each piece of menu items need to be compose.

I can't find or understand how to replace those above shell functions with Swift functions.

I will be very happy to find with your help some pieces of code to do that.

(Ben D. Jones) #2

We I can give a more detailed answer tomorrow but you could use Process to call parts of your script as needed from a UI for example.


Can you give me a bit more on what you mean? Do you want to interact with the scripts with a swift app or UI? That’s what I assume by your comment.

(Quinn “The Eskimo!”) #3

I can't find or understand how to replace those above shell functions
with Swift functions.

This isn’t an easy question to answer because it touches on a number of tricky issues:

  • Privilege escalation — Most of these operations require privileges, but a macOS GUI app runs without privileges. The standard way to resolve this paradox is to split your code into an app and a privileged helper tool (as shown by the EvenBetterAuthorizationSample sample code) but this is hard to do correctly.
  • Lack of APIs — Some of these tools can do things that are simply not possible via public APIs. For example, there’s no API equivalent to the installer tool. In this case your only option is to run the tool from your app (using Process). That’s less than ideal, because tools are not APIs.

  • Unsupported techniques — Other tools have an equivalent API, but you’re using them in a way that’s not supported via that API. For example, dscl is mostly a wrapper around the OpenDirectory framework [1] and you can use that API to do pretty much whatever you can do with the tool. However, your high-level goal, creating a new account, is not just about setting up the directory record, you also have to set up the user’s home directory, and there’s no public API for that.

The devil really is in the details here, and those details are definitely off topic for Swift Forums. My recommendations are:

  • Hop over to DevForums. There’s a bunch of topic areas appropriate for your questions over there [2].

  • Analyse your requirements and come up with a list of specific tasks.

  • For each of those tasks, create a new thread in the appropriate topic area. Make sure to include the details about what you’re trying to do. For example, the networksetup tool has lots of different subcommands, and the correct API to use depends on exactly which subcommand you’re using.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] Actually, it uses the legacy DirectoryService framework, but the OD framework is much nicer.

[2] Including:

1 Like

Hi eskimo and bendjones,

I know that what I want to do is concerning privileges.
I must use "sudo" prior to launch my 1505 lines shell and act as a root operator. This shell doesn't reside on system I build but on an external protected disk with all install kits and files.
We are only two persons using this disk and are the only ones that knows firmware and admin password (except our manager) and have an ethernet adapter for AD binding.

I beleived that all API that exists as shell command where also translate inside Swift.

I will learn how to send shell command from Swift and retrieve results. I'll rewrite only in Swift code the main body of the shell file (looking for package, testing values for choices, asking value as username, password, etc...)

Thanks for you time, I'll check the docs you mentionned.