State scripts and user input from terminal

karamanr
Mon, 21 Feb 2022 09:48:51 +0000
General Discussions

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

4 posts - 2 participants