3 # $NetBSD: znew,v 1.3 2008/04/27 09:07:13 nakayama Exp $
4 # $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
6 # Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
8 # Permission to use, copy, modify, and distribute this software for any
9 # purpose with or without fee is hereby granted, provided that the above
10 # copyright notice and this permission notice appear in all copies.
12 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 # Return 0 if the first arg file size is smaller than the second, 1 otherwise.
23 a
=`du -k "$1" | awk '{ print $1 }'`
24 b
=`du -k "$2" | awk '{ print $1 }'`
28 # Check gzip integrity if the -t flag is specified
30 if test $tflag -eq 1; then
35 # Decompress a file and then gzip it
41 if test ! -e "$filez"; then
42 echo "$prog: $filez does not exist"
45 if test ! -f "$filez"; then
46 echo "$prog: $filez is not a regular file"
49 if test -e "$filegz" -a $fflag -eq 0; then
50 echo "$prog: $filegz already exists"
54 tmp
=`mktemp /tmp/znewXXXXXXXXXX` ||
{
55 echo "$prog: cannot create tmp file"
58 trap 'rm -f "$tmp"; exit 1' HUP INT QUIT PIPE TERM
60 # Do the actual work, producing a file "$tmp"
61 if uncompress -f -c < "$filez" |
gzip -f $gzipflags > "$tmp"; then
63 if test $kflag -eq 1 && smaller
"$filez" "$tmp"; then
64 echo -n "$prog: $filez is smaller than $filegz"
69 if ! checkfile
"$tmp"; then
70 echo "$prog: integrity check of $tmp failed"
75 # Try to keep the mode of the original file
76 if ! cp -fp "$filez" "$filegz"; then
77 echo "$prog: warning: could not keep mode of $filez"
79 if ! cp "$tmp" "$filegz" 2> /dev
/null
; then
80 echo "$prog: warning: could not keep mode of $filez"
81 if ! cp -f "$tmp" "$filegz" 2> /dev
/null
; then
82 echo "$prog: could not copy $tmp to $filegz"
83 rm -f "$filegz" "$tmp"
87 if ! touch -fr "$filez" "$filegz"; then
88 echo -n "$prog: warning: could not keep timestamp of "
93 echo "$prog: failed to process $filez"
100 usage
="usage: $prog [-9fKtv] file ..."
107 # -P flag is recognized to maintain compatibility, but ignored. Pipe mode is
109 while getopts :ftv9PK i
; do
113 v
) gzipflags
="-v $gzipflags";;
114 9) gzipflags
="-9 $gzipflags";;
117 \?) echo "$usage"; exit 1;;
121 shift $
((OPTIND
- 1))
123 if test $# -eq 0; then
130 while test $# -ne 0; do
131 if ! process
"$1"; then