#!/bin/sh -

# This script needs to copy ownerships and such, so only root may run it.

TERM=`which term`
UNDO=no;

for i in $*; do
        if [ x$i = "x-u" ]; then
		UNDO=yes
		continue
	fi
        if [ $UNDO = "no" ]; then
		j=term`basename $i`
		if ldd $i | grep 'libtermnet.so.2|libt.so.4'; then 
  			echo $i "was already compiled for term support."
  			cp $i $j
		else
  			sed 's/libc\.so\.4/libt\.so\.4/g' < $i > $j
		fi
		cpacl $TERM $j
		if [ -u $i ]; then 
			if chown `/bin/ls -l $i|awk '{print $3}'` $j; then
               	 		chmod u+s $j;
                	fi
		fi
	else
		j=`basename $i|sed 's/^term//'`
		if ldd $i | grep 'libc.so.4'; then 
  			echo $i "was not termified."
  			cp $i $j
		else
  			sed 's/libt\.so\.4/libc\.so\.4/g' < $i > $j
		fi
	fi
done

