Contribute  :  Web Resources  :  Past Polls  :  Site Statistics  :  Downloads  :  Forum  
    BiW ReversingThe challenge is yours    
 Welcome to BiW Reversing
 Monday, October 25 2021 @ 10:34 AM CEST

extracting a single file from a rpm package to user directory


CodingLevel : newbie

OS : linux
Language : shell script

linux is in endless development so there obviously is a pretty big stream of
patches updates and stuff and after a while you will get used to searching
through those cvs archieves rpm archieves etc

now assuming you are root installing a downloaded rpm package is very easy
but if you are not root and you still want to look what is inside the package
or want to extract a single file its a pain in the ass the first time around
you would have to google around through that endless maze of same useless
information mirrored on million sites around the universe which would never
yield any working information and you would end up doing man -k rpm info rpm
rpm --help | more stuff all by yourself thousand times
and would atlast find a very mucky way out

well i posted my experiance and ranting above :)
now the other day i downloaded an .rpm
then i did
rpm -qlp file.rpm |more to confirm if the intended file existed in that package
now rpm doesnt have a single file extraction mechanism ( i got that after reading
info rpm for about 1000 times ) so it was back to google again
and after scouring around i found that there exist another one
called rpm2cpio

now doing info rpm2cpio and scouring around google i found that i have to pipe the .rpm in to rpm2cpio
then pass it as input to cpio
to extract the whole directory
and then navigate through the whole
directory structure by cd cd cd (yeah i can autocomplete the path still it doesnt
count dont i have to hit tab key ??)
well enough rant now :)

i present a simple bash script that would automate the whole stuff

rpm2cpio $1 | cpio -t 2>/dev/null | grep $2 | while read a ; do rpm2cpio $1 | cpio -idmur $a 2>/dev/null ; done

save the above snippet as
do chmod 700 to make it executable
run that script and pass two arguments to it
the package name and the file name you want to extract
like this

./ binutils-debuginfo- macro
rename ./usr/src/debug/binutils- -> macro.c
rename ./usr/src/debug/binutils- -> macro.h

the rename is interactive renaming
the script will stop execution
till you type a name and continue executing after you typed in a name

an example usage shown below

someone@server:~/myfirst/myfirstasm/test/rpmextract> ls

someone@server:~/myfirst/myfirstasm/test/rpmextract> ./ binutils-debuginfo- macro

rename ./usr/src/debug/binutils- -> macro.c
rename ./usr/src/debug/binutils- -> macro.h

someone@server:~/myfirst/myfirstasm/test/rpmextract> ls
binutils-debuginfo-  macro.c  macro.h
hope it was usefull

thanks to Detten for his server usage
and thanks to cy_`at #social@ptp for helping me with this script

thanks and regards


What's Related

Story Options

extracting a single file from a rpm package to user directory | 1 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
extracting a single file from a rpm package to user directory
Authored by: detten on Friday, December 16 2005 @ 12:12 PM CET
Nice little script :)
Since I mainly use ArchLinux ( a distribution that doesn't use rpm / tgz /deb packages), I have to manually extract files from rpm's from time to time without wanting to actually install the files to eg. /usr dir as root.

I do something like this to locally extract the entire rpm :

rpmunpack < somepackage.rpm | gzip -d | cpio -i dmuv

To look at the file list first change the '-i' to '-t' in cpio command, to extract some file(s) only I use cpio's -E switch like this :

rpmunpack < somepackage.rpm | gzip -d | cpio -i dmuv -E filename
 Copyright © 2021 BiW Reversing
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.82 seconds