Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/gzip import openbsd z* scripts and manuals.



details:   https://anonhg.NetBSD.org/src/rev/2e81a9c3a5c7
branches:  trunk
changeset: 556817:2e81a9c3a5c7
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Dec 28 12:31:55 2003 +0000

description:
import openbsd z* scripts and manuals.

diffstat:

 usr.bin/gzip/gzexe    |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/gzip/gzexe.1  |   71 ++++++++++++++++++++
 usr.bin/gzip/zdiff    |  108 ++++++++++++++++++++++++++++++
 usr.bin/gzip/zdiff.1  |  106 +++++++++++++++++++++++++++++
 usr.bin/gzip/zforce   |   52 ++++++++++++++
 usr.bin/gzip/zforce.1 |   51 ++++++++++++++
 usr.bin/gzip/zmore    |   72 ++++++++++++++++++++
 usr.bin/gzip/zmore.1  |   92 +++++++++++++++++++++++++
 usr.bin/gzip/znew     |  135 ++++++++++++++++++++++++++++++++++++++
 usr.bin/gzip/znew.1   |   69 +++++++++++++++++++
 10 files changed, 933 insertions(+), 0 deletions(-)

diffs (truncated from 973 to 300 lines):

diff -r 5e1a2689cc99 -r 2e81a9c3a5c7 usr.bin/gzip/gzexe
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/gzip/gzexe        Sun Dec 28 12:31:55 2003 +0000
@@ -0,0 +1,177 @@
+#!/bin/sh -
+#
+# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
+#
+#  Copyright (c) 2003 Otto Moerbeek <otto%drijf.net@localhost>
+#
+#  Permission to use, copy, modify, and distribute this software for any
+#  purpose with or without fee is hereby granted, provided that the above
+#  copyright notice and this permission notice appear in all copies.
+#
+#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+# The number of lines plus one in the on-the-fly decompression script
+lines=19
+
+# A simple string to recognize already compressed files
+magic="# compressed by gzexe"
+
+# Write the decompression script to stdout
+header () {
+       typeset prog tmp
+       # first section needs variable expansion, second not
+       cat <<- EOF
+               #!/bin/sh -
+               $magic
+               lines=$lines
+       EOF
+       cat <<- 'EOF'
+               prog=`/usr/bin/basename "$0"`
+               tmp=`/usr/bin/mktemp -d /tmp/gzexeXXXXXXXXXX` || {
+                       /bin/echo "$prog: cannot create tmp dir"; exit 1
+               }
+               trap '/bin/rm -rf "$tmp"' 0
+               if /usr/bin/tail +$lines "$0" |
+                   /usr/bin/gzip -dc > "$tmp/$prog" 2> /dev/null; then
+                       /bin/chmod u+x "$tmp/$prog"
+                       "$tmp/$prog" ${1+"$@"}
+                       ret=$?
+               else
+                       /bin/echo "$prog: cannot decompress $0"
+                       ret=1
+               fi
+               exit $ret
+       EOF
+}
+
+# Test if a file is compressed by checking the magic line
+compressed () {
+       test "X`sed -n 2p "$1" 2> /dev/null`" = "X$magic"
+}
+
+# Decompress a file
+decompress () {
+       tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
+               echo "$prog: cannot create tmp file"
+               return 1
+       }
+       if ! cp "$1" "$tmp"; then
+               echo "$prog: cannot copy $1 to $tmp"
+               rm -f "$tmp"
+               return 1
+       fi
+       if ! tail +$lines "$tmp" | gzip -vdc > "$1"; then
+               echo "$prog: cannot decompress $1"
+               cp "$tmp" "$1"
+               rm -f "$tmp"
+               return 1
+       fi
+}
+
+# Perform some sanity checks on the file
+check () {
+       if test ! -e "$1"; then
+               echo "$prog: cannot compress non-existing file $1"
+               return 1
+       fi
+
+       if test ! -f "$1"; then
+               echo "$prog: cannot compress non-regular file $1"
+               return 1
+       fi
+
+       case `basename "$1"` in
+               sh | mktemp | rm | echo | tail | gzip | chmod)
+                       echo "$prog: cannot compress $1, I depend on it"
+                       return 1
+       esac
+
+       if test ! -x "$1"; then
+               echo "$prog: cannot compress $1, it is not executable"
+               return 1
+       fi
+
+       if test -u "$1" -o -g "$1"; then
+               echo "$prog: cannot compress $1, it has an s bit set"
+               return 1
+       fi
+}
+
+# Compress a file
+compress () {
+       tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
+               echo "$prog: cannot create tmp file"
+               return 1
+       }
+       if ! cp "$1" "$tmp"; then
+               echo "$prog: cannot copy $1 to $tmp"
+               rm -f "$tmp"
+               return 1
+       fi
+       if ! cp "$1" "$1"~; then
+               echo "$prog: cannot create backup copy $1~"
+               rm -f "$1"~ "$tmp"
+               return 1
+       fi
+
+       # Use cp to overwrite the existing file preserving mode and owner
+       # if possible. If the file is not writable, this will produce an
+       # error.
+
+       if header "$1" > "$tmp" && gzip -vc "$1" >> "$tmp"; then
+               if ! cp "$tmp" "$1"; then
+                       echo "$prog: cannot copy $tmp to $1"
+                       rm -f "$tmp"
+                       return 1
+               fi
+       else
+               echo "$prog: cannot compress $1"
+               rm -f "$1"~ "$tmp"
+               return 1
+       fi
+}
+
+# Is the -d flag specified?
+dflag=
+
+# Return value
+rc=0
+
+if test "X$1" = X-d; then
+       dflag=1
+       shift
+fi
+
+prog=`basename "$0"`
+USAGE="usage: $prog [-d] file ..."
+if test $# -eq 0; then
+       echo $USAGE
+       exit 1
+fi
+
+while test $# -ne 0; do
+       if test $dflag; then
+               if ! compressed "$1"; then
+                       echo "$prog: $1 is not compressed"
+                       rc=1;
+               elif ! decompress "$1"; then
+                       rc=$?
+               fi
+       else
+               if compressed "$1"; then
+                       echo "$prog: $1 is already compressed"
+                       rc=1;
+               elif ! check "$1" || ! compress "$1"; then
+                       rc=$?
+               fi
+       fi
+       shift
+done
+exit $rc
diff -r 5e1a2689cc99 -r 2e81a9c3a5c7 usr.bin/gzip/gzexe.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/gzip/gzexe.1      Sun Dec 28 12:31:55 2003 +0000
@@ -0,0 +1,71 @@
+.\"    $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
+.\"
+.\" Copyright (c) 2003 Otto Moerbeek <otto%drijf.net@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd July 30, 2003
+.Dt GZEXE 1
+.Os
+.Sh NAME
+.Nm gzexe
+.Nd create auto-decompressing executables
+.Sh SYNOPSIS
+.Nm gzexe
+.Op Fl d
+.Ar
+.Sh DESCRIPTION
+The
+.Nm
+utility uses
+.Xr gzip 1
+to compress executables, producing executables that decompress on-the-fly
+when executed.
+This saves disk space, at the cost of slower execution times.
+The original executables are saved by copying each of them to a file with
+the same name with a
+.Sq ~
+suffix appended.
+After verifying that the compressed executables work as expected, the backup
+files can be removed.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl d
+Decompress executables previously compressed by
+.Nm gzexe .
+.El
+.Pp
+The
+.Nm
+program refuses to compress non-regular or non-executable files,
+files with a setuid or setgid bit set, files that are already
+compressed using
+.Nm
+or programs it needs to perform on-the-fly decompression:
+.Xr sh 1 ,
+.Xr mktemp 1 ,
+.Xr rm 1 ,
+.Xr echo 1 ,
+.Xr tail 1 ,
+.Xr gzip 1
+and
+.Xr chmod 1 .
+.Sh SEE ALSO
+.Xr gzip 1
+.Sh CAVEATS
+The
+.Nm
+utility replaces files by overwriting them with the generated
+compressed executable.
+To be able to do this, it is required that the original files are writable.
diff -r 5e1a2689cc99 -r 2e81a9c3a5c7 usr.bin/gzip/zdiff
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/gzip/zdiff        Sun Dec 28 12:31:55 2003 +0000
@@ -0,0 +1,108 @@
+#!/bin/sh -
+#
+# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
+#
+# Copyright (c) 2003 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Sponsored in part by the Defense Advanced Research Projects
+# Agency (DARPA) and Air Force Research Laboratory, Air Force
+# Materiel Command, USAF, under agreement number F39502-99-1-0512.
+#
+
+# Set $prog based on $0
+case $0 in
+       *cmp)   prog=cmp
+               ;;
+       *)      prog=diff
+               ;;
+esac
+USAGE="usage: z$prog [options] file1 [file2]"
+
+# Pull out any command line flags so we can pass them to diff/cmp
+# XXX - assumes there is no optarg
+flags=
+while test $# -ne 0; do
+       case "$1" in
+               --)
+                       shift
+                       break



Home | Main Index | Thread Index | Old Index