unrpm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. #
  3. # This should work with the GNU version of cpio and gzip!
  4. # This should work with the bash or ash shell!
  5. # Requires the programs (cpio, gzip, and the pager more or less).
  6. #
  7. usage() {
  8. cat <<EOF
  9. Usage: unrpm -l package.rpm <List contents of rpm package>
  10. unrpm -x package.rpm /foo/boo <Extract rpm package to this directory,
  11. put . for current directory>
  12. EOF
  13. exit
  14. }
  15. rpm=$2
  16. exist() {
  17. if [ -z "${rpm}" ]; then
  18. usage
  19. elif [ ! -s "${rpm}" ]; then
  20. echo "Can't find ${rpm}!"
  21. exit 1
  22. fi
  23. }
  24. if [ -z "$1" ]; then
  25. usage
  26. elif [ "$1" = "-l" ]; then
  27. exist
  28. type more >/dev/null 2>&1 && pager=more
  29. type less >/dev/null 2>&1 && pager=less
  30. [ "$pager" = "" ] && echo "No pager found!" && exit
  31. (
  32. printf "\nPress enter to scroll, q to Quit!\n\n"
  33. rpm2cpio "${rpm}" | cpio -tv --quiet
  34. ) | ${pager}
  35. exit
  36. elif [ "$1" = "-x" ]; then
  37. exist
  38. if [ -z "$3" ]; then
  39. usage
  40. elif [ ! -d "$3" ]; then
  41. echo "No such directory $3!"
  42. exit 1
  43. fi
  44. rpm2cpio "${rpm}" | (umask 0 ; cd "$3" ; cpio -idmuv) || exit
  45. echo
  46. echo "Extracted ${rpm} to $3!"
  47. exit
  48. else
  49. usage
  50. fi