home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / compress / gnuzip_.zip / GZEXE.IN < prev    next >
Text File  |  1993-03-28  |  1KB  |  55 lines

  1. :
  2. #!/bin/sh
  3. # Compressor for Unix executables.
  4. # Use this only for binaries that you do not use frequently.
  5. # The compressed version is a shell script which decompresses itself
  6. # after skipping 18 lines of shell commands.
  7.  
  8. if test $# = 0; then
  9.   echo compress executables. original file foo is renamed to foo~
  10.   echo usage: `basename $0` files...
  11.   exit 1
  12. fi
  13.  
  14. res=0
  15. for i do
  16.   if test ! -f $i ; then
  17.     echo `basename $0`: $i not found
  18.     res=1
  19.     continue
  20.   fi
  21.  
  22. # Try invoking the compressed executable with the original name:
  23.   sed "s,foo,$i," > g$$ <<'EOF'
  24. #!/bin/sh
  25. if tail +18 $0 | gzip -cd > /tmp/gztmp$$; then
  26.   chmod 755 /tmp/gztmp$$
  27.   if ln /tmp/gztmp$$ /tmp/foo 2>/dev/null; then
  28.     /tmp/foo $*
  29.     res=$?
  30.     /bin/rm -f /tmp/gztmp$$ /tmp/foo
  31.   else
  32.     /tmp/gztmp$$ $*
  33.     res=$?
  34.     /bin/rm -f /tmp/gztmp$$
  35.   fi
  36. else
  37.   echo Cannot decompress $0
  38.   exit 1
  39. fi
  40. exit $res
  41. EOF
  42.  
  43.   if gzip -cv9 $i >> g$$; then
  44.     /bin/rm -f $i~
  45.     mv $i $i~
  46.     mv g$$ $i
  47.     chmod 755 $i
  48.   else
  49.     /bin/rm -f g$$
  50.     echo `basename $0`: compression not possible for $i, file unchanged.
  51.     res=1
  52.   fi
  53. done
  54. exit $res
  55.