Documentation
¶
Overview ¶
Snag a copy of a ELF binary and all its dependencies to another/path/bin & another/path//lib64.
This is the main implementation of the command-line application `snaggle`, for use as a library in other code and scripts.
Snaggle is designed to help create minimal runtime containers from pre-existing installations. It may work for other use cases and I'd be interested to hear about them at: https://github.com/MusicalNinjaDad/snaggle
WARNING: This is not designed work on non-linux systems - don't try it unless you want to have fun with unexpected and unhandled os error types.
Index ¶
Constants ¶
const Version = "1.2.1"
Variables ¶
var (
ErrCopyInplace = errors.New("cannot copy in-place")
)
Functions ¶
func Snaggle ¶
Snaggle parses the file(s) given by path and build minimal /bin & /lib64 under root.
If path refers to a directory, all valid ELF binaries directly under path will be snagged. Provide the Option [Recursive()] to recurse subdirectories.
Snaggle will hardlink (or copy, see notes):
- path -> root/bin (executables) or path/lib64 (libraries), unless the Option [InPlace()] is provided
- All dynamically linked dependencies -> root/lib64
For example:
_ = Snaggle("/bin/which", "/runtime") // you probably want to handle any error, not ignore it
// Results in:
// /runtime/bin/which
// /runtime/lib64/libc.so.6
// /runtime/lib64/libpcre2-8.so.0
// /runtime/lib64/libselinux.so.1
Notes: ¶
- Hardlinks will be created if possible.
- A copy will be performed if hardlinking fails for one of the following reasons:
- path & root are on different filesystems
- the user does not have permission to hardlink (e.g. https://docs.kernel.org/admin-guide/sysctl/fs.html#protected-hardlinks)
- Copies will retain the original filemode
- Copies will attempt to retain the original ownership, although this will likely fail if running as non-root
Types ¶
type InvocationError ¶ added in v0.3.0
Snaggle was invoked with semantically invalid inputs. err will be formatted to read well when directly output to stderr during CLI invokation E.g: invoking Snaggle(path/to/FILE, root, Recursive()) will wrap a [&fs.PathError]{Op: "--recursive", Path: "path/to/FILE", Err: syscall.ENOTDIR}
func (*InvocationError) Error ¶ added in v0.3.0
func (e *InvocationError) Error() string
func (*InvocationError) Unwrap ¶ added in v0.3.0
func (e *InvocationError) Unwrap() error
type Option ¶ added in v0.2.0
type Option func(*options)
Option setting functions
func Copy ¶ added in v1.1.0
func Copy() Option
Copy entire directory contents to /destinationroot/full/source/path
func InPlace ¶ added in v0.2.0
func InPlace() Option
Snag in place: only snag dependencies & interpreter
type SnaggleError ¶ added in v0.3.0
type SnaggleError struct {
Src string // Source path
Dst string // Destination path
// contains filtered or unexported fields
}
An error occurred during snaglling
func (*SnaggleError) Error ¶ added in v0.3.0
func (e *SnaggleError) Error() string
func (*SnaggleError) Unwrap ¶ added in v0.3.0
func (e *SnaggleError) Unwrap() error
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
snaggle
command
Snag a copy of a binary and all its dependencies to DESTINATION/bin & DESTINATION/lib64
|
Snag a copy of a binary and all its dependencies to DESTINATION/bin & DESTINATION/lib64 |
|
Parses an ELF binary providing additional details vs.
|
Parses an ELF binary providing additional details vs. |
|
Helpers and values which can be used in any package
|
Helpers and values which can be used in any package |
|
testing
Helpers related to testdata assets.
|
Helpers related to testdata assets. |