Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created April 26, 2018 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/3df91c0dcc78ba57693659fd27f2fe94 to your computer and use it in GitHub Desktop.
Save yaauie/3df91c0dcc78ba57693659fd27f2fe94 to your computer and use it in GitHub Desktop.
I had a need the other day to read files out of RPM and DEB packages, but wanted to avoid extracting them to my local filesystem; the following scripts cobble together the various tools I found to simply read a single file from either to stdout.
#!/usr/bin/env bash -x
# prereq: tar
package="${1:?package}"
file="${2:?file}"
tar -xOf $package data.tar.gz | tar -zxO $file
#!/usr/bin/env bash -x
# prereq: rpm2cpio
# prereq: cpio (GNU-flavored); will auto-detect from `GNU_CPIO` env var, GNU-flavored `cpio` on path, or `gnu-cpio` on path
package="${1:?package}"
file="${2:?file}"
# detect GNU-flavored `cpio`, which supports reading to stdout:
# - IF `GNU_CPIO` set, trust it;
# - ELSE IF `cpio` on path is GNU, use it;
# - ELSE look for `gnu-cpio`
GNU_CPIO=${GNU_CPIO:-$(cpio --help | grep GNU >/dev/null && which cpio || which gnu-cpio)}
rpm2cpio $package | "${GNU_CPIO:?}" -iv --to-stdout $file 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment