#!/bin/sh -

#
# tzx V1.00 - a simplier and hopefully more robust transparent executable
# compression.
#
# Oleg Kibirev * April 1995 * oleg@gd.cs.CSUFresno.EDU
#
# This code is covered by General Public License, version 2 or any later
# version of your choice. You should recieve file "COPYING" which contains
# text of the license with any distribution of this program; if you don't 
# have it, a copy is available from ftp.gnu.ai.mit.edu.
#

error=0
umask 0

for i in "$@"; do
  if [ ! -f "$i" ]; then
    echo "$i:	Not a regular file." 1>&2
    error=1
    continue
  fi	

  if [ -g "$i" -o -u "$i" ]; then
    echo "$i:	Setuid and setgid executables not supported." 1>&2
    error=1
    continue
  fi

  case "$i" in
  /usr/local/bin/untcx|/bin/gzip)
	echo "$i: Would depend on itself to execute." 1>&2
	error=1
	continue ;;
  esac

  if ! (mv $i ${i}~ && cp -a ${i}~ ${i} && (echo '#!/usr/local/bin/untzx'; gzip -9 < ${i}~) > $i)
  then
    error=1
  fi
done

exit $error
