Commit graph

154 commits

Author SHA1 Message Date
Tomas Popela
668f7dcfa5 Fix the saving and restoring of the array of positional parameters
Otherwise https://www.shellcheck.net/ would complain:
  Line 21:
  arguments="$@"
            ^-- SC2124: Assigning an array to a string! Assign as
              array, or use * instead of @ to concatenate.

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

POSIX doesn't support arrays other than the one for positional
parameters (ie. "$@"); and "$@" is generally recommended for
forwarding the positional parameters, not $@ or "$*" or $* [1,2].

Therefore, the original contents of "$@" are saved in a scalar variable
after quoting them in a way that's resilient against spaces and
wildcards in the elements, and are later restored using 'set -- ...'
based on Rich's sh (POSIX shell) tricks:
http://www.etalabs.net/sh_tricks.html

Since the forward_to_host to function isn't passed any positional
parameters but still references "$@", because it uses 'set -- ...' to
restore the script's array of positional parameters, SC2119 [3] and
SC2120 [4] need to be silenced. Otherwise https://www.shellcheck.net/
would complain:
  Line 976:
  forward_to_host()
  ^-- SC2120: forward_to_host references arguments, but none are ever
    passed.

The --verbose debug output was restructured to silence SC2145 [5].
Otherwise https://www.shellcheck.net/ would complain:
  Line 986:
  echo "... to host: $0 $@" >&3
                        ^-- SC2145: Argument mixes string and array.
                          Use * or separate argument.

As a nice side-effect the new output highlights the importance of using
"$@" to forward the positional parameters instead of the other
alternatives.

Fallout from 5b3d234c9e

[1] https://unix.stackexchange.com/questions/41571/what-is-the-difference-between-and/94200
[2] https://unix.stackexchange.com/questions/129072/whats-the-difference-between-and
[3] https://github.com/koalaman/shellcheck/wiki/SC2119
[4] https://github.com/koalaman/shellcheck/wiki/SC2120
[5] https://github.com/koalaman/shellcheck/wiki/SC2145

https://github.com/debarshiray/toolbox/pull/83
2019-03-22 17:21:14 +01:00
Debarshi Ray
e54f9766e6 Reduce reliance on Buildah by switching to 'podman inspect ...'
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 37 MB respectively,
whereas the flatpak binary is a mere 1.4 MB. This isn't surprising
because both buildah and podman vendor in each other, so they are
almost, but not quite, clones of each other.

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-03-22 17:20:29 +01:00
Debarshi Ray
16f0b21ebc images: Reduce their sizes by removing temporary files created by DNF
For a locally built squashed fedora-toolbox:29 image [1], the size
reported by 'podman images' goes from 630 MB to 425 MB.

[1] Using: buildah bud --squash ...
2019-03-21 17:39:39 +01:00
Emiel Wiedijk
189f366dea Avoid a Bash-ism (ie. echo flags) and stick to POSIX (ie. printf)
Detected by https://www.shellcheck.net/.

Note that for coloured output the escape sequences need to be
interpreted as control characters and hence the variables containing
them need to be expanded inside the format string. This is an exception
to the general rule of thumb regarding printf [1] and hence SC2059
needs to be silenced. Otherwise https://www.shellcheck.net/ would
complain:
  Line 740:
  printf "${LBC}Images created by toolbox${NC}\n"
         ^-- SC2059: Don't use variables in the printf format string.
           Use printf "..%s.." "$foo".

Some changes by Debarshi Ray.

[1] https://github.com/koalaman/shellcheck/wiki/SC2059

https://github.com/debarshiray/toolbox/issues/53
2019-03-19 19:04:15 +01:00
Debarshi Ray
37d5459bfe Give access to Kerberos if KCM credential caches are being used
There's no easy way to introspect the Kerberos configuration from the
command line. eg., the credential cache type being used, or the value
of the socket_path setting that denotes which socket the KCM service
will listen on. Therefore, it's assumed that the former is KCM if the
socket's path can be parsed from the sssd-kcm.socket unit.

Given the immutable nature of Podman containers, the toolbox container
and its corresponding image will have to be re-created if the host OS
is sufficiently re-configured.

The krb5-libs package was added to the base toolbox images to ensure
the presence of the /etc/krb5.conf.d directory with the correct
permissions. Currently, the package is already pulled in by various
dependencies. Therefore, it doesn't increase the size of the base
image, but serves as a safeguard against any inadvertent changes.

