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

后端 未结 7 1896
梦谈多话
梦谈多话 2021-02-02 14:47

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 a

7条回答
  •  别那么骄傲
    2021-02-02 15:01

    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.

提交回复
热议问题