Commit graph

21 commits

Author SHA1 Message Date
Debarshi Ray
0212ce0db9 build: Tweak the names of the ShellCheck tests
https://github.com/containers/toolbox/pull/1120
2022-09-09 17:16:25 +02:00
Debarshi Ray
e6c0c00d79 build: Disambiguate the 'toolbox' file and target
Fallout from 6c0b045e1a

https://github.com/containers/toolbox/pull/1120
2022-09-09 17:13:31 +02:00
Debarshi Ray
61efad34bc profile.d: Fix the PS1 on Z shell
Currently, on Fedora, a nested instance of Z shell inside a Toolbox
container renders the PS1 like this:
\[\]⬢\[\][\u@\h \W]\$

Notice that Z shell doesn't like that the terminal escape sequences
for the foreground colour are wrapped in '\[' and '\]' [1], and doesn't
understand the special characters like '\u' and '\h'.

This is fixed by making the PS1 specific to the shell. The prompt for
Z shell is based on the default prompt used on Fedora, just like the
one for Bash.

Note that this only affects nested instances of Z shell because of the
way the start-up scripts for Z shell are written on Fedora. Toolbox
invokes top-level shell as a login shell, and for those the PS1 set by
profile.d/toolbox.sh is overwritten by the operating system's default
in /etc/zshrc. See:
https://bugzilla.redhat.com/show_bug.cgi?id=2026749

[1] Commit bc1a816ea3
    https://github.com/debarshiray/toolbox/issues/190

https://github.com/containers/toolbox/pull/936
2021-11-25 19:04:20 +01:00
Debarshi Ray
95dbb5ed49 profile.d: Avoid warnings for undefined variables with 'set -u'
See:
https://gitlab.gnome.org/GNOME/vte/-/issues/285
https://gitlab.gnome.org/GNOME/vte/-/commit/e148105691926cbd

https://github.com/containers/toolbox/pull/936
2021-11-25 18:10:43 +01:00
kuba3351
3641a0032f profile.d: Show welcome message on Fedora Kinoite
SC3059 shellcheck rule could be disabled,
because we reqiure bash or zsh to run the welcome script,
so case modification will work.

https://github.com/containers/toolbox/pull/881
2021-11-08 18:06:05 +02:00
Ondřej Míchal
a24c2f6dc1 test/system: Bump secondary fedora image from 29 to 32
The fedora-toolbox:32 image is the first of images in the renamed
toolbox image repository[0]. With the change we can drop the
pull_image_old() function because it was kept only for the old image.

Seems like newer version of ShellCheck checks the validity of variable
names (SC2153). This caused a false positive, so I silenced it.

[0] https://github.com/containers/toolbox/pull/615

https://github.com/containers/toolbox/pull/780
2021-05-31 12:28:24 +02:00
Debarshi Ray
16c47c0e82 profile.d: Silence SC2148
While Toolbox's test suite explicitly uses --shell=sh when running
shellcheck(1) on profile.d/toolbox.sh, external tools like Coverity
can't be expected to do the same. So they complain:
  Line 1:
  [ "$BASH_VERSION" != "" ] || [ "$ZSH_VERSION" != "" ] || return 0
  ^-- SC2148: Tips depend on target shell and yours is unknown. Add a
    shebang or a 'shell' directive.

See: https://github.com/koalaman/shellcheck/wiki/SC2148

https://github.com/containers/toolbox/pull/673
2021-01-19 19:01:41 +01:00
Debarshi Ray
6fa2184da5 profile.d: Prevent setting VTE-specific PROMPT_COMMAND without VTE
Fedora's /etc/bashrc sets the PROMPT_COMMAND environment variable to
__vte_prompt_command when running inside a VteTerminal. This becomes a
problem if the __vte_prompt_command shell function is missing because
/etc/profile.d/vte.sh itself is absent [1], which is the case with the
Red Hat Universal Base Image.

This tricks the code in /etc/bashrc into not doing that.

[1] https://pagure.io/setup/pull-request/23

https://github.com/containers/toolbox/pull/667
2021-01-12 02:37:47 +01:00
Debarshi Ray
88f2916822 profile.d: Restore compatibility with Z shell
Otherwise, every zsh instance was running into:
  zsh: #: command not found...

Fallout from dcdfa3a1f5

https://github.com/containers/toolbox/pull/660
2021-01-07 20:03:56 +01:00
Debarshi Ray
dcdfa3a1f5 profile.d: Don't leak all the os-release fields into the shell
All the fields defined in /usr/lib/os-release were being injected into
the shell as environment variables. This is unintentional. Some of the
variables have relatively generic names, and having them in the
environment can lead to unexpected surprises.

Fallout from c6e37cdef3

