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