cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gwesterfieldjr
Level 3

execute sudo commands from shell script

Hello,

I'm creating an installer for Mac OS X and I'm having huge issues trying to execute sudo commands. I have the installer checked for "Requires an Administrator Name and Password to Install" but the installer is still failing to execute sudo commands from a bash script that i create in a custom code action and deploy to be executed. The bash script has looks like this ....

#!/bin/bash

#Install XCode Command Line Utilities
cd "/usr/local/bin/AppWrapping/XCode"
hdiutil mount xcode452cltools10_86938211a.dmg
sudo installer -pkg "/Volumes/Command Line Tools (Mountain Lion)/Command Line Tools (Mountain Lion).mpkg" -target /
hdiutil eject "/Volumes/Command Line Tools (Mountain Lion)"

The script is running and mounting the dmg file. then when it trys to run the sudo installer -pkg line i get this error "no tty present and no askpass program specified"

please help...
Labels (1)
0 Kudos
(1) Reply
pv7721
Level 20

I think that it'll be easier to run a custom code that would check if the installer is run by root and it would abort the installation if it's not the case. Using sudo is tricky, and I think that you need several prerequisite: the user running the installer must be in the sudoers group AND sudo should work without prompting for a password (most likely this is what happens in your case, the installer waits for the script which expects you to enter your password when executing the sudo command).
0 Kudos