Skip to content

Instantly share code, notes, and snippets.

@ruario
Created March 22, 2014 19:34
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 ruario/9713031 to your computer and use it in GitHub Desktop.
Save ruario/9713031 to your computer and use it in GitHub Desktop.
Extracts rpms to similarly named directories, using only bash, grep, tail, cpio and a decompressor
#!/bin/bash
mkdir -p ${1%.rpm} || exit 1
RPMHDRLGTH=$(LANG=C grep -abom1 '.7zXZ\|]'$'\000\000''....'$'\377\377\377\377\377\377''\|BZh9\|'$'\037\213\b' "$1")
case "$RPMHDRLGTH" in
*7zXZ) COMPRESSOR=xz ;;
*]*) COMPRESSOR=lzma ;;
*BZh9) COMPRESSOR=bzip2 ;;
*) COMPRESSOR=gzip ;;
esac
tail -c+$[${RPMHDRLGTH%:*}+1] "$1" | $COMPRESSOR -d | ( cd ${1%*.rpm} ; cpio --quiet -imd )
@ruario
Copy link
Author

ruario commented Jun 1, 2014

Just some notes. This assumes GNU tools. Additionally it will not work with rpm5.org rpm's that use xar instead of cpio internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment