X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gzexe.in;h=bcd788c671450699d990ed548464ad5614ea22a6;hb=0161769885b1bdcc3d5f6699ade8f2b88c56e570;hp=b7a0cf4c260495553447721350e7ed94d0937910;hpb=302189d124ed5849c2589ea92e912eb24fdc4ab3;p=gzip diff --git a/gzexe.in b/gzexe.in index b7a0cf4..bcd788c 100755 --- a/gzexe.in +++ b/gzexe.in @@ -13,6 +13,27 @@ # The : is required for some old versions of csh. # On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5 + +# Copyright (C) 1998, 2002 Free Software Foundation +# Copyright (C) 1993 Jean-loup Gailly + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + + +PATH="BINDIR:$PATH" x=`basename $0` if test $# = 0; then echo compress executables. original file foo is renamed to foo~ @@ -21,8 +42,10 @@ if test $# = 0; then exit 1 fi +set -C tmp=gz$$ -trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15 +trap "rm -f $tmp; exit 1" HUP INT QUIT TRAP USR1 PIPE TERM +: > $tmp || exit 1 decomp=0 res=0 @@ -32,8 +55,8 @@ if test "x$1" = "x-d"; then shift fi -echo hi > zfoo1$$ -echo hi > zfoo2$$ +echo hi > zfoo1$$ || exit 1 +echo hi > zfoo2$$ || exit 1 if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then cpmod=${CPMOD-cpmod} fi @@ -53,6 +76,9 @@ if test -z "$tail"; then echo cannot find tail exit 1 fi +case `echo foo | $tail -n +1 2>/dev/null` in +foo) tail="$tail -n";; +esac for i do if test ! -f "$i" ; then @@ -75,7 +101,7 @@ for i do continue fi case "`basename $i`" in - gzip | tail | chmod | ln | sleep | rm) + gzip | tail | sed | chmod | ln | sleep | rm) echo "${x}: $i would depend on itself"; continue ;; esac if test -z "$cpmod"; then @@ -86,26 +112,28 @@ for i do writable=0 chmod u+w $tmp 2>/dev/null fi + : >| $tmp # truncate the file, ignoring set -C fi if test $decomp -eq 0; then - sed 1q $0 > $tmp + sed 1q $0 >> $tmp sed "s|^if tail|if $tail|" >> $tmp <<'EOF' -skip=22 +skip=23 set -C umask=`umask` umask 77 -if tail +$skip $0 | "BINDIR"/gzip -cd > /tmp/gztmp$$; then +tmpfile=`tempfile -p gztmp -d /tmp` || tmpfile=/tmp/gztmp.$$ || exit 1 +if tail +$skip "$0" | /bin/gzip -cd >> $tmpfile; then umask $umask - /bin/chmod 700 /tmp/gztmp$$ + /bin/chmod 700 $tmpfile prog="`echo $0 | /bin/sed 's|^.*/||'`" - if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then - trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0 - (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null & + if /bin/ln $tmpfile "/tmp/$prog" 2>/dev/null; then + trap '/bin/rm -f $tmpfile "/tmp/$prog"; exit $res' 0 + (/bin/sleep 5; /bin/rm -f $tmpfile "/tmp/$prog") 2>/dev/null & /tmp/"$prog" ${1+"$@"}; res=$? else - trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0 - (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null & - /tmp/gztmp$$ ${1+"$@"}; res=$? + trap '/bin/rm -f $tmpfile; exit $res' 0 + (/bin/sleep 5; /bin/rm -f $tmpfile) 2>/dev/null & + $tmpfile ${1+"$@"}; res=$? fi else echo Cannot decompress $0; exit 1 @@ -120,7 +148,7 @@ EOF else # decompression - skip=22 + skip=23 if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then eval `sed -e 1d -e 2q "$i"` fi