erikberglund / SwiftPrivilegedHelper

Example application using a privileged helper tool with authentication in an unsandboxed application written in Swift
MIT License
180 stars 33 forks source link

Upgraded project to Xcode 11 and Swift 5. More significantly replace… #27

Closed chipjarred closed 3 years ago

chipjarred commented 3 years ago

…d CodeSignUpdate.sh with CodeSignUpdate.swift (intended to be run as a script during the Run Script phase, not actually compiled). It does the same job, but since it doesn't need to redirect I/O to build strings, it is can actually produce useful error message that show up in the build log. The shell script did produce some error messages, but they were never displayed because stdout was redirected to shell variable string content. It adds some additional checks too. It removes hardcoding of bundle IDs in the script. They are now provided by preceding the call to swift CodeSignUpdate.swift in the RunScript phase with export commands that set shell variables, MAIN_BUNDLE_ID, and HELPER_BUNDLE_ID.

chipjarred commented 3 years ago

I'm sorry for such a large pull request. I should have broken it up into two parts. One for the migration to Swift 5, and the other for the new CodeSignUpdate script written in Swift.

I found the project very helpful, so I wanted to give back. Your shell script in the Run Script phase is much better than manually running SMJobBlessUtil.py, but when there are errors, it only gives "Shell script terminated with exit code 1", because the script is using stdout to build strings. I took your shell script as a base, and implemented the same functionality in Swift, which doesn't have to redirect I/O to build strings. It also allowed me to do some extra checking and validation. I've added a README file for the Scripts folder to explain.

Of course since it's intended to run as part of the build process, CodeSignUpdate is run as a script rather than compiling it normally.

I did not intend to commit the changes that the script applies automatically to the plists when I built it. They should be replaced by anyone who builds it anyway, but, those files don't need to be updated in the repo.