home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / mtools_3.6.src.lzh / MTOOLS_3.6 / SCRIPTS / uz < prev    next >
Text File  |  1997-11-12  |  1KB  |  62 lines

  1. #!/bin/sh
  2. # uz [file...]
  3. # lz [file...]
  4. #
  5. # If called "uz", gunzips and extracts a gzip'd tar'd archive.
  6. # If called "lz", gunzips and shows a listing of a gzip'd tar'd archive.
  7. #
  8. # Requires: gzip and tar in the user's path.  Should work with most tars.
  9. # "-" is now used for backwards compatibility with antique tars, e.g. SCO.
  10. #
  11. # 1994/02/19    DCN    Created (as a trivial, but useful script)
  12. # 1994/12/01    DCN    Combined uz and lz, added suffix handling
  13. #
  14. # Copyright (C) 1994 David C. Niemi (niemidc@erols.com)
  15. # The author requires that any copies or derived works include this
  16. # copyright notice; no other restrictions are placed on its use.
  17. #
  18.  
  19. set -e
  20. set -u
  21.  
  22. case $0 in
  23. *uz)
  24.     tarparam="-pxvf"
  25.     action="Extracting from "
  26.     ;;
  27. *lz)
  28.     tarparam="-tvf"
  29.     action="Reading directory of "
  30.     ;;
  31. *)
  32.     echo "$0: expect to be named either \"uz\" or \"lz\"." >&2
  33.     exit 1
  34.     ;;
  35. esac
  36.  
  37. if [ $# = 0 ]; then
  38.     echo "$action standard input." >&2
  39.     gzip -cd - | tar "$tarparam" -
  40.     exit 0
  41. fi
  42.  
  43. while [ $# -ge 1 ]; do
  44.     echo >&2
  45.     found=
  46.     for suffix in "" .gz .tgz .tar.gz .z .tar.z .taz .tpz .Z .tar.Z ; do
  47.         if [ -r "${1}$suffix" ]; then
  48.             found=$1$suffix;
  49.             break;
  50.         fi
  51.     done
  52.     if [ -z "$found" ]; then
  53.         echo "$0: could not read \"$1\"." >&2
  54.     else
  55.         echo "$action \"$found\"." >&2
  56.         gzip -cd -- "$found" | tar "$tarparam" -
  57.     fi
  58.     shift
  59. done
  60.  
  61. exit 0
  62.