Programmatically join device to app

I am creating a script that takes care of the our whole device provisioning process at once. One of these steps is joining the device to an application. During normal (non-script) usage, balena join <ip> --application <app> asks for how often the device should check-in with the app, and you provide the answer in minutes (or press enter for the default). In trying to do this with a script, I’ve found that it keeps giving me the error Prompts can not be meaningfully rendered in non-TTY environments whenever I try to provide the answer with the script (or even just on the command line). I’ve tried using yes and piping in input from a file or echo. Is this just not possible currently, or is there a better way of doing it?

Hey,

We would like to learn a bit more,

  • Are you using openBalena or balenaCloud?
  • can you share your script, so we can look into it and possibly point you to better/different methods of doing the provisioning.

We are using balenaCloud.
I put the main provisioning script on Pastebin, as while it’s not super big, it’s still a little too big for a forum post imho. https://pastebin.com/ysV8WUUk
Here is the script that actually runs the balena join command that I’ve been having trouble with. It just seems to hang, and trying out the different methods for supplying input on the command line keeps giving me that error.

#!/bin/bash
#Joins TAGe G2 to balena application and returns uuid

set -euo pipefail

if [[ $# -eq 2 ]] && [[ -n "$1" ]] && [[ -n "$2" ]]
then
    uuid=$( ssh -p 22222 root@$1 'cat /mnt/boot/config.json' | jq -r '.uuid' )
    balena join $1 --application $2
    echo $uuid
else
    echo "Please provide the IP address of the TAGe and the application to join"
    exit 1
fi

I should also mention that we’re using unsupported boards (Odroid-C2s), which is why we have to manually add devices to applications, as opposed to them phoning home as soon as they come online.
Looking at the balena join command with DEBUG=1 prepended to it, the command uses the -n flag with ssh. According to the man page, this

Redirects stdin from /dev/null (actually, prevents reading from stdin).

This may explain the behavior I’m seeing. It also uses the -t flag, which “(f)orces pseudo-terminal allocation”. This is I believe how it shows the prompt for check-in rate.
Sp, I’m not sure if I can get around this.

Hi,

I am not sure, but I think this is a limitation in the input parsing lib in balenaCLI. The best approach here would be to create an issue on the balena-cli repo highlighting the fact that there is no non-interactive mode, or that you cannot pass the poll time via an argument. If that gets picked up by the team, you can monitor it for progress OR if you’re feeling generous then we do welcome PRs :+1:

I have created it here for you: https://github.com/balena-io/balena-cli/issues/1670

1 Like

Thanks! I will look into this.