toolbox/profile.d/toolbox.sh
Debarshi Ray 166b09b822 profile.d: Warn if $TERM has no terminfo entry in the container
It tries to loosely mimic ncurses to look up a terminfo entry for the
current terminal, as mentioned in the terminfo(5) manual. Unlike
ncurses, it doesn't handle TERMINFO_DIRS, though, to avoid parsing an
array of directories for the sake of simplicity.

Every line of code in this file is part of the interactive shell's
start-up sequence, which makes it a trade-off between correctness and
speed. Therefore, the purpose of this warning is not to exhaustively
catch all possible corner cases, but to serve as a convenience in the
majority of cases. Ultimately, if someone is using an exotic terminal
set-up, then a missing warning is a minor price to pay in order to not
slow things down for the vast majority of users who don't.

Based on code written by Mert Alp Taytak:
https://github.com/containers/toolbox/pull/515

https://github.com/containers/toolbox/issues/505
2020-08-28 17:27:49 +02:00

71 lines
2.5 KiB
Bash

[ "$BASH_VERSION" != "" ] || [ "$ZSH_VERSION" != "" ] || return 0
[ "$PS1" != "" ] || return 0
toolbox_config="$HOME/.config/toolbox"
host_welcome_stub="$toolbox_config/host-welcome-shown"
toolbox_welcome_stub="$toolbox_config/toolbox-welcome-shown"
# shellcheck disable=SC1091
. /usr/lib/os-release
if [ -f /run/ostree-booted ] \
&& ! [ -f "$host_welcome_stub" ] \
&& [ "${ID}" = "fedora" ] \
&& { [ "${VARIANT_ID}" = "workstation" ] || [ "${VARIANT_ID}" = "silverblue" ]; }; then
echo ""
echo "Welcome to Fedora Silverblue. This terminal is running on the"
echo "host system. You may want to try out the Toolbox for a directly"
echo "mutable environment that allows package installation with DNF."
echo ""
printf "For more information, see the "
# shellcheck disable=SC1003
printf '\033]8;;https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/\033\\documentation\033]8;;\033\\'
printf ".\n"
echo ""
mkdir -p "$toolbox_config"
touch "$host_welcome_stub"
fi
if [ -f /run/.containerenv ] \
&& [ -f /run/.toolboxenv ]; then
PS1=$(printf "\[\033[35m\]⬢\[\033[0m\]%s" "[\u@\h \W]\\$ ")
if ! [ -f "$toolbox_welcome_stub" ]; then
echo ""
echo "Welcome to the Toolbox; a container where you can install and run"
echo "all your tools."
echo ""
echo " - Use DNF in the usual manner to install command line tools."
echo " - To create a new tools container, run 'toolbox create'."
echo ""
printf "For more information, see the "
# shellcheck disable=SC1003
printf '\033]8;;https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/\033\\documentation\033]8;;\033\\'
printf ".\n"
echo ""
mkdir -p "$toolbox_config"
touch "$toolbox_welcome_stub"
fi
if [ "$TERM" != "" ]; then
error_message="Error: terminfo entry not found for $TERM"
term_without_first_character="${TERM#?}"
term_just_first_character="${TERM%$term_without_first_character}"
terminfo_sub_directory="$term_just_first_character/$TERM"
if [ "$TERMINFO" = "" ]; then
! [ -e "/usr/share/terminfo/$terminfo_sub_directory" ] \
&& ! [ -e "$HOME/.terminfo/$terminfo_sub_directory" ] \
&& echo "$error_message" >&2
else
! [ -e "$TERMINFO/$terminfo_sub_directory" ] \
&& echo "$error_message" >&2
fi
fi
fi
unset toolbox_config
unset host_welcome_stub
unset toolbox_welcome_stub