Skip to content

Instantly share code, notes, and snippets.

@dcode
Created March 30, 2015 17:05
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 dcode/798a9c69aa5076238a92 to your computer and use it in GitHub Desktop.
Save dcode/798a9c69aa5076238a92 to your computer and use it in GitHub Desktop.
rpm2cpio shell script
You just need to save that to rpm2cpio.sh, make it executable, and then
run
rpm2cpio rpm-4.1.1-1.7x.src.rpm | cpio -idv
Source: http://www.redhat.com/archives/rpm-list/2003-June/msg00367.html
#!/bin/sh
pkg=$1
if [ "$pkg" = "" -o ! -e "$pkg" ]; then
echo "no package supplied" 1>&2
exit 1
fi
leadsize=96
o=`expr $leadsize + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
sigsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
hdrsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $hdrsize`
dd if=$pkg ibs=$o skip=1 2>/dev/null | gunzip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment