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