Annotation of coherent/g/usr/bin/gzip/gzexe.in, revision 1.1

1.1     ! root        1: :
        !             2: #!/bin/sh
        !             3: # gzexe: compressor for Unix executables.
        !             4: # Use this only for binaries that you do not use frequently.
        !             5: #
        !             6: # The compressed version is a shell script which decompresses itself after
        !             7: # skipping $skip lines of shell commands.  We try invoking the compressed
        !             8: # executable with the original name (for programs looking at their name).
        !             9: # We also try to retain the original file permissions on the compressed file.
        !            10: 
        !            11: # Warning: the first line of this file must be either : or #!/bin/sh
        !            12: # The : is required for some old versions of csh.
        !            13: 
        !            14: x=`basename $0`
        !            15: if test $# = 0; then
        !            16:   echo compress executables. original file foo is renamed to foo~
        !            17:   echo usage: ${x} [-d] files...
        !            18:   echo   "   -d  decompress the executables"
        !            19:   exit 1
        !            20: fi
        !            21: 
        !            22: tmp=gz$$
        !            23: trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15
        !            24: 
        !            25: decomp=0
        !            26: res=0
        !            27: test "$x" = "ungzexe" && decomp=1
        !            28: if test "$1" = "-d"; then
        !            29:   decomp=1
        !            30:   shift
        !            31: fi
        !            32: 
        !            33: for i do
        !            34:   if test ! -f "$i" ; then
        !            35:     echo ${x}: $i not a file
        !            36:     res=1
        !            37:     continue
        !            38:   fi
        !            39: 
        !            40:   cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
        !            41:   if test -w $tmp 2>/dev/null; then
        !            42:     writable=1
        !            43:   else
        !            44:     writable=0
        !            45:     chmod u+w $tmp 2>/dev/null
        !            46:   fi
        !            47:   if test $decomp -eq 0; then
        !            48:     sed 1q $0 > $tmp
        !            49:     sed "s,foo,$i," >> $tmp <<'EOF'
        !            50: skip=18
        !            51: if tail +$skip $0 | gzip -cd > /tmp/gztmp$$; then
        !            52:   chmod 755 /tmp/gztmp$$
        !            53:   if ln /tmp/gztmp$$ /tmp/foo 2>/dev/null; then
        !            54:     trap '/bin/rm -f /tmp/gztmp$$ "/tmp/foo"; exit $res' 0
        !            55:     (sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/foo") 2>/dev/null &
        !            56:     /tmp/foo ${1+"$@"}; res=$?
        !            57:   else
        !            58:     trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0
        !            59:     (sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
        !            60:     /tmp/gztmp$$ ${1+"$@"}; res=$?
        !            61:   fi
        !            62: else
        !            63:   echo Cannot decompress $0
        !            64:   exit 1
        !            65: fi; exit $res
        !            66: EOF
        !            67:     if gzip -cv9 "$i" >> $tmp; then
        !            68:       /bin/rm -f "$i~"
        !            69:       mv "$i" "$i~" || {
        !            70:         echo ${x}: cannot backup $i as $i~
        !            71:        rm -f $tmp
        !            72:        res=1
        !            73:        continue;
        !            74:       }
        !            75:       mv $tmp $i || cp -p $tmp $i 2>/dev/null || cp $tmp $i
        !            76:       if test $writable -eq 0; then
        !            77:        chmod u-w $i 2>/dev/null
        !            78:       fi
        !            79:     else
        !            80:       /bin/rm -f $tmp
        !            81:       echo ${x}: compression not possible for $i, file unchanged.
        !            82:       res=1
        !            83:     fi
        !            84: 
        !            85:   else #decompression
        !            86:     skip=18
        !            87:     if sed -e 1d -e 2q "$i" | grep "^skip=" >/dev/null; then
        !            88:       eval `sed -e 1d -e 2q "$i"`
        !            89:     fi
        !            90:     if tail +$skip $i | gzip -cd > $tmp; then
        !            91:       /bin/rm -f "$i~"
        !            92:       mv "$i" "$i~" || {
        !            93:         echo ${x}: cannot backup $i as $i~
        !            94:        rm -f $tmp
        !            95:        res=1
        !            96:        continue;
        !            97:       }
        !            98:       mv $tmp "$i" || cp -p $tmp "$i" 2>/dev/null || cp $tmp "$i" || {
        !            99:         echo ${x}: cannot create $i
        !           100:        rm -f $tmp
        !           101:         res=1
        !           102:         continue
        !           103:       }
        !           104:       rm -f $tmp
        !           105:       if test $writable -eq 0; then
        !           106:        chmod u-w $i 2>/dev/null
        !           107:       fi
        !           108:     else
        !           109:       echo ${x}: $i probably not in gzexe format, file unchanged.
        !           110:     fi
        !           111:   fi
        !           112: done
        !           113: exit $res

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.