Commit graph

258 commits

Author SHA1 Message Date
Debarshi Ray
3b311313b7 Prepare 0.0.11 2019-06-21 16:31:50 +02:00
Debarshi Ray
585053bb8e Notify the terminal about the current toolbox container in use
This will let GNOME Terminal preserve the current toolbox container, if
any, when opening a new terminal. Since this is mainly beneficial to
users of an interactive shell inside a toolbox container, the escape
sequences are only emitted by 'toolbox enter', and not 'toolbox run'.

The OSC 777 escape sequence is taken from Enlightenment's Terminology:
https://phab.enlightenment.org/T1765

It's a VTE-specific extension until a standard escape sequence is
agreed upon across multiple different terminal emulators [1].

[1] https://gitlab.freedesktop.org/terminal-wg/specifications/issues/17

https://github.com/debarshiray/toolbox/pull/199
2019-06-21 16:19:18 +02:00
Casey Jao
c2e41553db Unbreak setting up /home as a symbolic link
The whole idea behind commit 66e982af72 was to set up $HOME and
/home to match the host. Therefore, it's pointless to check if /home
is a symbolic link or not inside the toolbox container. The state of
/home needs to be checked on the host, and then the toolbox container
adjusted accordingly.

One crucial difference is that the toolbox container is created before
its /home can be adjusted. Earlier, there was the user-specific
customized image, whose /home was adjusted first, and then the toolbox
container created from that. This boils down to the following
invocation happening before the symbolic link can be set up:
  podman create --volume "$HOME":$HOME":rslave --workdir "$HOME" ...

As a result, on host operating systems like Fedora 29 where /home is a
symbolic link with $HOME pointing inside it, Podman populates /home
with the user's sub-directory inside the toolbox container. This
prevents the subsequent 'rmdir $HOME' from working, and consequently
kills the container's entry point.

Compare that to Fedora 30 and newer where this problem doesn't occur
because /home is a symbolic link but $HOME points inside the target
/var/home directory.

This is why $HOME is canonicalized before bind mounting it into the
container and the container's working directory is reverted back to the
default (ie. /).

Fallout from 8b84b5e460

https://github.com/debarshiray/toolbox/issues/185
2019-06-17 23:28:34 +02:00
Casey Jao
adfca25c57 Unbreak error handling when setting up /home as a symbolic link
The unary logical negation operator (ie. !) was getting associated with
the 'rmdir /home' instead of the entire sequence.

Fallout from 8b84b5e460

https://github.com/debarshiray/toolbox/issues/185
2019-06-17 21:32:29 +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
cbef52527f Unbreak 'podman cp ...' to work with podman-1.3.1
The '--pause' flag for 'podman cp' was only introduced in
podman-1.4.0 [1]. Having it work with older Podman versions is useful
when bisecting regressions.

Fallout from e715ff2f9b

[1] Podman commit 49dc18552a13ee76
    https://github.com/containers/libpod/commit/49dc18552a13ee76

https://github.com/debarshiray/toolbox/pull/194
2019-06-14 21:42:18 +02:00
Debarshi Ray
e715ff2f9b Prevent Podman from complaining about 'podman cp --pause=true ...'
Rootless containers cannot be paused while data is copied into them.
The '--pause' flag used to default to 'true', but it would be silently
ignored until recently [1,2] when it got turned into an error in
podman-1.4.0. Therefore, it has to be explicitly toggled using
'--pause=false'. Otherwise, it would lead to:
  toolbox: copying /etc/profile.d/toolbox.sh to container fubar
  Error: cannot copy into running rootless container with pause set -
    pass --pause=false to force copying
  toolbox: unable to copy /etc/profile.d/toolbox.sh to container fubar

The '--pause' flag was latter changed to default to 'false' [3], but
it's good to be defensive and have this addressed from both sides.

Note that 'podman cp --pause false ...' doesn't work. It's necessary to
use the '=' because it gets confused trying to parse the
space-separated source and destination path arguments.

[1] Podman commit 48e35f7da70c24ed
    https://github.com/containers/libpod/commit/48e35f7da70c24ed

[2] Podman commit 57d40939792719e6
    https://github.com/containers/libpod/commit/57d40939792719e6

[3] Podman commit d40b450afdc9784a
    https://github.com/containers/libpod/commit/d40b450afdc9784a

https://github.com/debarshiray/toolbox/pull/193
2019-06-14 19:30:54 +02:00
Debarshi Ray
0886fb466e Check if /etc/subgid and /etc/subuid have entries for the user
This is relevant when running on hosts where the current user might
have been created long ago with an old version of shadow-utils, and
the host OS has been upgraded in-place ever since.

