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 / tgz < prev    next >
Text File  |  1997-11-12  |  2KB  |  71 lines

  1. #!/bin/sh
  2. #
  3. # tgz [destination [source...] ]
  4. #
  5. # Make a gzip'd tar archive $1 (or stdout) out of specified files
  6. # (or, if not specified, from everything in the current directory)
  7. #
  8. # Requires gzip in the user's path.
  9. #
  10. # Requires gnu tar (or something close) in the user's path
  11. # due to use of --exclude, --totals and -S.
  12. #
  13. # 1994/02/19    DCN    Created
  14. # 1994/12/01    DCN    Cleanup and major improvements
  15. #
  16. # Copyright (C) 1994 David C. Niemi (niemidc@erols.com)
  17. # The author requires that any copies or derived works include this
  18. # copyright notice; no other restrictions are placed on its use.
  19. #
  20.  
  21. set -e
  22. set -u
  23.  
  24. Error ()
  25. {    echo "Error: $0: ${@-}." >&2
  26.     exit 1
  27. }
  28.  
  29. if [ $# = 0 ]; then
  30.     dest=
  31.     src=.
  32.     tar cvf - . | gzip -9v
  33.     exit 0
  34. elif [ $# = 1 ]; then
  35.     dest=$1
  36.     src=.
  37. else
  38.     dest=$1
  39.     shift
  40.     src="${@-}"
  41. fi
  42.  
  43. case $dest in
  44. "" | . | .. | */ | */. | */.. )
  45.     echo "Usage: $0: [destination [source...] ]" >&2
  46.     exit 1
  47.     ;;
  48. *.t?z | *.?z | *.z | *.Z | *.tz | *.tz? )
  49.     ;;
  50. *)
  51.     dest=${dest}.tgz    ## Add on .tgz as default suffix
  52. esac
  53.  
  54. if [ -h "$dest" ]; then
  55.     Error "Destination file \"$dest\" already exists as a symbolic link"
  56. elif [ -f "$dest" ]; then
  57.     Error "Destination \"$dest\" already exists as a file"
  58. elif [ -d "$dest" ]; then
  59.     Error "Destination \"$dest\" already exists as a directory"
  60. fi
  61. if [ -z "$dest" -o "X$dest" = 'X-' ]; then
  62.     echo "Writing gzipp'd tar archive to standard output." >&2
  63.     tar cvfS - -- $src | gzip -9v
  64. else
  65.     echo "Writing gzip'd tar archive to \"$dest\"." >&2
  66.     tar -cvS --totals --exclude "$dest" -f - -- $src | gzip -9v > "$dest" 
  67.     ls -l "$dest" >&2
  68. fi
  69.  
  70. exit 0
  71.