Last active
September 5, 2021 06:28
-
-
Save ruario/9674124 to your computer and use it in GitHub Desktop.
Minimal rpm2cpio using only bash, grep, tail and a decompressor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RPMHDRLGTH=$(LC_CTYPE=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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above still assumes a GNU toolset. This should work on both GNU and BSD systems and even BusyBox.
I shall leave it as an exercise as to what I am doing here and why this looks unnecessarily complex. (spoiler: it isn't) 😉