https://github.com/debarshiray/toolbox/issues/174
2019-05-24 13:41:27 +02:00
Wynter Woods
9215c6f549 Give access to the entire /dev from the host operating system
Things like the proprietary NVIDIA driver need access to devices
directly inside the /dev directory (eg., /dev/nvidia0 and
/dev/nvidiactl), and since such devices can come and go at runtime they
cannot be bind mounted individually. Instead, the entire directory
needs to be made available.

https://github.com/debarshiray/toolbox/issues/116
2019-05-23 15:34:01 +02:00
Debarshi Ray
8db414ddc2 Keep /etc/localtime and /etc/timezone synchronized with the host
The permission of $XDG_RUNTIME_DIR/.flatpak-helper/monitor needs to be
relaxed [1] for this work in some corner cases. However, it already
works for the vast majority of cases when used as $USER or root inside
the toolbox container.

[1] https://github.com/flatpak/flatpak/pull/2916

https://github.com/debarshiray/toolbox/issues/70
2019-05-22 16:58:30 +02:00
Debarshi Ray
34cc27a77a Keep /etc/host.conf synchronized with the host
https://github.com/debarshiray/toolbox/issues/70
2019-05-22 16:49:27 +02:00
Debarshi Ray
3e7400836f Allow Qt applications to work without QT_X11_NO_MITSHM
This reverts commit fdc00a2778.

https://github.com/debarshiray/toolbox/issues/163
2019-05-22 12:12:52 +02:00
Debarshi Ray
8b81058f3f Prepare 0.0.10 2019-05-21 18:55:47 +02:00
Andre Moreira Magalhaes
e6389a9ef1 Support column(1) from bsdmainutils
Fedora ships with column(1) from util-linux [1], which supports the
--table-columns option and long option names that are missing in
Debian's column(1) from bsdmainutils [2].

[1] http://man7.org/linux/man-pages/man1/column.1.html
[2] https://manpages.debian.org/testing/bsdmainutils/column.1.en.html

https://github.com/debarshiray/toolbox/pull/137
2019-05-21 18:15:26 +02:00
Andre Moreira Magalhaes
1a69573575 Support 'sudo' as default sudo(8) group
Most Debian based images use the 'sudo' group for sudo(8) access, while
Fedora uses the 'wheel' group. Hence check if either group exists
before attempting to add the user to it and fail otherwise.

https://github.com/debarshiray/toolbox/pull/167
2019-05-20 17:04:37 +02:00
Andre Moreira Magalhaes
3db5d0a698 Set the Kerberos credential cache type only if Kerberos is available
https://github.com/debarshiray/toolbox/pull/167
2019-05-20 17:04:37 +02:00
Debarshi Ray
5412ed03ec Unbreak the initialization of /etc/hosts and /etc/resolv.conf
The unary logical negation operator (ie. !) was getting associated with
the 'cd /etc' instead of the entire sequence. As a result, neither
/etc/hosts nor /etc/resolv.conf were getting symlinked.

Fallout from 8b84b5e460

https://github.com/debarshiray/toolbox/pull/168
2019-05-20 16:25:25 +02:00
Debarshi Ray
3278c1fa3f Make it easier to debug the 'toolbox init-container' entry point
This makes it possible to use 'podman start --attach' to see what the
'toolbox init-container' entry point is doing.

https://github.com/debarshiray/toolbox/pull/168
2019-05-20 16:25:21 +02:00
Debarshi Ray
9fc44b4eac Migrate existing containers when Podman is updated
This was triggered by changes to rootless Podman containers in
podman-1.3.0 [1]. Containers created with version 1.2.0 or older need
to be migrated.

[1] https://github.com/containers/libpod/issues/2935

https://github.com/debarshiray/toolbox/pull/166
2019-05-20 15:37:25 +02:00
Debarshi Ray
39806d9269 Drop the prefix from spinner messages
The prefixed spinner messages look odd because neither the download
confirmation prompts nor the hints on how to enter a container have
them. It's better to only prefix the debug and error messages so as to
disambiguate their origins.

https://github.com/debarshiray/toolbox/pull/164
2019-05-17 14:33:39 +02:00
Debarshi Ray
8b84b5e460 Drop the Buildah dependency and the user-specific customized image
This works by configuring the toolbox container after it has been
created, instead of before. The toolbox script itself is mentioned as
the entry point of the container, which does 'exec sleep +Inf' once the
initialization is done.

A new command 'init-container' was added to perform the initialization.
It is primarily meant to be used as the entry point for all toolbox
containers, and must be run inside the container that's to be
initialized. It is not expected to be directly invoked by humans, and
cannot be used on the host.

