xref: /freebsd/usr.bin/gzip/zforce (revision 2a58b312b62f908ec92311d1bd8536dbaeb8e55b)
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#
21# $FreeBSD$
22prog=`basename $0`
23USAGE="usage: $prog file ..."
24if test $# -eq 0; then
25	echo $USAGE
26	exit 1
27fi
28
29ret=0
30
31while test $# -ne 0; do
32	case "$1" in
33		*[._-]gz)
34			shift
35			;;
36		*.t[ag]z)
37			shift
38			;;
39		*)
40			if file "$1" |
41				grep -q "gzip compressed data" 2> /dev/null
42			then
43				n="$1".gz
44				if mv "$1" "$n" 2> /dev/null; then
45					echo "$1" -- renamed to "$n"
46				else
47					ret=1
48					echo $prog: cannot rename "$1" to "$n"
49				fi
50			fi
51			shift
52			;;
53	esac
54done
55exit $ret
56