Finish commit of rpmunpack and add in scripts for undeb and unrpm
[oweals/busybox.git] / examples / unrpm
1 #!/bin/sh
2 #
3 usage() {
4 echo "Usage: unrpm -l package.rpm            <List contents of rpm package>"
5 echo "       unrpm -x package.rpm /foo/boo   <Extract rpm package to this directory,"
6 echo "                                        put . for current directory>"  
7 exit
8 }
9
10 rpm=$2
11  
12 exist() {
13 if [ "$rpm" = "" ]; then
14 usage
15 elif [ ! -s "$rpm" ]; then
16 echo "Can't find $rpm!"
17 exit
18 fi
19 }
20
21 if [ "$1" = "" ]; then
22 usage
23 elif [ "$1" = "-l" ]; then
24 exist
25 type more >/dev/null 2>&1 && pager=more
26 type less >/dev/null 2>&1 && pager=less
27 (echo -e "\nPress enter to scroll, q to Quit!\n" ; rpmunpack < $rpm | gunzip -c | cpio -tvf --quiet) | $pager 
28 exit
29 elif [ "$1" = "-x" ]; then
30 exist
31 if [ "$3" = "" ]; then
32 usage
33 elif [ ! -d "$3" ]; then
34 echo "No such directory $3!"
35 exit
36 fi
37 rpmunpack < $rpm | gunzip | (cd $3 ; cpio -idmuv) || exit 
38 echo
39 echo "Extracted $rpm to $3!"
40 exit
41 else
42 usage
43 fi