X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gzexe.in;fp=gzexe.in;h=b67e92e6c0c6c863fdba9968eb4ea9d1b2d63883;hb=8f94ab178da95f87bd131b8faaec313a5d9d672f;hp=b7a0cf4c260495553447721350e7ed94d0937910;hpb=302189d124ed5849c2589ea92e912eb24fdc4ab3;p=gzip diff --git a/gzexe.in b/gzexe.in index b7a0cf4..b67e92e 100755 --- a/gzexe.in +++ b/gzexe.in @@ -13,7 +13,7 @@ # 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` +x=`basename "$0"` if test $# = 0; then echo compress executables. original file foo is renamed to foo~ echo usage: ${x} [-d] files... @@ -21,9 +21,6 @@ if test $# = 0; then exit 1 fi -tmp=gz$$ -trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15 - decomp=0 res=0 test "$x" = "ungzexe" && decomp=1 @@ -32,12 +29,10 @@ if test "x$1" = "x-d"; then shift fi -echo hi > zfoo1$$ -echo hi > zfoo2$$ -if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then - cpmod=${CPMOD-cpmod} +cpmod= +if type ${CPMOD:-cpmod} 2>/dev/null; then + cpmod=${CPMOD:-cpmod} fi -rm -f zfoo[12]$$ tail="" IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:" @@ -75,9 +70,14 @@ for i do continue fi case "`basename $i`" in - gzip | tail | chmod | ln | sleep | rm) + bash | chmod | gzip | ln | mktemp | rm | sed | sh | tail) 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 @@ -90,22 +90,23 @@ for i do if test $decomp -eq 0; then 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) +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 @@ -128,6 +129,7 @@ EOF : else echo ${x}: $i probably not in gzexe format, file unchanged. + rm -f $tmp res=1 continue fi