https://github.com/containers/toolbox/pull/623
2020-11-17 00:30:29 +01:00
Kan Li
30ee7d9a38 Fix warning for Ubuntu containers: "Error: terminfo entry not found for xterm-256color"
On Ubuntu, both /usr/share/terminfo and /lib/terminfo can have contents, and xterm-256color is at /lib/terminfo (provided by ncurses-base package) while xterm+256color is at /usr/share/terminfo (provided by ncurses-term package). This PR checks both directory to suppress the warning.
2020-10-17 14:07:15 +02:00
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
Michael Nguyen
c6e37cdef3 profile.d: Tighten the Silverblue check
The Silverblue welcome message was being displayed incorrectly on
other OSTree based OS's (Fedora Atomic Host, Fedora CoreOS, etc).

Note that none of the stable Silverblue releases that have shipped so
far (ie., until Silverblue 30) have had 'silverblue' as the VARIANT_ID.
This makes the check a bit more convoluted that it should have been.

https://github.com/debarshiray/toolbox/pull/236
2019-08-12 13:47:36 +02:00
Colin Walters
e8f72f1e76 Drop the "immutable" term
I'm still waging a fight against this.  Please stop saying "immutable"
for this, it's more misleading than useful.

Previously e.g. https://github.com/debarshiray/toolbox/pull/43

https://github.com/debarshiray/toolbox/pull/221
2019-07-17 20:57:23 +02:00
Calvin Ling
bc1a816ea3 Unbreak rendering & wrapping of commands typed at an interactive prompt
... by wrapping the terminal escape sequences in '\[' and '\]':
https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html

https://github.com/debarshiray/toolbox/issues/190
2019-06-17 15:16:32 +02:00
Debarshi Ray
de67ff4bcc Use a magenta hexagon instead of 🔹 in the PS1
... because of its likeness to the Toolbox logo. Note that the magenta
foreground colour is requested through a terminal escape sequence with
SGR parameters [1]. The specific colour code for magenta is 35.

The main body of the PS1 needs to be split out to prevent Bash from
complaining:
  bash: printf: missing unicode digit for \u

[1] https://en.wikipedia.org/wiki/ANSI_escape_code

https://github.com/debarshiray/toolbox/pull/150
2019-05-06 16:38:10 +02:00
Debarshi Ray
0e38e7d0b3 Retain the PS1 across su(1) and sudo(8)
The shell start-up scripts are where the PS1 is meant to be set. So
far, the absence of a toolbox-specific start-up script was being worked
around by setting the PS1 as part of the 'podman exec' invocation. This
came with certain limitations. eg., using su(1) or sudo(8) to get a
root shell can overwrite the PS1 set during 'podman exec' with a value
set by the operating system's existing start-up scripts depending on
which environment variables were being retained.

Now that the toolbox has it's own /etc/profile.d/toolbox.sh start-up
script, it's time to move the PS1 to its rightful home.

Since the start-up script and /run/.toolboxenv are present in older
toolbox containers, this change should be fully backwards compatible
and lead to a more robust PS1 without breaking older containers.

https://github.com/debarshiray/toolbox/pull/148
2019-05-06 12:48:49 +02:00
Debarshi Ray
f864d67baf Create /run/.toolboxenv in 'toolbox enter' for identification
This is better than setting an environment variable like
TOOLBOX_CONTAINER with 'podman create' because, unlike environment
variables, it can't be unset later by commands like su(1) or sudo(8).
One nice side-effect of doing it inside 'toolbox enter' is that it
will automatically work with older toolbox containers.

A subsequent commit will switch to using the /etc/profile.d/toolbox.sh
start-up script to set the PS1 instead of doing it as part of the
'podman exec' invocation. Having the identification mechanism work with
older toolbox containers is important to avoid breaking the PS1 for
backwards compatibility.

This reverts commit c7b7fa1867

https://github.com/debarshiray/toolbox/pull/148
2019-05-06 12:48:18 +02:00
Debarshi Ray
c7b7fa1867 Set TOOLBOX_CONTAINER in the environment to identify as a toolbox
This is a lot more clear and explicit than TOOLBOX_PATH, which is more
of an implementation detail to bind mount the toolbox script inside the
toolbox container.

https://github.com/debarshiray/toolbox/pull/142
2019-04-29 20:39:23 +02:00
Debarshi Ray
abb2ac6fd4 Show a welcome text on interactive shells running inside a toolbox
The welcome text uses the OSC 8 [1] escape sequence to add a hyperlink
to the Silverblue documentation [2].

Silence a SC1003 [3] because the intention is to print the 'ESC \'
string terminator (or ST), and not escape a single quote.

[1] https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
[2] https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/
[3] https://github.com/koalaman/shellcheck/wiki/SC1003

https://github.com/debarshiray/toolbox/pull/130
2019-04-25 16:21:13 +02:00
Debarshi Ray
79f59b667b Show a welcome text on interactive shells running on Silverblue hosts
The welcome text uses the OSC 8 [1] escape sequence to add a hyperlink
to the Silverblue documentation [2].

Silence a SC1003 [3] because the intention is to print the 'ESC \'
string terminator (or ST), and not escape a single quote.

[1] https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
[2] https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/
[3] https://github.com/koalaman/shellcheck/wiki/SC1003

https://github.com/debarshiray/toolbox/pull/127
2019-04-25 15:52:23 +02:00