#!/bin/sh
# Change permissions, links so that a group of users can access the
# diagnostic commands.

COMMANDS="traceroute statnet netwatch trafshow"

function errorexit 
{
	echo -n "ERROR: "
	echo $1;
	exit 1;
}


if [ "x$1" = "x" ]; then
  echo "Usage: diagperm <group allowed access to diagnostic commands>"
else
  if [ "$EUID" -ne 0 ]; then
	errorexit "This program must be run by super-user (root)."
 fi
 if grep -q $1 /etc/group; then
  for i in $COMMANDS; do
	if [ -x /usr/sbin/suidregister ]; then
		suidregister /usr/sbin/$i root $1 4754 || errorexit "Cannot suid register /usr/sbin/$i ."
	else
		if [ -f /usr/sbin/$i ]; then
			chgrp $1 /usr/sbin/$i
			chmod 4754 /usr/sbin/$i
			if [ ! -f /usr/local/bin/$i ]; then
				ln -s ../../sbin/$i /usr/local/bin 
			else
				 echo "Please check that /usr/local/bin/$i is a symbolic link to /usr/sbin/$i ."
			fi
		fi
	fi
  done
  echo "Permissions enabled for members of group $1 ."
 else
   echo "Group $1 not in /etc/group."
 fi
fi