https://github.com/debarshiray/toolbox/pull/74
2019-03-15 15:30:48 +01:00
Debarshi Ray
2b3989dd7f Prepare 0.0.7 2019-03-14 14:06:57 +01:00
Debarshi Ray
e71af911f2 doc/toolbox-rmi: Fix typo
Fallout from 7acc9936cf
2019-03-14 14:06:57 +01:00
Debarshi Ray
7d2b503b02 Give access to /dev/bus for control transfers from USB devices
This enables things like:
  $ colormgr get-sensor-reading lcd

https://github.com/debarshiray/toolbox/pull/79
2019-03-13 18:16:38 +01:00
Debarshi Ray
0c848abd18 Give access to removable devices and other temporary mounts
Currently, when udisks is configured to use /run/media instead of
/media, on most operating systems, the /run/media directory is created
by udisks itself when the first mount is handled [1]. This causes
problems when creating the toolbox container, if nothing has been
mounted after the current boot, because a missing directory cannot be
bind mounted.

Fedora Silverblue is a significant exception to the above, where
rpm-ostree takes care of creating /run/media with systemd-tmpfiles [2]
during boot.

The correct long-term solution is to get udisks to create /run/media
during boot with systemd-tmpfiles by installing a snippet in
tmpfiles.d [3, 4]. Until that happens, and is widely deployed, the
toolbox needs to provide the snippet itself to make things work on
the majority of operating systems.

Note that, in case udisks is configured to use /media instead of
/run/media, then this will create an unused /run/media directory. This
is probably fine because /run/media is the default setting for udisks.
Moreover, an unused directory is way better than not being able to
access mount points from a toolbox container or having 'podman create'
fail due to a missing directory.

Based on 4a2a15f2eb and as suggested by
Daniel J Walsh.

[1] UDisks commit aa02e5fc53efdeaf
    https://github.com/storaged-project/udisks/commit/aa02e5fc53efdeaf
[2] rpm-ostree commit 958dfa435e4e4a3e
    https://github.com/projectatomic/rpm-ostree/commit/958dfa435e4e4a3e
[3] https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
[4] https://github.com/storaged-project/udisks/pull/641

https://github.com/debarshiray/toolbox/issues/3
2019-03-13 15:48:03 +01:00
Emiel Wiedijk
a1865baee8 Avoid a Bash-ism (ie. $'...') and stick to POSIX (ie. $(printf '...'))
Detected by the checkbashisms [1] tool.

[1] https://packages.debian.org/sid/devscripts

https://github.com/debarshiray/toolbox/issues/53
2019-03-12 16:13:39 +01:00
Debarshi Ray
4d37209313 Simplify code by removing a useless use of cat(1)
... detected by https://www.shellcheck.net/.

Fallout from 5b3d234c9e
2019-03-12 16:13:39 +01:00
Debarshi Ray
6a5b41835e Use a POSIX compatible built-in to detect the presence of flatpak-spawn
... because it's both faster and more portable than which(1). Detected
by https://www.shellcheck.net/.

Note that the checkbashisms [1] tool thinks that only 'command -p ...'
is specified in POSIX, but that's not true [2].

