Use "gzip -lv", not "gzip -v". Patch by Ralf Neubauer.
[debian/gzip] / zforce.in
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
10 # Copyright (C) 2002 Free Software Foundation
11 # Copyright (C) 1993 Jean-loup Gailly
12
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
16 # any later version.
17
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 # 02111-1307, USA.
27
28
29 PATH="BINDIR:$PATH"; export PATH
30 x=`basename $0`
31 if test $# = 0; then
32   echo "force a '.gz' extension on all gzip files"
33   echo usage: $x files...
34   exit 1
35 fi
36
37 res=0
38 for i do
39   if test ! -f "$i" ; then
40     echo ${x}: $i not a file
41     res=1
42     continue
43   fi
44   test `expr "$i" : '.*[.-]z$'` -eq 0 || continue
45   test `expr "$i" : '.*[.-]gz$'` -eq 0 || continue
46   test `expr "$i" : '.*[.]t[ag]z$'` -eq 0 || continue
47
48   if gzip -lv < "$i" 2>/dev/null | grep '^defl' > /dev/null; then
49
50     if test `expr "$i" : '^............'` -eq 12; then
51       new=`expr "$i" : '\(.*\)...$`.gz
52     else
53       new="$i.gz"
54     fi
55     if mv "$i" "$new" 2>/dev/null; then
56       echo $i -- replaced with $new
57       continue
58     fi
59     res=1; echo ${x}: cannot rename $i to $new
60   fi
61 done
62 exit $res