Skip to content

Instantly share code, notes, and snippets.

@albestro
Created February 22, 2022 15:59
Show Gist options
  • Save albestro/906693f3ef55fba9083248f0b83e9d71 to your computer and use it in GitHub Desktop.
Save albestro/906693f3ef55fba9083248f0b83e9d71 to your computer and use it in GitHub Desktop.

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).

Use-case

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.

Reference

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.

Real-life use-case: CUDA toolkit file extraction

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"
#!/bin/bash
# This script extracts, from all "cuda*.run" installers in the working directory,
# files whose path inside the archive match the pattern "*nvcc*host_config.h"
#
# Resulting files will be stored in separate independent folders,
# whose name correspond to the installer filename suffixed with ".extract"
for cuda_pkg in `ls cuda*.run`; do
outdir="${cuda_pkg}.extract"
mkdir $outdir && bash ${cuda_pkg} --tar "xf" "-C $outdir" "--wildcards *nvcc*host_config.h" &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment