Search code examples
xcodebuildxcode4sudo

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?


Solution

  • 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.