MichaIng / DietPi

Lightweight justice for your single-board computer!
https://dietpi.com/
GNU General Public License v2.0
4.7k stars 492 forks source link

xterm-kitty | Automate installation of global terminal definition #6655

Open Voklen opened 9 months ago

Voklen commented 9 months ago

Required Information

Steps to reproduce

  1. Install kitty terminal on your desktop computer
  2. SSH into DietPi through kitty +kitten ssh <user>@<ip>
  3. Run sudo dietpi-update

Expected behaviour

Actual behaviour

 DietPi-Update
─────────────────────────────────────────────────────
 Phase: Checking for available DietPi update

tput: unknown terminal "xterm-kitty"
/boot/dietpi/func/dietpi-globals: line 267: ( 59 + 5 ) /  : syntax error: operand expected (error token is "/  ")

Extra details

I noticed this when I was updating DietPi, so I tried to set export TERM='dumb' but then it didn't come up with the updating UI so I had to get the keyboard out, plug it into a monitor and update it from there. This issue potentially has some relation to #5347, running

/boot/dietpi/func/run_ntpd 1

still gives

/boot/dietpi/func/dietpi-globals: line 267: ( 58 + 5 ) /  : syntax error: operand expected (error token is "/  ")
MichaIng commented 9 months ago

First of all, I think on login, there should be a warning that no matching terminal definition has been found, isn't it? It should even automatically set the TERM variable to xterm, working around the issue. Or do you use another shell than bash?

However, best is anyway to install native xterm-kitty support. Two options:

EDIT: Ah, now I see the issue, as you did use the +kitty flag already. It installs the terminal for the login user only (sure, as it has no permissions to do any different), while dietpi-update runs via sudo as root. Please move the definition to a global place:

sudo mkdir -p /etc/terminfo/x
sudo mv ~/.terminfo/x/xterm-kitty /etc/terminfo/x/
Voklen commented 9 months ago

Ahhh that's interesting and explains why the normal way with +kitty didn't work but installing kitty-terminfo did indeed fix the issue. Thank you very much for the quick response.

MichaIng commented 9 months ago

As you are not the first running into this, let me reopen and think about how we can solve this a clever way automatically with our login scripts.

Voklen commented 9 months ago

There is the option of modifying visudo to preserve TERMINFO with

Defaults env_keep += "TERM TERMINFO"
MichaIng commented 9 months ago

It is preserved, which is the problem, as root does not have this definition in its home dir. It could be explicitly reset/set to xterm, but then the nice kitty terminal features are lost.

If kitty +kitty ssh does not only install but also update the users' terminal definition, I though about a symlink, to have the global one kept in sync:

sudo ls -s "$HOME/.terminfo/x/xterm-kitty" /etc/terminfo/x/xterm-kitty

But I guess every other non-root user would then run into errors, as /<other users' home>/.terminfo/x/xterm-kitty is within a directory they have no read access to. Copying/moving it over means that it won't be updated. Via apt it will get bug fixes and security patches, if needed, from Debian, but feature-wise can be up to 2 years behind. 🤔