As a result, the default name for the toolbox containers is now
fedora-toolbox-<version-id>, not fedora-toolbox-<user>-<version-id>.
For backwards compatibility, 'toolbox enter' and 'toolbox run' will
continue to work with containers using the old naming scheme.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 15:47:33 +02:00
Debarshi Ray
dadb21dade Shuffle some code around
A subsequent commit will create toolbox container names based on both
the base image and the user-specific customized image. This will make
it easier to read.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
affcede2eb Check for /run/.toolboxenv later to accommodate entry point commands
A subsequent commit will add a new command to configure a toolbox
container after it has been created. This command is meant to be the
container's entry point, which runs before /run/.toolboxenv gets
created. Given that the entry point will be set by 'toolbox create'
it's safe to assume that it's a toolbox container anyway.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
f1d45600e0 Check for flatpak-spawn(1) later - right before actually using it
A subsequent commit will add a new command to configure a toolbox
container after it has been created. This command is meant to run
inside the container without being forwarded to the host. Therefore,
just running inside a container doesn't mean that flatpak-spawn(1) is
mandatory.

This should help with toolbox containers created from images which
don't have flatpak-spawn(1) in them. eg., the fedora-toolbox base image
for Fedora 28.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
85f5b3e3db Shuffle some code around
Consolidate the code to forward commands to the host in one place
instead of doing it repeatedly for each command. This reduces the
levels of indentation in the code, making it easier to read.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
f74400f450 Run the entry point as root:root
A subsequent commit will add a new command to configure a toolbox
container after it has been created. This command is meant to be the
container's entry point, and will need to do things as root:root
relative to the user namespace.

Even though root:root is the default in 'podman create', explicitly
specifying it overrides any other value inherited from the
user-specific customized image. eg., older images had $USER as the
default user.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
fd08a98bd9 Add c.gh.debarshiray.toolbox to the container during 'podman create'
Commit 8127daa29e added the com.github.debarshiray.toolbox label
to the user-specific customized image generated by the 'create'
command, which gets inherited by toolbox containers using the image.
However, there might be really old images lying around in users' caches
that don't have the label, and in those cases the damage can be
limited by adding it directly to the newly created toolbox container.

Moreover, a subsequent commit will remove the need for the
user-specific customized image, and which will make this change
mandatory.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Debarshi Ray
48ddffb3d8 Tweak the debug output
This will make a subsequent commit easier to read.

https://github.com/debarshiray/toolbox/pull/160
2019-05-16 14:50:22 +02:00
Damian Ludwig
f9bed79dc2 Unbreak 'buildah unshare ...' to work with buildah-1.7
Even though buildah-unshare(1) does mention the need for the dashes,
the buildah-1.8 development builds do work without them. However,
buildah-1.7 is more pedantic and insists on having the dashes.

https://github.com/debarshiray/toolbox/issues/152
2019-05-16 14:48:22 +02:00
Debarshi Ray
7450b06caf README.md: Update
Fallout from de67ff4bcc
2019-05-16 14:46:21 +02:00
Debarshi Ray
51fe2d3607 doc/toolbox: Update 2019-05-16 14:40:17 +02:00
Debarshi Ray
e5350fe840 Set the Kerberos credential cache type in the container unconditionally
KCM is the only type of Kerberos credential cache that can seamlessly
work across the host and the toolbox container. In case the host isn't
using KCM, then Kerberos will error out inside the toolbox container,
which is fine.

https://github.com/debarshiray/toolbox/pull/162
2019-05-16 13:02:59 +02:00
Debarshi Ray
db62b8bc7a Quote a few variables to avoid triggering SC2086 in future
See: https://github.com/koalaman/shellcheck/wiki/SC2086
2019-05-15 17:26:16 +02:00
Debarshi Ray
89bb7f62b1 Reduce reliance on Buildah by switching to 'podman create --workdir'
Currently, the toolbox script depends on both the buildah and podman
commands. However, both are Go programs, and like all Go programs the
absense of shared libraries leads to bigger binaries. eg., the buildah
and podman binaries are approximately 22 MB and 48 MB respectively,
whereas the flatpak binary is a mere 1.4 MB.

Due to this, there's some nascent desire from the Endless OS folks to
reduce the dependency footprint of the toolbox script by replacing
Buildah with the corresponding Podman commands. This is a step in that
direction.

