gzexe: ensure file always exists
[gzip.git] / zforce.in
blobf0ff71ca3cc9048df6d05afb7691a65c184806d8
1 #!/bin/sh
2 # zforce: force a gz extension on all gzip files so that gzip will not
3 # compress them twice.
5 # This can be useful for files with names truncated after a file transfer.
6 # 12345678901234 is renamed to 12345678901.gz
9 # Copyright (C) 2002, 2007, 2010-2017 Free Software Foundation, Inc.
10 # Copyright (C) 1993 Jean-loup Gailly
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with this program; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 version="zforce (gzip) @VERSION@
27 Copyright (C) 2010-2017 Free Software Foundation, Inc.
28 This is free software. You may redistribute copies of it under the terms of
29 the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
30 There is NO WARRANTY, to the extent permitted by law.
32 Written by Jean-loup Gailly."
34 usage="Usage: $0 [FILE]...
35 Force a .gz extension on all compressed FILEs so that gzip will
36 not compress them twice.
38 Report bugs to <bug-gzip@gnu.org>."
40 if test $# = 0; then
41 printf >&2 '%s\n' "$0: invalid number of operands; try \`$0 --help' for help"
42 exit 1
45 res=0
46 for i do
47 case "$i" in
48 --h*) printf '%s\n' "$usage" ; exit;;
49 --v*) printf '%s\n' "$version"; exit;;
50 *[-.]z | *[-.]gz | *.t[ag]z) continue;;
51 esac
53 if test ! -f "$i" ; then
54 printf '%s\n' "zforce: $i not a file"
55 res=1
56 continue
59 if gzip -lv < "$i" 2>/dev/null | grep '^defl' > /dev/null; then
61 new="$i.gz"
62 if mv "$i" "$new"; then
63 printf '%s\n' "$i -- replaced with $new"
64 else
65 res=$?
68 done
69 exit $res