home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / gzip124.zip / gzip-1.2.4 / zforce.in < prev    next >
Text File  |  1993-06-11  |  1KB  |  43 lines

  1. :
  2. #!/bin/sh
  3. # zforce: force a gz extension on all gzip files so that gzip will not
  4. # compress them twice.
  5. #
  6. # This can be useful for files with names truncated after a file transfer.
  7. # 12345678901234 is renamed to 12345678901.gz
  8.  
  9. PATH="BINDIR:$PATH"; export PATH
  10. x=`basename $0`
  11. if test $# = 0; then
  12.   echo "force a '.gz' extension on all gzip files"
  13.   echo usage: $x files...
  14.   exit 1
  15. fi
  16.  
  17. res=0
  18. for i do
  19.   if test ! -f "$i" ; then
  20.     echo ${x}: $i not a file
  21.     res=1
  22.     continue
  23.   fi
  24.   test `expr "$i" : '.*[.-]z$'` -eq 0 || continue
  25.   test `expr "$i" : '.*[.-]gz$'` -eq 0 || continue
  26.   test `expr "$i" : '.*[.]t[ag]z$'` -eq 0 || continue
  27.  
  28.   if gzip -l < "$i" 2>/dev/null | grep '^defl' > /dev/null; then
  29.  
  30.     if test `expr "$i" : '^............'` -eq 12; then
  31.       new=`expr "$i" : '\(.*\)...$`.gz
  32.     else
  33.       new="$i.gz"
  34.     fi
  35.     if mv "$i" "$new" 2>/dev/null; then
  36.       echo $i -- replaced with $new
  37.       continue
  38.     fi
  39.     res=1; echo ${x}: cannot rename $i to $new
  40.   fi
  41. done
  42. exit $res
  43.