3
0

undeb 1.3 KB

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