Created
April 10, 2016 05:01
-
-
Save Tatsh/fca0dc3fcefddc24bcf86282d671da78 to your computer and use it in GitHub Desktop.
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
if ! command -v rpmunpack >/dev/null 2>&1; then | |
# For OS X | |
# Credit http://stackoverflow.com/a/27694039 | |
__rpm2cpio_data() { | |
local -r rpm="$1" | |
local -r leadsize=96 | |
local -r brpm=$(basename "${rpm%.*}") | |
local o=$((leadsize + 8)) | |
local headersize= | |
local extractor= | |
local compression= | |
local decompressor= | |
# shellcheck disable=SC2046 | |
set $(od -j "$o" -N 8 -t u1 "$rpm") | |
il=$((256 * (256 * (256 * $2 + $3) + $4) + $5)) | |
dl=$((256 * (256 * (256 * $6 + $7) + $8) + $9)) | |
sigsize=$((8 + 16 * il + dl)) | |
o=$((o + sigsize + (8 - (sigsize % 8)) % 8 + 8)) | |
# shellcheck disable=SC2046 | |
set $(od -j "$o" -N 8 -t u1 "$rpm") | |
il=$((256 * (256 * (256 * $2 + $3) + $4) + $5)) | |
dl=$((256 * (256 * (256 * $6 + $7) + $8) + $9)) | |
headersize=$((8 + 16 * il + dl)) | |
o=$((o + headersize)) | |
extractor="dd if=$rpm ibs=$o skip=1" | |
compression=$($extractor | file -) | |
decompressor=cat | |
case "$compression" in | |
*gzip*|*GZIP*) | |
decompressor=gunzip | |
;; | |
*bzip2*|*BZIP2*) | |
decompressor=bunzip2 | |
;; | |
*xz*|*XZ) | |
decompressor=unxz | |
;; | |
*cpio*|*CPIO*) | |
;; | |
*) | |
if command -v lzmash >/dev/null 2>&1; then | |
decompressor='lzmash -d -c' | |
else | |
return 1 | |
fi | |
;; | |
esac | |
$extractor 2>/dev/null | $decompressor | |
} | |
rpmunpack() { | |
local -r rpm="$1" | |
local -r brpm=$(basename "${rpm%.*}") | |
__rpm2cpio_data "$1" > "${brpm}.cpio" | |
mkdir "$brpm" | |
cd "$brpm" | |
cpio -idmv < "../${brpm}.cpio" | |
cd .. | |
rm -f "${brpm}.cpio" | |
} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment