Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sudo inside of a Run Script build phase in Xcode 4?

I need use execute a command inside of a script in a Run Script build phase in Xcode 4 using sudo. However, the compiler complains:

sudo: no tty present and no askpass program specified

Anyone have a clever solution for this problem?

like image 203
ericg Avatar asked Jul 23 '11 21:07

ericg


1 Answers

One solution is to place the sudo password in an executable shell script like the following:

#!/bin/bash
echo thesudopassword

This shell script might be called password.sh

Then, setup the environment variable SUDO_ASKPASS=password.sh

Once this is setup, the -A option can be passed to sudo. This option uses the ASKPASS program to obtain the sudo password. The ASKPASS program need only write the password to stdout.

So, for example,

sudo -A ditto -V /tmp/testserver.dst /

This is obviously a rather insecure solution, but it does work.

like image 63
ericg Avatar answered Oct 13 '22 01:10

ericg