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 8PATH="/usr/bin:$PATH"; export PATH 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 27 if gzip -l < "$i" 2>/dev/null | grep '^defl' > /dev/null; then 28 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 39 fi 40done 41exit $res 42