Hi,
I’ve been testing a Download_Leave state script that’s supposed to take input from the terminal, however when it’s called with Mender it doesn’t work as intended. The script works fine when executed from terminal, but when called from mender it skips the part where it has to read the input from terminal. For now I’ve made it work by passing the input from a text file, however it’s not the ideal solution for testing.
#!/bin/bash
RETRY_LATER=21
OK=0
userConfirm() {
while true; do
read -p "Do you wish to install this program?" yn
case $yn in
[Yy]* ) exit ${OK};;
[Nn]* ) echo $yn
exit ${RETRY_LATER};;
* ) echo "Please answer yes or no.";;
esac
done
}
userConfirm </etc/mender/scripts/no.txt>&2
Hello @karamanr!
The update scripts are not attached to a TTY, just like cronjob, or a systemd unit. So you will need some form of workaround, or strategy change. The simplest one is obviously reading from a file as you already worked out. An alternative might be having a process that does the interaction with the terminal, and provides some form of IPC that your script can connect, like dbus, some socket… there are many possibilities. In the end it all depends on your use case.
Greetz,
Josef
Thanks for the quick response!
I see, this script is just for testing, I’ll probably switch to something different (python script that asks user from a GUI perhaps).
Another quick question, is there a way to avoid the automatic update check when Mender starts from boot. My device will probably need to be shut down after every use and it’ll be a bit annoying to ask the user if he wants to check for updates every time, assuming I’m using a state script.
Hi @karamanr
Well the python script will see the same problem if run in that context. If a process is not attached to a tty, it can’t do terminal interaction, no matter what language it is implemented in.
For the other question, do you mean the check should not even be started? Or just the script not ask the user? In that case, you could give the script a simple uptime check, or touch a file in /tmp upon first run, and only proceed if the file already exists.
Greetz
Josef