https://github.com/debarshiray/toolbox/pull/161
2019-05-14 18:19:03 +02:00
Debarshi Ray
aa0e6222ff doc/toolbox-run: Style fixes 2019-05-14 17:26:02 +02:00
Debarshi Ray
d7ff7f0b0b Reduce reliance on Buildah by switching to 'podman create --user ...'
Currently, the toolbox script depends on both the buildah and podman
commands. However, both are Go programs, and like all Go programs the
absense of shared libraries leads to bigger binaries. eg., the buildah
and podman binaries are approximately 22 MB and 48 MB respectively,
whereas the flatpak binary is a mere 1.4 MB.

Due to this, there's some nascent desire from the Endless OS folks to
reduce the dependency footprint of the toolbox script by replacing
Buildah with the corresponding Podman commands. This is a step in that
direction.

https://github.com/debarshiray/toolbox/pull/159
2019-05-14 14:53:26 +02:00
Debarshi Ray
f6ac08f47f Fix typo
Fallout from c492907c12
2019-05-14 13:02:11 +02:00
Debarshi Ray
5150f902bd Remove fragile & useless code to get the 'podman exec' PID when nested
Various users in the wild have reported errors about not being able to
walk up the process tree via /proc, and currently the PID of the
parent 'podman exec' process isn't used for anything. The original idea
was to explore killing the process or something when entering another
toolbox container while already being inside one, but that's not
implemented at the moment, and it was only a vague idea to begin with.
2019-05-10 18:58:39 +02:00
Debarshi Ray
449917c6b7 Support running nested only when inside a toolbox container
... as opposed to any random container.

This puts in place a minimum baseline as to what can be expected from
the environment when running inside a container.
2019-05-10 18:52:41 +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
Toni Schmidbauer
2da4cc4634 Add a run command
This makes 'toolbox enter' similar to 'toolbox run $SHELL'.

The 'run' command is meant to spawn arbitrary binaries present inside
the toolbox container. Therefore it doesn't make sense for it to fall
back to /bin/bash, like it does for 'enter' if $SHELL is absent.

It's expected that users might use 'run' to create ad-hoc *.desktop
files. That's why it neither offers to create nor falls back to an
existing container like 'enter' does, because such interactions can't
happen when used in a *.desktop file. It's also a more advanced command
that new users are less likely to be interested in. Hence, this
shouldn't affect usability.

Some changes by Debarshi Ray.

https://github.com/debarshiray/toolbox/pull/76
2019-05-06 15:23:58 +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
c492907c12 Make profile.d/toolbox.sh available inside older toolbox containers
Commit 97f4e072d5 made /etc/profile.d/toolbox.sh available inside
the toolbox container through a bind mount. However, it only works for
for toolbox containers created after that commit. Older containers
don't have the bind mount.

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. It's necessary to ensure that the start-up
script is available on older containers to avoid breaking the PS1 when
entering them.

https://github.com/debarshiray/toolbox/pull/148
2019-05-03 20:14:29 +02:00
Debarshi Ray
22b2d40830 completion: Silence SC2207
Otherwise https://www.shellcheck.net/ would complain:
  Line 29:
  COMPREPLY=($(compgen -W "--help --verbose $commands" -- "$2"))
             ^-- SC2207: Prefer mapfile or read -a to split command
               output (or quote to avoid splitting).

See: https://github.com/koalaman/shellcheck/wiki/SC2207
2019-05-02 16:41:25 +02:00
Debarshi Ray
3694b599d6 Reduce reliance on Buildah by switching to 'podman pull ...'
Currently, the toolbox script depends on both the buildah and podman
commands. However, both are Go programs, and like all Go programs the
absense of shared libraries leads to bigger binaries. eg., the buildah
and podman binaries are approximately 22 MB and 48 MB respectively,
whereas the flatpak binary is a mere 1.4 MB.

Due to this, there's some nascent desire from the Endless OS folks to
reduce the dependency footprint of the toolbox script by replacing
Buildah with the corresponding Podman commands. This is a step in that
direction.
2019-05-02 16:23:22 +02:00
Debarshi Ray
5a5e563343 Use more appropriate API to check the cache for the base image 2019-05-02 16:20:34 +02:00
Debarshi Ray
0473213907 Keep /etc/hosts and /etc/resolv.conf synchronized with the host
https://github.com/debarshiray/toolbox/issues/129
2019-04-30 18:00:41 +02:00
Debarshi Ray
3c4c439f69 Prepare 0.0.9 2019-04-30 12:29:09 +02:00
Debarshi Ray
05da8023b4 doc/toolbox-enter: Mention the 'initial setup' and fallback behaviour
https://github.com/debarshiray/toolbox/issues/128
2019-04-30 12:19:36 +02:00