Makeself generated self-executable installer (see https://makeself.io/), also known by their .run
extension, are a common and popular way of packaging.
Put simply, they embed in a single file both the extracting script together with the tar archive with the package. After extracting it, a custom command can be executed (e.g. the actual custom installer).
It may be needed in some cases to just get access to a file in the archive embedded in the .run
, without having to fully install/extract the package.
Makeself gives the ability to pass options to the tar
command executed internally, so that it is possible to control the extraction process.
Makeself --tar
option allow to specify one or more parameters to tar
, which are passed in a command like the next one (see snippet from the original repo)
MS_dd "\$0" \$offset \$s | MS_Decompress | tar "\$arg1" - "\$@"
Where it can be seen that once the binary of the archive is extracted from the script, it is piped to be decompressed (e.g. tar.gz
is Gzip compressed), then the resulting .tar
archive is piped to the tar
command as in
tar $1 - $@ # where "-" is the placeholder for stdin input
So, to Makeself --tar
option, it should be passed as first argument f
(composing the tar option f -
, indicating that the archive comes from stdin), and then we can add all other commands needed after it.
Keep reading for an actual working example.
CUDA provides toolkits generated with Makeself, and their sizes are generally in the order of GBs. A use-case I addressed with those is to be able to extract a C++ header file inside the CUDA toolkit for checking a single line in it.
- I didn't want to install it and alter my system,
- moreover I'd like to not fully extract the entire package for just accessing few kB (and playing with more CUDA toolkits altogether, this becomes even more relevant / note: decompression happens anyway).
So, I used tar
ability to extract a single file from a tar archive, by passing the options to the Makeself self-executable installer itself, without having to manually access the binary part of the script containing the archive.
# run the cuda installer by passing the `--tar` option, part of the Makeself option,
# which allow to extract files whose paths inside the archive match the pattern "*nvcc*host_config.h"
bash cuda_11.4.4_470.82.01_linux.run --tar "xf" "--wildcards *nvcc*host_config.h"