]> git.cworth.org Git - gzip/blobdiff - gzexe.in
Imported Debian patch 1.3.5-10
[gzip] / gzexe.in
index b67e92e6c0c6c863fdba9968eb4ea9d1b2d63883..d1916356c9ae9ae3b258eea47ad9359269d362ae 100755 (executable)
--- a/gzexe.in
+++ b/gzexe.in
 # The : is required for some old versions of csh.
 # On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
 
-x=`basename "$0"`
+
+# 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~
   echo usage: ${x} [-d] files...
@@ -21,6 +42,11 @@ if test $# = 0; then
   exit 1
 fi
 
+set -C
+tmp=gz$$
+trap "rm -f $tmp; exit 1" HUP INT QUIT TRAP USR1 PIPE TERM
+: > $tmp || exit 1
+
 decomp=0
 res=0
 test "$x" = "ungzexe" && decomp=1
@@ -29,10 +55,12 @@ if test "x$1" = "x-d"; then
   shift
 fi
 
-cpmod=
-if type ${CPMOD:-cpmod} 2>/dev/null; then
-  cpmod=${CPMOD:-cpmod}
+echo hi > zfoo1$$ || exit 1
+echo hi > zfoo2$$ || exit 1
+if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
+  cpmod=${CPMOD-cpmod}
 fi
+rm -f zfoo[12]$$
 
 tail=""
 IFS="${IFS=    }"; saveifs="$IFS"; IFS="${IFS}:"
@@ -48,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
@@ -70,14 +101,9 @@ for i do
     continue
   fi
   case "`basename $i`" in
-  bash | chmod | gzip | ln | mktemp | rm | sed | sh | tail)
+  gzip | tail | sed | chmod | ln | sleep | rm)
        echo "${x}: $i would depend on itself"; continue ;;
   esac
-
-  tmp=`/bin/mktemp -t gzexe.XXXXXXXXXX` || exit 1
-  trap "rm -f $tmp; exit 1" HUP INT QUIT PIPE TERM
-  trap "rm -f $tmp; exit 0" EXIT
-
   if test -z "$cpmod"; then
     cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
     if test -w $tmp 2>/dev/null; then
@@ -86,16 +112,17 @@ 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=23
 set -C
 umask=`umask`
 umask 77
-tmpfile=$(tempfile -p gztmp -d /tmp)
-if tail +$skip $0 | /bin/gzip -cd >> $tmpfile; then
+tmpfile=`tempfile -p gztmp -d /tmp` || exit 1
+if tail +$skip "$0" | /bin/gzip -cd >> $tmpfile; then
   umask $umask
   /bin/chmod 700 $tmpfile
   prog="`echo $0 | /bin/sed 's|^.*/||'`"
@@ -121,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
@@ -129,7 +156,6 @@ EOF
       :
     else
       echo ${x}: $i probably not in gzexe format, file unchanged.
-      rm -f $tmp
       res=1
       continue
     fi