Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent TERM values in skel scripts #2124

Closed
jsmeix opened this issue Apr 26, 2019 · 6 comments
Closed

Inconsistent TERM values in skel scripts #2124

jsmeix opened this issue Apr 26, 2019 · 6 comments

Comments

@jsmeix
Copy link
Member

jsmeix commented Apr 26, 2019

For background information see
#1282 (comment)

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?

@jsmeix jsmeix added this to the ReaR v2.6 milestone Apr 26, 2019
@jsmeix jsmeix self-assigned this Apr 26, 2019
@jsmeix jsmeix modified the milestones: ReaR v2.6, ReaR v2.7 Apr 29, 2020
@github-actions
Copy link

Stale issue message

@github-actions
Copy link

Stale issue message

@dcz01
Copy link

dcz01 commented Apr 28, 2021

@jsmeix When will this little bug be solved finally?

@jsmeix
Copy link
Member Author

jsmeix commented May 5, 2021

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
Copy link
Contributor

OliverO2 commented May 5, 2021

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
Copy link

github-actions bot commented Jul 5, 2021

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants