-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The sh file is not excuted #31
Comments
Perhaps create a really simple bash script and try that first? eg #!/bin/bash
echo Hello World
# or perhaps
touch ~/Desktop/helloworld Just to rule out that angle. |
I tried this just now, the simple bash script also cannot execute. |
Hi, I got very same issue above. Have you gotten any solution on this @huizhenhe-dev ? Thanks, |
The command to be executed has to be a Mach-O executable binary, not a shell script. To run a shell script you'd use the path of the shell (ie. Also the path you enter in the dialog box is the path being passed to the Remember the code provided in this project is intended to show how to call a privileged helper tool. It's expected that you'd modify the code for the command(s) you want to run. For security reasons it would be better to implement the functionality you want to execute in Swift code rather than call out to a shell script. That code would go in the helper. Ideally you'd use Cocoa or BSD API rather than system commands, but if you do need system command line tools, call exactly the binaries you need and try to avoid shell scripts. |
When I wrote my previous reply I was on my phone, and it wasn't convenient to look at the source code. Now that I can, I want to follow up. Using the code as it exists in this repo, if you enter /bin/ls /path/to/your/shell/script.sh Which matches the output you show, but because of what I believe to be a misunderstanding about what the app is intended to do, it's not what you're expecting. You're expecting for your shell script to be executed. To do that you have to replace the In To run a shell script, after setting command to You'll also need to update the It's not required for the helper tool to call out to an external program. In fact, it's more secure, and more performant, to implement whatever functionality you want in the helper tool directly in Swift code. Being in the helper tool let's you make Cocoa/BSD calls the main app wouldn't have permissions for. Basically you'd replace the contents of |
Thank you for your excellence answer. I'm aware of using sh file can be a security issue. However i need to execute several chflags command and still not find any api to support it.
Appreciate your help! |
@chipjarred one more question: How can I show the password popup only once, even if I quit the app and run it again? I'm asking because I'm building a background application and I need to ask for the root password only during the installation process. |
I'm pretty sure you can set file flags with Foundation's #include <sys/stat.h>
#include <unistd.h>
int chflags(const char *path, u_int flags); Which would translate to Swift as: import Darwin
func chflags(_ path: UnsafePointer<Int8>, _ flags: UInt32) -> Int32 In Terminal, you can get the man 2 chflags I'm guessing when you were looking for the API, you probably left out the section number, which would give you the Anyway, I'd wrap the call to As for your other question, I'm not sure if it will work to save an authorization from one execution to another, so I'd have to experiment with it. In the second version of |
You may find Apple's old docs on Authorization Services helpful: Authorization Services Programming Guide |
Thanks @chipjarred for your quick response. I will give a try with Keychain first, appreciated it! |
Hi @chipjarred , sorry for bothering you so much. I have one more question: how can we cache the helper installation request? |
It shouldn't need to re-install the helper for each restart - only when you need to update the helper tool . If I recall correctly, |
Thanks @chipjarred . I tried to check status of helper but its always show me an error:
The error comes from calling
I also check in |
Update: i check |
If you get that error, it should mean the helper isn't installed. If it is installing it, I don't know why it would be unloading it. You probably already figured this out, but the actual helper tool binary is installed in Since you reference // -------------------------------------
func helper(_ completion: ((Bool) -> Void)?) -> HelperProtocol?
{
/*
Get the current helper connection and return the remote object
(Helper.swift) as a proxy object to call functions on.
*/
func localErrorHandler(_ error: Error)
{
self.log(
stdErr: "Helper connection was closed with error: \(error)"
)
if let onCompletion = completion {
onCompletion(false)
}
}
return self.helperConnection()?.remoteObjectProxyWithErrorHandler(
localErrorHandler
) as? HelperProtocol
} Note that it calls the helperStatus { installed in
if !installed {
self.install()
}
} Does this help? |
Thanks @chipjarred , you're right, I'm using your folk and having exactly your above code. I'm always getting Here's steps to reproduce:
I'm not quite sure why their status is unloaded. My goal is to install the helper just once. |
Using my fork, it works. These are the steps I took:
Just to verify, after restart, in Xcode I put a breakpoint in the To be fair, for the time being I'm stuck on Big Sur, and there is some possibility that some Launch Services behavior may have changed since, but I think it's unlikely. At what point in the app's life cycle are you calling |
@chipjarred I checked the application in macOS Big Sur 11.5.2, it's working now! so i think problem is probably macOS version. |
That's good to know. I wonder if the change was in Ventura or in Monterey. I would hope that Apple provides a way to make it work, but it will require some investigation to find out how. If I come across something I will let you know. If you find a solution, please share it here. |
It looks like Ventura added a new Service Management API, SMAppService, and deprecated |
Thanks @chipjarred. Appreciated it! |
Hi, I build the project, then input path "/tmp/generatePb_swift.sh", then click "Run Command", there is log here "Command exit code: 0". But the sh file is not executed. I see "com.github.erikberglund.SwiftPrivilegedHelper" installed in /Library/PrivilegedHelperTools.
The text was updated successfully, but these errors were encountered: