I've got a lengthy and complex bash script which works OK, but I'm trying to automate my deployment process and I'm flummoxed at this point.
I can get the script to run as a LaunchAgent no problem, but of course it happens in the background on boot. So I have a pause at the start of the script where I can press any button if I need to interrupt the script.
The problem with that is I need the script to open in a Terminal window so I can press the button to cancel or continue it. This is where my trouble starts.
The script has many sudo commands. I've created the below
.plist and I can load it manually just fine. It works and loads the script and everything works. However, it does nothing at boot and just exits with error code 1 in Console.
I've tried putting it in
/Library/LaunchDaemons. It basically needs to open the terminal window as root so that all the commands within the script will run as root without the need for me to manually enter the password.
<?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>com.deecies.first</string> <key>ProcessType</key> <string>Interactive</string> <key>ProgramArguments</key> <array> <string>open</string> <string>-a</string> <string>terminal</string> <string>/Users/admin/first-boot.command</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
I tried specifying
/usr/bin/open and the full path to
Terminal.app too, but to no avail. I've tried adding sudo string first and
/usr/bin/sudo but nothing either.
I did manage it to get a Terminal window to open when it was placed in
/Library/LaunchAgents, however it doesn't appear to be opening either Terminal, or the script, as root, as I get "permission denied" for all the commands in the script that would require sudo.