#2124 Issue closed: Inconsistent TERM values in skel scripts

Labels: cleanup, discuss / RFC, no-issue-activity

jsmeix opened issue at 2019-04-26 09:22:

For background information see
https://github.com/rear/rear/issues/1282#issuecomment-486988867

The scripts in the usr/share/rear/skel directory are those
that are run during ReaR recovery system startup phase.

In our current GitHub master code in those scripts I found

# find usr/share/rear/skel -type f | xargs grep 'TERM='

usr/share/rear/skel/default/etc/profile:
export TERM=ansi

usr/share/rear/skel/default/usr/lib/systemd/system/serial-getty@.service:
Environment=TERM=vt100

usr/share/rear/skel/default/usr/lib/systemd/system/getty@.service:
Environment=TERM=linux

The different TERM values that are set here
indicate that something at least looks inconsistent
regarding the TERM value in our ReaR recovery system.

@rear/contributors
does someone of you know if the different TERM values
that are set during ReaR recovery system startup are intentional
or is that something that should be cleaned up to one same value?

github-actions commented at 2020-06-30 01:33:

Stale issue message

github-actions commented at 2021-04-26 02:35:

Stale issue message

dcz01 commented at 2021-04-28 11:02:

@jsmeix When will this little bug be solved finally?

jsmeix commented at 2021-05-05 08:18:

I cannot do anything here only on my own because I don't know anything
about the (possibly subtle) differences of TERM values like

TERM=ansi
TERM=vt100
TERM=linux
TERM=dumb

If someone who is an expert in TERM values can tell what
"the one and only right TERM value" is that makes "all work everywhere"
we could "just set" this right TERM value everywhere in ReaR.

I fear we need a TERM value where ANSI escape sequences are supported
because we use ANSI escape sequences by default in lib/progresssubsystem.nosh
https://github.com/rear/rear/blob/master/usr/share/rear/lib/progresssubsystem.nosh

FWIW:
Personally I always use

PROGRESS_MODE="plain"
PROGRESS_WAIT_SECONDS="3"

in my etc/rear/local.conf because I prefer simple plain ASCII messages (KISS).

OliverO2 commented at 2021-05-05 16:44:

There is no way have a single correct TERM value:

  • For a (virtual) console login, which uses the machine's integrated graphics unit, the Linux kernel manages text output, interpreting escape sequences. In these cases, TERM=linux seems to be correct.
  • For a serial login, TERM must be set per connection or chosen by the user at login time. There is no way of knowing which kind of physical terminal or emulator is attached, although ansi might be the most common one these days.
  • For a GUI, its terminal application determines the correct TERM setting (typically, something like xterm*).
  • For a remote connection (ssh or other), the client side determines the terminal type, so it can be any of the above.

So the answer is:

  • For (virtual) console logins, set TERM=linux, which is done correctly in usr/share/rear/skel/default/usr/lib/systemd/system/getty@.service.
  • For all other purposes, do not touch the TERM value as this would break remote connections. If needed, the user could set a TERM value manually.
  • Otherwise, a wrong TERM setting might garble the screen. In the worst case it could render the terminal completely unusable: Escape sequences might switch fonts, colors (say "black on black"), alter the devices settings, ...

The proper solution in this case would probably be:

  • Remove the TERM setting in usr/share/rear/skel/default/usr/lib/systemd/system/serial-getty@.service.
  • Change the fixed setting in /etc/profile. For serial logins, a prompt might ask the user if she would like a TERM=ansi setting (possibly the most common now with people using terminal emulators over serial lines). So the setting in usr/share/rear/skel/default/etc/profile might become something like: # Offer a default TERM setting for login shells where TERM is not set if [[ $- == i && -z "$TERM" ]]; then while true; do echo "" read -r -p "Set 'TERM=ansi' (y/n)? " answer echo ""
            if [[ "$answer" == [yY] ]]; then
                export TERM=ansi
                break
            elif [[ "$answer" == [nN] ]]; then
                break
            else
                echo "Please answer 'y' or 'n'." >&2
            fi
        done
    fi
    

For a comparison of terminal attributes showing just the differences, use:

infocmp -dL ansi vt100 | less

See the terminfo(5) manual page for explanations. A single attribute difference between ansi and vt100 looks like:

    cursor_address: '\E[%i%p1%d;%p2%dH', '\E[%i%p1%d;%p2%dH$<5>'.

The difference here is an extra $<5> on the vt100 side. This is just a delay instruction (5 milliseconds). Since you'd probably have a hard time getting your hands on a real VT100 or other terminal hardware these days, delays no longer matter. On today's emulators, both entries are actually equivalent.

github-actions commented at 2021-07-05 02:08:

Stale issue message


[Export of Github issue for rear/rear.]