[1] https://packages.debian.org/sid/devscripts
[2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
2019-03-12 12:40:43 +01:00
Debarshi Ray
0152317522 Silence SC2086
Otherwise https://www.shellcheck.net/ would complain:
  Line 108:
  [ "$1" != "" ] && [ $1 -eq $1 ] 2>&3
                      ^-- SC2086: Double quote to prevent globbing and
                        word splitting.

See: https://github.com/koalaman/shellcheck/wiki/SC2086
2019-03-12 11:58:35 +01:00
Debarshi Ray
1002bd8192 Remove stray whitespace 2019-03-11 18:48:21 +01:00
Debarshi Ray
56c3cfc27c Make the --image flag override the base toolbox image, as documented
The current implementation of the --image flag, including the commit
message in commit 31de3ff96f that added it, was a total fiasco
and didn't match the intended behaviour or the documentation in the
manual at all. At the moment it overrides the name of the user-specific
customized image. This doesn't make sense because it's mostly an
implementation detail of the toolbox script - a way to get from the
base image to a toolbox container that's seamlessly integrated with the
host.

In other words, there's no need for a separate flag to allow having
multiple user-specific customized images from the same base image. It
already happens as a side effect of creating multiple toolbox
containers from the same base image using the --container flag.

What it really should do is override the base image so that toolbox
containers with different content can be created.

The format of a image reference is defined in:
https://github.com/moby/moby/blob/master/image/spec/v1.1.md
https://github.com/docker/distribution/blob/master/reference/reference.go

The code in create_toolbox_image_name is based on the ResolveName
function implemented in:
https://github.com/containers/buildah/blob/master/util/util.go

Fallout from 31de3ff96f

https://github.com/debarshiray/toolbox/pull/73
2019-03-11 18:05:19 +01:00
Debarshi Ray
f5f22bdf4e Try to avoid downloading a base image that's referred to by its ID
When any image is referred to by its non-human-readable ID, then it
must already be cached locally. It cannot be pulled from a registry
based on the hash, and there's no way to map it to the human-readable
name either.

A subsequent commit will leverage this to let the user override the
base toolbox image with an image reference that's a non-human-readable
ID.

The format of a image reference is defined in:
https://github.com/moby/moby/blob/master/image/spec/v1.1.md
https://github.com/docker/distribution/blob/master/reference/reference.go

https://github.com/debarshiray/toolbox/pull/73
2019-03-11 17:33:14 +01:00
Debarshi Ray
220e0d3632 Support base toolbox image names that include a domain
A subsequent commit will leverage this to let the user override the
base toolbox image with an image reference that might include a domain.
This can be helpful if the user wants to use an image from a specific
registry as opposed to the current approach of first looking for
localhost/<image> and then registry.fedoraproject.org/f$release/$image.

The format of a image reference is defined in:
https://github.com/moby/moby/blob/master/image/spec/v1.1.md
https://github.com/docker/distribution/blob/master/reference/reference.go

The code in image_reference_has_domain is based on the
splitDockerDomain function implemented in:
https://github.com/docker/distribution/blob/master/reference/normalize.go

https://github.com/debarshiray/toolbox/pull/73
2019-03-11 17:05:10 +01:00
Debarshi Ray
1e0564d66c Don't pollute the global namespace with the contents of /etc/os-release 2019-03-11 17:01:29 +01:00
Debarshi Ray
6e69d34b7f Be more informative when creating the working container
Creating just the working container itself takes noticeably long, even
if the base image is already cached locally.
2019-03-09 09:10:08 +01:00
Debarshi Ray
8ed688b724 Don't busy-loop when waiting for the spinner to stop 2019-03-09 08:53:13 +01:00
Debarshi Ray
2f9f71b378 Stop the spinner a few seconds faster
Currently, it was only checking the spinner-start file after looping
through all the frames of the animation. Instead it should check for
every frame.
2019-03-09 08:47:25 +01:00
Debarshi Ray
67dc9761e2 Silence SC2153
Otherwise https://www.shellcheck.net/ would complain:
  Line 277:
  if [ "$DBUS_SYSTEM_BUS_ADDRESS" != "" ]; then
        ^-- SC2153: Possible misspelling: DBUS_SYSTEM_BUS_ADDRESS may
          not be assigned, but dbus_system_bus_address is.

See: https://github.com/koalaman/shellcheck/wiki/SC2153
2019-03-08 12:47:45 +01:00
Debarshi Ray
1cdaf21203 doc: Fix the installation of manuals
The manuals shouldn't be installed in the top-level directory, but in
one of the sub-directories corresponding to the relevant section.

Fallout from 0a972dfccc
2019-03-06 17:08:22 +01:00
Emiel Wiedijk
c53b36676d Avoid a Bash-ism (ie. UID) and stick to POSIX (ie. id -ru)
Detected by the checkbashisms [1] tool.

[1] https://packages.debian.org/sid/devscripts

https://github.com/debarshiray/toolbox/issues/53
2019-03-06 14:08:25 +01:00
Ondřej Zoder
dde1fa0734 images: Restore documentation removed from the base Fedora images
https://github.com/debarshiray/toolbox/pull/55
2019-03-05 18:01:27 +01:00
Debarshi Ray
c9a061c7b9 doc/toolbox-enter: Mention the underlying podman commands
It's useful to know things like a running toolbox container has to be
stopped before removal or 'rm --force' needs to be used, etc.. This is
implicitly tied to the fact that entering a toolbox container is
equivalent to a 'podman start' followed by a 'podman exec'.
2019-03-05 16:32:53 +01:00
Debarshi Ray
517c77a0d6 doc: Grammar fixes 2019-03-05 16:32:53 +01:00
Ondřej Zoder
7acc9936cf Add rm and rmi commands
https://github.com/debarshiray/toolbox/pull/45
2019-03-05 16:17:46 +01:00
Debarshi Ray
40cb8caf46 Rename a variable
It's obvious that this is a container ID, so there's no need for the
"container" prefix.
2019-03-01 18:44:41 +01:00
Debarshi Ray
0a972dfccc Add manuals
https://github.com/debarshiray/toolbox/pull/66
2019-03-01 10:27:09 +01:00
Debarshi Ray
c65e656966 README.md: Add missing comma 2019-03-01 10:26:58 +01:00
Debarshi Ray
c219ac1882 README.md: Tweak
The word 'tool' sounds a bit less vague than 'project'.
2019-03-01 10:13:46 +01:00
Debarshi Ray
554fac08b0 Don't create volumes in the image for bind mounts from the host
Otherwise, it breaks 'podman start ...' in Podman commit
52df1fa7e054d577 [1]. Even though the podman regression was fixed in
commit 21bc766ee3829776 [2], it's prudent to also fix the toolbox
script to be more correct.

This problem isn't localized to a single command, but spans across
'create' and 'enter'. If a customized toolbox image created by the
'create' command has volumes for host bind mounts, then it will break
'podman start ...' in the 'enter' command. Therefore, users need to be
encouraged to recreate both their customized toolbox images. This is
currently done through the --verbose debug logs to avoid needless
noise because the regression was restricted to development snapshots
of podman.

Toolbox containers created from images built by broken Podman versions
between commits 52df1fa7e054d577 and 21bc766ee3829776, and broken
toolbox scripts prior to this commit, will continue to not start.
Those toolboxes and their corresponding customized images need to be
re-created with at least one of the components, either podman or this
script, fixed.

Note that 'podman inspect --type container ...' doesn't have a Go
template field for "Image". However, "ImageName" gracefully falls back
to the ID for images without a human-readable name, which is arguably
better than always using an ID.

As suggested by Daniel J Walsh and Giuseppe Scrivano.

[1] https://github.com/containers/libpod/commit/52df1fa7e054d577
[2] https://github.com/containers/libpod/commit/21bc766ee3829776

https://github.com/containers/libpod/issues/2441
https://github.com/debarshiray/toolbox/issues/62
2019-02-26 20:47:24 +01:00
Debarshi Ray
10ee2d44b7 Clarify the error message if the toolbox container is not found
https://github.com/debarshiray/toolbox/issues/59
2019-02-26 19:47:38 +01:00
Debarshi Ray
ad75d97b50 images: Add fedora-toolbox image definition for Fedora 31 2019-02-25 14:45:46 +01:00
Debarshi Ray
acad65cd41 extra-packages: Style fixes 2019-02-25 14:37:58 +01:00
Debarshi Ray
a82261f30a extra-packages: Add flatpak-xdg-utils to Fedoras 29 and 30
This is necessary for the toolbox script to work inside the toolbox
container [1]. Having the flatpak-spawn command, provided by the
flatpak-xdg-utils package, readily available in the base image makes
for a better out of the box experience.

The flatpak-xdg-utils package is not available on Fedora 28. Given
that Fedora 28 is getting close to the end of its life cycle, it's
probably not worth doing all the paperwork to offer the package there.

[1] Commit 5b3d234c9e
    https://github.com/debarshiray/toolbox/pull/54
2019-02-25 14:04:46 +01:00
Debarshi Ray
04a91d5189 Prepare 0.0.6 2019-02-21 19:47:56 +01:00
Debarshi Ray
0af7be08a9 Don't write to standard output if any of the list functions fail
Currently, 'toolbox list' doesn't handle errors thrown by any of the
functions used by it. If something fails, it will send the error
message to the standard error output and continue trying to list other
things.

Instead, it's better to ensure that all the internal functions have
succeeded before listing anything. If there's an error, print the error
message but don't mix it with attempts to list other things so that
the failure mode is cleaner and it's more obvious that something went
wrong.
2019-02-20 19:54:37 +01:00
Debarshi Ray
d8294628c2 Use the standard error output for error messages 2019-02-20 19:52:06 +01:00
Debarshi Ray
8ae0645c80 Handle errors in command pipeline when listing containers
Listing toolbox containers involves parsing the output of 'podman ps'
and rearranging the columns into a table. Parsing and rearranging
output is inherently brittle, and there's no guarantee that podman
itself won't fail. Therefore, it's prudent to sprinkle some error
handling.
2019-02-20 19:52:06 +01:00
Debarshi Ray
5a67dec0e8 Handle errors in command pipeline when listing images
Listing toolbox images involves parsing the output of 'podman images'
and rearranging the columns into a table. Parsing and rearranging
output is inherently brittle, and there's no guarantee that podman
itself won't fail. Therefore, it's prudent to sprinkle some error
handling.
2019-02-20 19:52:06 +01:00
Debarshi Ray
85c319274f Add missing --verbose option to --help
Fallout from 5e4e63a11b
2019-02-20 19:52:06 +01:00
Debarshi Ray
de09605583 Remove redundant code
Unsetting the IFS variable doesn't disable field splitting. It makes
the shell behave as if the default field separators (ie. <space>,
<tab> and <newline>) are in play. See:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

The original reason for unsetting IFS was to disable field splitting,
which was clearly wrong. Moreover, there was no need to worry about it
in the first place, because none of the command substitutions being
performed involve multiline output where field splitting would have
become relevant.

Fallout from 5e4e63a11b
2019-02-20 14:16:10 +01:00
Debarshi Ray
10d1f5962f README.md: Add a hyperlink for OCI 2019-02-19 15:16:28 +01:00
Debarshi Ray
a0f169c1ce README.md: Add missing whitespace 2019-02-19 15:14:26 +01:00
Debarshi Ray
ecc76f39ac Silence SC1091
Otherwise https://www.shellcheck.net/ would complain:
  Line 44:
  . /etc/os-release
    ^-- SC1091: Not following: /etc/os-release was not specified as
      input (see shellcheck -x).

See: https://github.com/koalaman/shellcheck/wiki/SC1091
2019-02-19 14:57:14 +01:00
Emiel Wiedijk
26a285a7e0 POSIX only supports single digit file descriptors
See: https://wiki.ubuntu.com/DashAsBinSh

Detected by the checkbashisms [1] tool.

[1] https://packages.debian.org/sid/devscripts

https://github.com/debarshiray/toolbox/issues/53
2019-02-19 14:30:11 +01:00
Debarshi Ray
9315f6cbbf Fix typos
... detected by https://www.shellcheck.net/.

The opening solid bracket (ie. [) is actually a command like any other.
It expects it's final argument to be the closing bracket (ie. ]). Thus,
the redirection needs to be after the trailing bracket.

Fallout from 80f25c6924
2019-02-19 14:08:52 +01:00
Debarshi Ray
5b3d234c9e Make it work inside the toolbox container itself
A truly seamless developer experience requires erasing the divide
between the host and the toolbox container as much as possible.
Currently, various tools don't work at all when used from inside the
toolbox because they expect to be run on the host. eg., flatpak,
podman, and the toolbox script itself. This puts a significant enough
cognitive burden on the developer. At the very least, the human
operator needs to keep track of the context in which those commands
are being issued.

To make things better, the toolbox script has been made aware of the
context in which it is running. If it detects that it's running inside
the toolbox container, denoted by a 'podman exec ...' parent process
and the presence of /run/.containerenv, then it tries to forward its
own invocation to the host over D-Bus using 'flatpak-spawn --host' [1].
This uses the HostCommand method on the org.freedesktop.Flatpak D-Bus
service underneath to do the forwarding.

The process offering the org.freedesktop.Flatpak service doesn't have
some variables, like COLORTERM and TERM, set in its environment, and
their absence hinders the use of interactive shells. This is addressed
by tunneling the same set of environment variables that are also passed
to podman.

[1] http://docs.flatpak.org/en/latest/flatpak-command-reference.html#flatpak-spawn

https://github.com/debarshiray/toolbox/pull/54
2019-02-19 13:22:18 +01:00