0

I would like to automate a build - for now, during my development, so no security stuff involved.

I have created a script that moves libs to /usr/local/lib and issues ldd command.

These things require sudo.

Running the script from the builder (Qt Creator), I am not prompted to enter my sudo password, and I get the error

sudo: no tty present and no askpass program specified
Sorry, try again.

I have found a few solutions to this but it just did not work... what am I missing ?

Exact code:

in myLib.pro

#temporary to make my life easier
QMAKE_POST_LINK = /home/me/move_libs_script

in move_libs_script:

#!/bin/bash 
sudo cp $HOME/myLib/myLib.so.1 /usr/local/lib/
sudo ldconfig

I did as suggested by the answer above: edited visudo and added the script... even added qmake...

sudo visudo

added at the end:

me ALL=NOPASSWD: /home/me/move_libs_script, /usr/bin/qmake-qt4

It saved file: /etc/sudoers.tmp (and doing the command sudo visudo again I saw that my changes were kept so I am not sure what is with the tmp)

Still same errors

sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts

Edit: after asking the question I found a suggested similar question: https://stackoverflow.com/a/10668693/1217150

So I tried to add a custom step...

Result:

09:50:03: Running build steps for project myLib...
09:50:03: Could not start process "ssh-askpass Sudo Password | sudo -S bash ./move_libs_script" 
Error while building project myLib (target: Desktop)
When executing build step 'Custom Process Step'

(if I run from terminal I get asked for password)

New edit: so I thought I can outsmart the system and call a script that calls my script...

myLib.pro

QMAKE_POST_LINK = /home/me/sudo_move_libs_script

sudo_move_libs_script:

#!/bin/bash 
ssh-askpass Sudo Password | sudo -S bash $HOME/move_libs_script

got it !!! I will post as answer i guess

New edit as answer to comment:

in mainExe.pro:

QMAKE_POST_LINK = ./link_lib

in link_lib:

#!/bin/sh
LD_LIBRARY_PATH=$HOME/myLib
export LD_LIBRARY_PATH

Result: Executable fails because the lib is not to be found (of course before testing I emoved the copy from /usr/local/lib)

Community
  • 1
  • 1
Thalia
  • 13,637
  • 22
  • 96
  • 190
  • The commands you list in `sudoers` are the ones that can be used with `sudo`. Not the commands/scripts/etc. that will be calling sudo. Do you have the `ssh-askpass` program installed? – Etan Reisner Dec 03 '14 at 17:57
  • Just edited that i tested from terminal and it works from there – Thalia Dec 03 '14 at 17:58
  • The environment of the custom command may not have the `DISPLAY` environment variable set correctly such that it can display a window. – Etan Reisner Dec 03 '14 at 18:11
  • How can I check if that is he case and if yes how can I fix it ? (another workaround I just tried failed) – Thalia Dec 03 '14 at 18:22
  • A custom command of `env` will spit out the environment it has at you. If it doesn't have it you'd just have to set it to the appropriate value. `echo $DISPLAY` in a terminal will tell you. – Etan Reisner Dec 03 '14 at 18:32
  • Typed echo $DISPLAY and got :0 – Thalia Dec 03 '14 at 18:34
  • Why are you installing your library to the system location this frequently? What needs it to be there? – Etan Reisner Dec 03 '14 at 18:39
  • I am modifying the lib... rebuilding and checking ... the linker needs it and since I am running from Qt Creator, I cannot do a temporary path with "export LD_LIBRARY_PATH".... the executable will still not find it when run from Qt Creator, I tried. So this is just to be able to build and change fast without jumping to Terminal to run a script every 5 minutes. I put this in the lib build then run the executable without rebuilding (it is giant) – Thalia Dec 03 '14 at 18:42
  • What executable? `LD_LIBRARY_PATH` should absolutely work if things are set up correctly. Where did you `export LD_LIBRARY_PATH`? – Etan Reisner Dec 03 '14 at 18:44
  • I tried calling it from the pro file of the executable, exporting the lib home directory (where the lib is built) – Thalia Dec 03 '14 at 18:46
  • It would need to be done in the shell session that runs the binary or in a parent shell of the process/session that runs the binary. I have no idea where your entry in the .pro file happens. – Etan Reisner Dec 03 '14 at 18:53
  • Edited question again... When I deploy the executable i run a shell script that sets the path and runs the executable. But when running from Qt Creator... how would I tell Qt Creator to run the script ? – Thalia Dec 03 '14 at 18:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66149/discussion-between-etan-reisner-and-thalia). – Etan Reisner Dec 03 '14 at 19:00

1 Answers1

0

Solution 1:

To run the command I needed with sudo from Qt, and be asked for password

myLib.pro

QMAKE_POST_LINK = /home/me/sudo_move_libs_script

sudo_move_libs_script:

#!/bin/bash 
ssh-askpass Sudo Password | sudo -S bash $HOME/move_libs_script

move_libs_script:

#!/bin/bash 
cp $HOME/myLib/myLib.so.1 /usr/local/lib/
ldconfig

Solution 2

Avoid using sudo: run a custom executable from Qt Creator (just like I would when project is deployed) - I can execute my program with correct dependency. Unfortunately it does not work for debug.

In the Run Configuration, place a script "dummy_executable" instead the app executable:

dummy_executable:

#!/bin/sh
LD_LIBRARY_PATH=$HOME/myLib
export LD_LIBRARY_PATH
$HOME/myExec/myExec "$@

This method is great for running the program ... unfortunately gdb fails... I think it tries to debug the shell script ? So it won't work if I try to step through my program.

Choosing Solution 1, because it has advantages: allows me to build and debug the program, which is what I really need, and with the dependencies set I get the library built before running the program - which is perfect.

Thank you Etan Reisner

Thalia
  • 13,637
  • 22
  • 96
  • 190