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