xref: /freebsd/usr.bin/gzip/zforce (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
1#!/bin/sh -
2#
3# $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
4# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
5#
6#-
7# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
8#
9# Permission to use, copy, modify, and distribute this software for any
10# purpose with or without fee is hereby granted, provided that the above
11# copyright notice and this permission notice appear in all copies.
12#
13# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20#
21prog=`basename $0`
22USAGE="usage: $prog file ..."
23if test $# -eq 0; then
24	echo $USAGE
25	exit 1
26fi
27
28ret=0
29
30while test $# -ne 0; do
31	case "$1" in
32		*[._-]gz)
33			shift
34			;;
35		*.t[ag]z)
36			shift
37			;;
38		*)
39			if file "$1" |
40				grep -q "gzip compressed data" 2> /dev/null
41			then
42				n="$1".gz
43				if mv "$1" "$n" 2> /dev/null; then
44					echo "$1" -- renamed to "$n"
45				else
46					ret=1
47					echo $prog: cannot rename "$1" to "$n"
48				fi
49			fi
50			shift
51			;;
52	esac
53done
54exit $ret
55