-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Problem
Running sudo mailinabox via SSH without a PTY (e.g., from automation scripts, paramiko, Ansible, or cron) fails with:
Error opening terminal: unknown
This happens because dialog (ncurses) is called in setup/questions.sh when NONINTERACTIVE is not set, and dialog requires a terminal.
Workaround: Setting NONINTERACTIVE=1 sudo mailinabox works, but this is not documented and not intuitive — especially for reconfiguration scenarios where all settings are already in the env file.
Expected Behavior
When running sudo mailinabox without a terminal attached (no PTY), the script should automatically detect this and either:
- Set
NONINTERACTIVE=1automatically, or - Print a helpful error message suggesting
NONINTERACTIVE=1
Proposed Fix
In setup/questions.sh, add terminal detection at the top:
# Auto-detect headless mode when no terminal is available
if [ -z "${NONINTERACTIVE:-}" ] && ! [ -t 0 ]; then
# No terminal attached (SSH without PTY, cron, pipe, automation)
# dialog can't work without a terminal, so auto-set NONINTERACTIVE
export NONINTERACTIVE=1
echo "Notice: No terminal detected, running in non-interactive mode."
echo "To force interactive mode, run with: script -qc 'sudo mailinabox' /dev/null"
fi[ -t 0 ] checks if stdin is a terminal. If not (SSH without PTY, cron job, pipe), it automatically enables non-interactive mode and prints a notice.
Use Case
This is especially relevant for:
- Automation: Ansible, Puppet, scripts managing MiaB remotely
- IP migration: When changing
PUBLIC_IPinmailinabox.envand re-runningsudo mailinaboxvia SSH automation - CI/CD: Automated testing or deployment pipelines
Environment
- Mail-in-a-Box v74
- Ubuntu 22.04.5 LTS
- Running via Python paramiko SSH (no PTY allocated)